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
def run_validators(self, value): | |
if value in validators.EMPTY_VALUES: | |
return | |
errors = [] | |
for v in self.validators: | |
try: | |
v(value) | |
except ValidationError, e: | |
message = None | |
if hasattr(e, 'code'): |
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 os | |
from django.db import models | |
from easy_thumbnails.fields import ThumbnailerImageField | |
from easy_thumbnails.files import Thumbnailer, ThumbnailerImageFieldFile | |
import uuid | |
def _get_file_path(instance, filename): | |
filename = str(uuid.uuid4()) + os.splitext(filename) | |
return '/'.join('photo', filename) |
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
PS1="(`basename \"$VIRTUAL_ENV\"`\$(__git_ps1 :%s))$_OLD_VIRTUAL_PS1" | |
WORKDIR=$HOME/work/`basename $VIRTUAL_ENV` | |
cd () { | |
if (( $# == 0 )); then | |
if [ -d $WORKDIR ] && [ `pwd` != $WORKDIR ]; then | |
builtin cd $WORKDIR | |
else | |
builtin cd $VIRTUAL_ENV |
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
""" | |
To use these relative storage classes as the default, change the following | |
settings:: | |
DEFAULT_FILE_STORAGE = 'relative_storage.RelativeFileSystemStorage' | |
STATICFILES_STORAGE = 'relative_storage.RelativeStaticFilesStorage' | |
Then, you'll want to make sure that you only use the ``{% static %}`` tag when | |
referencing static files. | |
""" | |
from django.core.files import FileSystemStorage |
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 AddOrEditView(generic.UpdateView): | |
# The following two _kwarg attributes are introduced in Django 1.4, until | |
# then, they can exist here without any concern. | |
slug_url_kwarg = 'slug' | |
pk_url_kwarg = 'pk' | |
def get_object(self, *args, **kwargs): | |
pk = self.kwargs.get(self.pk_url_kwarg) | |
slug = self.kwargs.get(self.slug_url_kwarg) | |
if pk is None and slug is None: |
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
jQuery.fn.selectOptgroup = function(options) { | |
var settings = jQuery.extend({ | |
optSelect: '_options', | |
inBetween: '', | |
optBlank: null, | |
selectBlank: null, | |
keepOrphans: true, | |
showSpeed: 200 | |
}, options); |
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 as django_settings | |
class Settings(object): | |
DEFAULTS = { | |
# Define any default settings in here. | |
} | |
def __dir__(self): | |
return dir(django_settings) |
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.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 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 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 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
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 |