Skip to content

Instantly share code, notes, and snippets.

View nathanborror's full-sized avatar

Nathan Borror nathanborror

View GitHub Profile
def comment_saved_handler(sender, instance, created, **kwargs):
"""
Signal handler to populated comment count fields.
Bound to 'comment_count' field, should probably be checking for a field annotation in the model.
"""
if 'comment_count' in [f.name for f in instance.content_object._meta.fields]:
instance.content_object.count = instance.content_object.comments.count()
instance.content_object.save()
from django.contrib.comments.models import Comment
@register.filter
def gt(value, arg):
"Returns a boolean of whether the value is greater than the argument"
return value > int(arg)
@register.filter
def lt(value, arg):
"Returns a boolean of whether the value is less than the argument"
return value < int(arg)
#!/usr/bin/env python
#
# some bits stolen from Travis Cline's http://github.com/traviscline/git-branchdescriptions
#
import os
import re
import sys
from subprocess import Popen, PIPE
diff --git a/django/contrib/admindocs/templates/admin_doc/model_index.html b/django/contrib/admindocs/templates/admin_doc/model_index.html
index 4dd7caa..47c94c0 100644
--- a/django/contrib/admindocs/templates/admin_doc/model_index.html
+++ b/django/contrib/admindocs/templates/admin_doc/model_index.html
@@ -36,7 +36,7 @@
<ul>
{% regroup models by app_label as grouped_models %}
{% for group in grouped_models %}
- <li><a href="#{{ group.grouper }}">{{ group.grouper|capfirst }}</a></li>
+ <li><a href="#app-{{ group.grouper }}">{{ group.grouper|capfirst }}</a></li>
from dateutil.relativedelta import *
from datetime import *
TODAY = datetime.now()
TODAY+relativedelta(weekday=FR(+2))
@nathanborror
nathanborror / gist:188346
Created September 17, 2009 04:28
URL resolver
urlpatterns([
{'regex': /^\/(\w+)\/$/, 'view': View.timeline},
{'regex': /^\/(\w+)\/timeline\//, 'view': View.timeline},
{'regex': /^\/(\w+)\/notes\//, 'view': View.notes},
{'regex': /^\/(\w+)\/books\/$/, 'view': View.readerbooks},
{'regex': /^\/(\w+)\/contacts\//, 'view': View.contacts}
]);
function urlpatterns(obj) {
/**
* DatePicker
* @author Rick Hopkins
* @modified Micah Nolte, Martin Vaina, Nathan Borror
* @version 1.0
* @classDescription A date picker object for user with MooTools 1.2
* MIT-style License.
*
* Example:
* new DatePicker('date_input');
@nathanborror
nathanborror / gist:194559
Created September 27, 2009 02:44
Comparison filters
from django.template import Library
from django.template.defaultfilters import lower
register = Library()
@register.filter
def gt(value, arg):
"Returns a boolean of whether the value is greater than the argument"
try:
return float(value) > float(arg)
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>untitled</title>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/mootools/1.2.3/mootools-yui-compressed.js"></script>
<script type="text/javascript">
var Box = new Class({
from django.db import models
from django.contrib.auth.models import User
from django.utils.translation import ugettext_lazy as _
from django.core.cache import cache
RELATIONSHIP_CACHE = 60*60*24*7
RELATIONSHIP_CACHE_KEYS = {
'FRIENDS': 'friends',
'FOLLOWERS': 'followers',