This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from django.conf import settings | |
| from django.http import HttpResponse | |
| class ForceDefaultLanguageMiddleware(object): | |
| """ | |
| Ignore Accept-Language HTTP headers | |
| This will force the I18N machinery to always choose settings.LANGUAGE_CODE | |
| as the default initial language, unless another one is set via sessions or cookies |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from django import template | |
| from django.utils.safestring import mark_safe | |
| import json | |
| register = template.Library() | |
| @register.filter(name='json') | |
| def json_dumps(data): | |
| return mark_safe(json.dumps(data)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class MultipleProxyLastMiddleware(object): | |
| """ | |
| Middleware to "fix" HTTP_X_FORWARDED_xxx headers for multiple proxy chains. | |
| Picks the *last* element in the proxy list | |
| As in Django docs - https://docs.djangoproject.com/en/1.3/ref/request-response/#django.http.HttpRequest.get_host | |
| """ | |
| FORWARDED_FOR_FIELDS = [ | |
| 'HTTP_X_FORWARDED_FOR', | |
| 'HTTP_X_FORWARDED_HOST', | |
| 'HTTP_X_FORWARDED_SERVER', |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class RegistrationForm(ModelForm): | |
| address = ModelChoiceField(queryset=ADDRESS_MODEL.objects.all(), widget=HiddenInput()) | |
| service_area = ModelChoiceField(queryset=ServiceArea.objects.all(), widget=HiddenInput(), required=False) | |
| apartment_type = ModelChoiceField(queryset=ApartmentType.objects.all(), empty_label=None, label=capfirst(Registration.apartment_type.field.verbose_name)) | |
| registration_accuracy = IntegerField(widget=HiddenInput()) | |
| forced_add = BooleanField(label=_('Forced add'), required=False) | |
| unique_id = CharField(max_length=64, widget=HiddenInput()) | |
| class Meta: | |
| model = Registration |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Power of Q objects | |
| from django.db.models import Q | |
| q = Q() | |
| for v in vals: | |
| q |= Q(myfield__iexact=v) | |
| MyModel.objects.filter(q) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def post(self, request): | |
| query = self._build_query(self.DATA) | |
| qs = self.resource.model.objects.filter(query) | |
| qs_str = pickle.dumps(qs.query) | |
| h = hashlib.md5(qs_str) | |
| key = h.hexdigest() | |
| request.session['%s-%s' % (self._get_prefix(), key)] = qs_str; | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class AssetTask(models.Model): | |
| TASK_TYPE = ( | |
| (0 , _('normal')), | |
| (1 , _('failure')), | |
| (2 , _('duplicate')), | |
| (99, _('unknown')), | |
| ) | |
| task_type = models.IntegerField(_('task type'), choices=TASK_TYPE, default=0) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import csv, codecs, cStringIO | |
| from django.template.defaultfilters import yesno | |
| class excel_semicolon(csv.excel): | |
| """Describe the usual properties of Excel-generated CSV files.""" | |
| delimiter = ';' | |
| csv.register_dialect("excel-semicolon", excel_semicolon) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from django.utils.encoding import force_unicode | |
| from django.utils import datetime_safe | |
| from django.utils.functional import Promise | |
| import django.utils.simplejson as json | |
| import datetime | |
| class AugmentedJSONEncoder(json.JSONEncoder): | |
| """ | |
| Augmentation for simplejson encoder. | |
| Now additionally encodes arbitrary iterables, class instances, decimals, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| oldfile = open('freeze_old.txt') | |
| newfile = open('freeze_new.txt') | |
| packages = {} | |
| def splitpackage(line): | |
| result = line.split('==') | |
| if not len(result) == 2: | |
| result = line.split('@') | |
OlderNewer