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 .conf_base import AppSettings | |
class Settings(AppSettings): | |
YOUR_SETTING = True | |
""" | |
Give each setting some documentation for sphinx autodoc if you like. | |
""" | |
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
@register.assignment_tag | |
def flatpages(a, b, *order_first): | |
""" | |
Get the flatpages, optionally with specific ones ordered first. | |
Usage:: | |
{% flatpages '/home/' '/about/' as flatpages %} | |
{% for flatpage in flatpages %}...{% endfor %} | |
""" |
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 UpdateOrCreateMixin(object): | |
""" | |
A view mixin to allow views that use SingleObjectMixin to not fail if no pk/slug is provided. | |
Primarily useful for making an UpdateView that can create objects too. For example:: | |
class MyView(UpdateOrCreateMixin, UpdateView): | |
... | |
url(r'^add/$', MyView.as_view(), name='my-add-view'), |
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
import re | |
array_qs = re.compile(r'(\w+)\[(\d*)\]$') | |
class UnPHPify(object): | |
def process_request(self, request): | |
""" | |
Iterate request.GET, request.POST and request.FILES and amend the dict |
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 NotFound(object): | |
""" | |
A class representing a context variable which was not found. | |
TODO: this could be extended to use the ``TEMPLATE_STRING_IF_INVALID`` | |
Django setting for the ``__str__`` and ``__unicode__`` methods. | |
""" | |
def __init__(self, name=None): |
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.conf import settings | |
from django.contrib.sites.models import Site | |
from django.core.cache import cache | |
from project.apps.site_settings import models | |
KEY = 'site-settings-%d' % settings.SITE_ID | |
def get_settings(from_cache=True): | |
""" |
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
import re | |
re_float = re.compile('[-+]?(\d+\.\d*|\.\d+)$') | |
re_decimal = re.compile('[-+]?\d+$') | |
class CompileError(Exception): | |
pass | |
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
{% if user %} | |
<div class="left_column"> | |
{% endif %} | |
{% block content %} | |
{% endblock %} | |
{% if user %} | |
</div> | |
<div class="right_column"> | |
<div class="sidebar_header user_info"> | |
<h2>Welcome.</h2> |
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
{% if condition | |
%}{% for item in list %} | |
{{ item }}{% | |
endfor %}{% | |
endif %} |
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 YourBaseModel(models.Model): | |
@property | |
def child(self): | |
from django.core.exceptions import ObjectDoesNotExist | |
for related_object in self._meta.get_all_related_objects(): | |
if not issubclass(related_object.model, self.__class__): | |
continue | |
try: | |
return getattr(self, related_object.get_accessor_name()) |
OlderNewer