Skip to content

Instantly share code, notes, and snippets.

Avatar

Rey Abolofia purple4reina

  • Stitch Fix
  • Portland, OR
View GitHub Profile
@purple4reina
purple4reina / safe_template.py
Last active Aug 29, 2015
Django Safe Template
View safe_template.py
from django.template import Template
class SafeTemplate(Template):
"""
Subclass of the regular django Template but disallows rendering anything
that will call a method on a class thus making it safe for use as a user
editable object
Examples:
# this will return the template as expected
@purple4reina
purple4reina / run_unittests.py
Created Jun 9, 2015
Running Django Unit Tests
View run_unittests.py
#!/usr/bin/env python
"""
Run all unit tests within the current working directory optionally skipping
some modules
This script should be used instead of running `./manage.py test`. This django
provided unittest runner does not reset the testing database between each
testing file. The only way to ensure the testing database is completely dropped
is by running each test file individually.
View throttle.py
class throttle(object):
"""
Decorator that prevents a function from being called more than once every
time period. If called too soon, RuntimeError is raised.
To create a function that cannot be called more than once a minute:
@throttle(minutes=1)
def my_fun():
pass
You can’t perform that action at this time.