Skip to content

Instantly share code, notes, and snippets.

jQuery.fn.selectOptgroup = function(options) {
var settings = jQuery.extend({
optSelect: '_options',
inBetween: '',
optBlank: null,
selectBlank: null,
keepOrphans: true,
showSpeed: 200
}, options);
@SmileyChris
SmileyChris / gist:1249734
Created September 29, 2011 00:54
AddOrEditView
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:
"""
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
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
@SmileyChris
SmileyChris / gist:1789453
Created February 10, 2012 12:46
Playing around with creating an image with thumb field (haven't even run this code, so don't blame me if it doesn't work)
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)
@SmileyChris
SmileyChris / fields.py
Created February 14, 2012 00:04 — forked from insin/fields.py
Formatting horrible if
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'):
# Use 4 spaces, not tabs :P
# Don't go overboard with your newlines.
from django.shortcuts import render, redirect
from django.core.urlresolvers import reverse
# Do global imports rather than local ones unless you're specifically avoiding
# a circular import.
# Personally, I prefer to import the module rather than the classes.
filters = Q()
for value in your_list:
filters |= Q(your_field=value)
qs = qs.filter(filters)
@SmileyChris
SmileyChris / gist:2592044
Created May 4, 2012 04:33
Silent invalid arguments -> None
diff --git a/django/template/base.py b/django/template/base.py
index ab44bfb..3567756 100644
--- a/django/template/base.py
+++ b/django/template/base.py
@@ -551,9 +551,9 @@ class FilterExpression(object):
args = []
constant_arg, var_arg = match.group("constant_arg", "var_arg")
if constant_arg:
- args.append((False, Variable(constant_arg).resolve({})))
+ args.append(mark_safe(Variable(constant_arg).resolve({})))
import sublime, sublime_plugin
import string
import textwrap
import re
import comment
def previous_line(view, sr):
"""sr should be a Region covering the entire hard line"""
if sr.begin() == 0:
return None