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 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
# Current dispatch method | |
def dispatch(self, request, *args, **kwargs): | |
# Try to dispatch to the right method; if a method doesn't exist, | |
# defer to the error handler. Also defer to the error handler if the | |
# request method isn't on the approved list. | |
if request.method.lower() in self.http_method_names: | |
handler = getattr(self, request.method.lower(), self.http_method_not_allowed) | |
else: | |
handler = self.http_method_not_allowed | |
self.request = request |
This file contains 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
<html> | |
<head> | |
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script> | |
<script> | |
function setCookie(c_name,value,exdays) { | |
var exdate=new Date(); | |
exdate.setDate(exdate.getDate() + exdays); | |
var c_value=escape(value) + ((exdays==null) ? "" : "; expires="+exdate.toUTCString()); | |
document.cookie=c_name + "=" + c_value; | |
} |
This file contains 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 |
This file contains 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 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 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 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 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 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.""" |
OlderNewer