Skip to content

Instantly share code, notes, and snippets.

View nathanborror's full-sized avatar

Nathan Borror nathanborror

View GitHub Profile
@nathanborror
nathanborror / gist:77160
Created March 10, 2009 21:44
Widget service
/*
* Widget Maker
*
* <script type="text/javascript">
* var widget = {
* "id": "readernaut_widget",
* "width": 300,
* "height": 300
* };
* </script>
@nathanborror
nathanborror / gist:83774
Created March 23, 2009 21:00
Django template 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"
return value > int(arg)
@nathanborror
nathanborror / gist:88735
Created April 1, 2009 15:18
oEmbed list additions

2.3.4.5 The books type

This type is used for representing books. The following parameters are defined:

title (required)
The title of the book
url (required)
The source URL of the book.

description (optional)

@nathanborror
nathanborror / gist:88850
Created April 1, 2009 19:20
Build your own JSON
object_list = []
for note in object_list:
obj = {
'id': note.pk,
'note': note.note,
'note.reader_book': {
'id': note.reader_book.id,
'title': note.reader_book.title,
'subtitle': note.reader_book.subtitle,
'authors': ", ".join(["%s" % a.get_full_name for a in note.reader_book.authors.all()]),
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
#!/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
@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)
@nathanborror
nathanborror / flopsy.py
Created May 10, 2009 06:28
A very simple way to interact with python amqplib
"""
Copyright (c) 2008-2009, Nathan Borror
All rights reserved.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
Redistributions of source code must retain the above copyright notice, this list
of conditions and the following disclaimer.
Redistributions in binary form must reproduce the above copyright notice, this
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))