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 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()) |
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
| {% if condition | |
| %}{% for item in list %} | |
| {{ item }}{% | |
| endfor %}{% | |
| endif %} |
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
| {% 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 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 re | |
| re_float = re.compile('[-+]?(\d+\.\d*|\.\d+)$') | |
| re_decimal = re.compile('[-+]?\d+$') | |
| class CompileError(Exception): | |
| pass | |
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.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 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 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): |
NewerOlder