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()) |
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
WORKDIR=$HOME/work/`basename $VIRTUAL_ENV` | |
cd () { | |
if (( $# == 0 )); then | |
if [ -d $WORKDIR ] && [ `pwd` != $WORKDIR ]; then | |
builtin cd $WORKDIR | |
else | |
builtin cd $VIRTUAL_ENV | |
fi | |
else |
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 SubscriptionForm(forms.ModelForm): | |
""" Base form to be extended by providers which require authentication. """ | |
def save(self, *args, **kwargs): | |
self.instance.credentials = self.serialize() | |
return super(SubscriptionForm, self).save(*args, **kwargs) | |
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.utils.datastructures import SortedDict | |
from django.db.models.fields import AutoField | |
class EasyFieldsets(object): | |
""" | |
A mixin for use with ``ModelAdmin`` and related inline classes allowing | |
fieldsets to be used without having to manually define all fields | |
(undefined ones are placed at the end of the ``None`` fieldset). | |
""" |
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 as django_settings | |
class Settings(object): | |
DEFAULTS = { | |
# Define any default settings in here. | |
} | |
def __dir__(self): | |
return dir(django_settings) |
OlderNewer