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
{% extends "reversion/change_list.html" %} | |
{% load my_admin i18n %} | |
{% block extrahead %} | |
<script type="text/javascript" src="/media/static/js/jquery-1.3.2.js" /> | |
<script type="text/javascript" src="/media/static/js/jquery-ui-1.7.2.custom.min.js" /> | |
<script type="text/javascript" src="/media/static/js/change_list_sort.js" /> | |
{% endblock %} | |
{% block object-tools %} |
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.template import Library | |
from django.utils.encoding import force_unicode | |
from django.utils.functional import allow_lazy | |
from django.template.defaultfilters import stringfilter | |
register = Library() | |
def truncate_chars(s, num): | |
""" | |
Template filter to truncate a string to at most num characters respecting word |
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 import forms | |
import datetime | |
class MonthYearWidget(forms.MultiWidget): | |
""" | |
A widget that splits a date into Month/Year with selects. | |
""" |
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 | |
PROJECT_ROOT = os.path.dirname(os.path.abspath(__file__)) | |
DATABASES = { | |
'default': { | |
'ENGINE': 'django.db.backends.sqlite3', | |
'NAME': os.path.join(PROJECT_ROOT, '../local.db'), | |
'USER': '', |
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
[ui] | |
username = Josh Ourisman <[email protected]> | |
[extensions] | |
# easy_install hgsubversion | |
hgsubversion= | |
# easy_install hg-git | |
hggit= | |
fetch= | |
hgext.mq= |
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 csv, StringIO | |
class CSVEmitter(Emitter): | |
def get_keys(self, input_dict): | |
keys = [] | |
for item in input_dict.items(): | |
if isinstance(item[1], dict): | |
keys.extend(self.get_keys(item[1])) | |
else: | |
keys.append(item[0]) |
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 struct import pack, unpack | |
def encode(ip_address): | |
return unpack('i', ''.join([pack('B', int(sub)) for sub in ip_address.split('.')]))[0] | |
def decode(packed_address): | |
return '.'.join(['%d' % unpack('B', sub)[0] for sub in pack('i', packed_address)]) |
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 ThisAdmin(admin.ModelAdmin): | |
def queryset(self, request): | |
""" | |
Filter the objects displayed in the change_list to only | |
display those for the currently signed in user. | |
""" | |
qs = super(ThisAdmin, self).queryset(request) | |
if request.user.is_superuser: | |
return qs | |
return qs.filter(Q(owner=request.user) | Q(editors=request.user)) |
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 ThisAdmin(admin.ModelAdmin): | |
def get_urls(self): | |
urls = super(ThisAdmin, self).get_urls() | |
my_urls = patterns('', | |
url(r'^all/$', | |
self.admin_site.admin_view(all_objects), | |
{'admin': self,}, | |
name='all_initiatives'), | |
) | |
return my_urls + urls |
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 all_objects(request, admin): | |
return ThisAdmin(admin.model, admin.admin_site, request).changelist_view(request) |
OlderNewer