At present application loading is handled in different ways through Django.
Because of some of the limitations of Python, and some peculiarities of how
models work, modules should not be reimported. Consequently Django maintains
a global static, called the application cache. Models are imported from the
application cache transparently when interacting with the database. But
applications listed in INSTALLED_APPS contain more than just models. Some
contain template tags, admin.py files, search_indexes.py files from
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 collections | |
| class Foo(object): | |
| def next(self): | |
| return | |
| f = Foo() | |
| isinstance(f, collections.Iterator) # True on py2.6, False on 2.7 |
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
| { | |
| 'href': 'http://edetailing.incuna.com/api/v3/quotes', | |
| 'error': { | |
| 'status': 500, | |
| 'text': 'Internal Server Error', | |
| } | |
| } |
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
| # Extra imports | |
| from rest_framework.authtoken.models import Token | |
| from rest_framework.response import Response | |
| from rest_framework import status | |
| class Login(ObtainAuthToken): | |
| serializer_class = MyAuthTokenSerializerWithExtraChecks | |
| def post(self, request): | |
| """Override the post method to use custom serializer class.""" |
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 GetAccessToken(PermissionsMixin, View): | |
| authentication = [APIKeyAuthentication] | |
| form = UserForm | |
| def post(self, request, *args, **kwargs): | |
| user = authenticate(username=self.CONTENT['username'], password=self.CONTENT['password']) | |
| if not user: | |
| raise ErrorResponse(status.HTTP_400_BAD_REQUEST, {'detail': 'invalid username or password'}) | |
| access, created = Access.objects.get_or_create(application=self.user, user=user) | |
| response_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 AccessTokenAuthentication(BaseAuthentication): | |
| def authenticate(self, request): | |
| auth_header = request.META.get('HTTP_AUTHORIZATION') | |
| if not auth_header: | |
| return None | |
| token = re.match(r'token;([a-f0-9]{32})', auth_header, re.I) | |
| if not token: | |
| return None | |
| token = token.groups()[0].lower() | |
| 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 django.db import models | |
| class Entry(models.Model): | |
| RATING_CHOICES = zip(range(1, 11), range(1, 11)) | |
| user = models.ForeignKey('auth.User') | |
| date = models.DateField() | |
| medication_taken = models.BooleanField() | |
| rating_1 = models.IntegerField(choices=RATING_CHOICES) | |
| rating_2 = models.IntegerField(choices=RATING_CHOICES) |
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.db import models | |
| from django.utils.text import ugettext_lazy as _ | |
| from .contact_form_amended import ContactForm, ContactFormContent | |
| class MultiContactFormContent(ContactFormContent): | |
| FORM_CLASSES = {'simple-contact': ContactForm} | |
| FORM_CHOICES = (('simple-contact', _('Simple contact form')),) |
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
| (docs)marc docs $ rm -rf _build/html/ | |
| (docs)marc docs $ make html | |
| sphinx-build -b djangohtml -d _build/doctrees . _build/html | |
| Making output directory... | |
| Running Sphinx v1.1.3 | |
| loading pickled environment... done | |
| building [djangohtml]: targets for 243 source files that are out of date | |
| updating environment: 0 added, 1 changed, 0 removed | |
| reading sources... [100%] ref/class-based-views/generic-date-based | |
| looking for now-outdated files... none found |
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
| marc ~ $ ls /usr/share/postgresql/timezonesets/ | |
| Africa.txt Asia.txt Australia.txt Europe.txt Pacific.txt | |
| America.txt Atlantic.txt Default India | |
| Antarctica.txt Australia Etc.txt Indian.txt |