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
""" | |
A template tag for Django templates which does not allow | |
non-existent variable errors to fail silently. | |
Only works for simple lookups, where the variable is | |
a key in the context. | |
""" | |
from django import template | |
register = template.Library() |
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
""" | |
Unroll a nested dictionary into flat lists. | |
This might come in handy if you have on your hands a massive, hardcoded, | |
vertical- and horizontal-screen-spanning lookup map, and you would like to get | |
it into a tabular format, so you can, for example, load it into a relational | |
database table. | |
""" | |
import sys | |
import csv |
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
""" | |
Functions for pretty-printing dictionary differences, including an | |
assert function for testing purposes. | |
Under MIT License from sprin. (https://gist.github.com/sprin/6034947/) | |
Example: | |
a = { | |
'key1': 'val1', |
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
""" | |
A demo of creating a new database via SQL Alchemy. | |
Under MIT License from sprin (https://gist.github.com/sprin/5846464/) | |
This module takes the form of a nosetest with three steps: | |
- Set up the new database. | |
- Create a table in the new database. | |
- Teardown the new database. | |
""" |
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 CharFieldNoEmptyString(CharField): | |
def get_prep_value(self, value): | |
# Cast empty strings to null before saving to the DB. | |
value = ( | |
super(CharFieldNoEmptyString, self) | |
.get_prep_value(value) | |
) | |
return value or None |
NewerOlder