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.contrib.auth.models import User | |
| from django.contrib.auth.backends import ModelBackend | |
| class CIModelBackend(ModelBackend): | |
| """ | |
| Overrides the default authentication backend (ModelBackend) | |
| to support case-insensitive login. | |
| """ | |
| def authenticate(self, username=None, password=None): | |
| try: |
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 datetime import timedelta, datetime | |
| def first_sunday_on_or_after(dt): | |
| days_to_go = 6 - dt.weekday() | |
| if days_to_go: | |
| dt += timedelta(days_to_go) | |
| return dt | |
| # For a complete and up-to-date set of DST rules and timezone definitions, | |
| # visit the Olson Database: http://www.twinsun.com/tz/tz-link.htm or |
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 JsonpResponse(HttpResponse): | |
| def __init__(self, data, callback): | |
| json_encoder = LazyEncoder(ensure_ascii=False) | |
| json = json_encoder.encode(data) | |
| jsonp = "%s(%s)" % (callback, json) | |
| HttpResponse.__init__( | |
| self, jsonp, | |
| mimetype='application/json' | |
| ) |
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
| <script> | |
| <link href='prettify.css' rel='stylesheet' type='text/css'/> | |
| <script src='prettify.js' type='text/javascript'> | |
| </script> |
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
| qs = MyRelatedObject.objects.all() | |
| obj_dict = dict([(obj.id, obj) for obj in qs]) | |
| objects = MyObject.objects.filter(myrelatedobj__in=qs) | |
| relation_dict = {} | |
| for obj in objects: | |
| relation_dict.setdefault(obj.myobject_id, []).append(obj) | |
| for id, related_items in relation_dict.items(): | |
| obj_dict[id].related_items = related_items |
NewerOlder