Login

Most bookmarked snippets

Snippet List

South unran migration check

Middleware that checks if you ran all South migrations. If not, it will throw an exception. Make sure to only use this middleware in development!

  • middleware
  • migration
  • south
Read More

model queries to Google Visualization DataTables

Helper functions to use the Google Visualization API in Django. Module stores queries to use and creates a JSon representation of a Google Visualization DataTable for each by inspecting the query's model. Looks up any choices defined for the columns. Depends on Google Visualization Python API: https://code.google.com/p/google-visualization-python/ To use, define the queries to use with the Visualization API at the head of views.py with: add_query(queryset, 'query name') then in view functions, get the JSon representation of a Google Visualization DataTable for the query with: my_json = get_viz_json('query name') Within the HTML template, pipe the JSon through safe: var dataTable = new google.visualization.DataTable( {{ my_json|safe }} );

  • Google Visualization
  • charts
Read More

Password Obfuscation Log Filter

This is a simple logging [filter](https://docs.djangoproject.com/en/1.5/topics/logging/#topic-logging-parts-filters) to ensure that user-entered passwords aren't recorded in the log or emailed to admins as part of the request data if an error occurs during registration/login.

  • filter
  • log
  • password
  • logging
  • obfuscation
Read More

Multi-DB Reconnecting Persistent Postgres Connection

This is a modification of http://djangosnippets.org/snippets/1707/ that handles the database going down or PG Bouncer killing the connection. This also works in things like Twisted to make sure the connection is alive before doing a real query. Thanks @mike_tk for the original post! EDIT: Updated the wrapper to handle multi-db. Before it was using the first connection it made, now it creates an attribute name for the connection based on the name of the database.

  • database
  • multi-db
  • twisted
  • connection
  • persistent
  • multiple-databases
  • socket
  • web-socket
Read More

Form and ModelForm inheritance DRY

Modelform cant inhertit from forms. To solve this issue, split thing you wanto to inherit into filed definition and functionality definition. For modelform use the base_fields.update method as mentioned in the code.

  • form
  • inheritance
Read More

ReST google-map directive.

Use this directive to show google-map if you don't want to use 'raw' directive. default location is my favorite place. Of course you can change it :)

  • restructuredtext
  • google-map
  • directive
  • docutils
Read More

3110 snippets posted so far.