------------------------------- ------------------ Django --------------------
| Browser: GET /udo/contact/2 | === wsgi/fcgi ===> | 1. Asks OS for DJANGO_SETTINGS_MODULE |
------------------------------- | 2. Build Request (from wsgi/fcgi callback) |
| 3. Get settings.ROOT_URLCONF module |
| 4. Resolve URL/view from request.path | # url(r'^udo/contact/(?P<id>\w+)', view, name='url-identifier')
| 5. Apply request middlewares | # settings.MIDDLEWARE_CLASSES
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
| # -*- coding: utf-8 -*- | |
| from django.views.generic import ListView | |
| class SortableListView(ListView): | |
| allowed_sort_fields = () | |
| sort_default = None | |
| sort_key = 'sort' | |
| sort_field_splitter = '-' | |
| sort_ascending_postfix = 'up' | |
| sort_descending_postfix = 'down' |
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
| // directly uploads to S3 | |
| // See http://philfreo.com/blog/how-to-allow-direct-file-uploads-from-javascript-to-amazon-s3-signed-by-python/ | |
| // See https://github.com/elasticsales/s3upload-coffee-javascript | |
| editors.Filepicker = editors.Text.extend({ | |
| tagName: 'div', | |
| events: { | |
| 'change input[type=file]': 'uploadFile', |
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
| d = {192: u'A', 193: u'A', 194: u'A', 195: u'A', 196: u'A', 197: u'A', | |
| 199: u'C', 200: u'E', 201: u'E', 202: u'E', 203: u'E', 204: u'I', | |
| 205: u'I', 206: u'I', 207: u'I', 209: u'N', 210: u'O', 211: u'O', | |
| 212: u'O', 213: u'O', 214: u'O', 216: u'O', 217: u'U', 218: u'U', | |
| 219: u'U', 220: u'U', 221: u'Y', 224: u'a', 225: u'a', 226: u'a', | |
| 227: u'a', 228: u'a', 229: u'a', 231: u'c', 232: u'e', 233: u'e', | |
| 234: u'e', 235: u'e', 236: u'i', 237: u'i', 238: u'i', 239: u'i', | |
| 241: u'n', 242: u'o', 243: u'o', 244: u'o', 245: u'o', 246: u'o', | |
| 248: u'o', 249: u'u', 250: u'u', 251: u'u', 252: u'u', 253: u'y', |
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
| """Add user created_by and modified_by foreign key refs to any model automatically. | |
| Almost entirely taken from https://github.com/Atomidata/django-audit-log/blob/master/audit_log/middleware.py""" | |
| from django.db.models import signals | |
| from django.utils.functional import curry | |
| class WhodidMiddleware(object): | |
| def process_request(self, request): | |
| if not request.method in ('GET', 'HEAD', 'OPTIONS', 'TRACE'): | |
| if hasattr(request, 'user') and request.user.is_authenticated(): | |
| user = request.user |
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
| <!DOCTYPE html> | |
| <html> | |
| <head> | |
| <script src="http://code.jquery.com/jquery.min.js"></script> | |
| <link href="http://twitter.github.com/bootstrap/assets/css/bootstrap.css" rel="stylesheet" type="text/css" /> | |
| <script src="http://twitter.github.com/bootstrap/assets/js/bootstrap.js"></script> | |
| <meta charset=utf-8 /> | |
| </head> | |
| <body> | |
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 FilterMixin(object): | |
| """ | |
| View mixin which provides filtering for ListView. | |
| """ | |
| filter_url_kwarg = 'filter' | |
| default_filter_param = None | |
| def get_default_filter_param(self): | |
| if self.default_filter_param is None: | |
| raise ImproperlyConfigured( |
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
| <!DOCTYPE html> | |
| <html lang="en"> | |
| <head> | |
| <meta charset="utf-8"> | |
| <title>Bootstrap, from Twitter</title> | |
| <meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
| <meta name="description" content=""> | |
| <meta name="author" content=""> | |
| <!-- Le styles --> |
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 sqlalchemy as sa | |
| import sqlalchemy.orm as orm | |
| from sqlalchemy.ext.declarative import declarative_base | |
| from sqlalchemy.ext.declarative import declared_attr | |
| from sqlalchemy.orm import scoped_session, sessionmaker | |
| DBSession = scoped_session(sessionmaker()) | |
| class BaseMixin(object): | |
| query = DBSession.query_property() | |
| id = sa.Column(sa.Integer, primary_key=True) |