When debugging tests you frequently need to inspect response content, making a pdb. set_trace() breakpoint and printing response.content
but html isn't enough human readable (even for programmers :D) so, why not open it in your browser? Suposse you save this code in utils.py and you break your testcase as this:
response = self.client.get(self.url)
import pdb; pdb.set_trace()
Then:
(pdb) from utils import load_response_on_firefox
(pdb) load_response_on_firefox(response)
Ta-Da!
A Select widget that allows choices to be disabled. Specify `disabled_choices` to indicate which choices should be present in the list, but disabled.
A possible use case for this is a form that displays data that can be edited by privileged user's but only viewed by others.
This BasePasswordHasher allows the easy migration of passwords from Drupal to Django 1.4. Drupal stores its passwords using a SHA512 hash, but with some iterations and postprocessing.
This snippet allows you to migrate the username and passwords over seamlessly- the only necessary change is truncating the first character of each password hash (since Django 1.4 stores each password as algorithm$hash).
Note that this snippet *requires* Django 1.4, but there is no option for that snippet in the list.
Provided as a github gist [here](https://gist.github.com/2344345).
This template tag allows you to increment a variable within a template. This avoids the need of having to use the `add` filter and the syntax is quite intuitive.
Converts an integer or floating-point number or a string to a string containing the delimiter character (default comma) after every delimeter_count digits (by default 3 digits)
A Django 1.4 wizard mixin for use cases with a wizard step on the frontpage
of your site -- with a request path of `'/'`.
Just define the name of the step (e.g. `root_step = 'landing_page'`)
and it does the setup and redirection automatically.
If you read the docstring and the example you should get a clue what this Code does. I didn't want a big function everytime that handles every specific form, formset combinations so this how i can add/edit Models with specific Forms given to the magic_handle_inlineformsets function. It also works for Forms without innline_formsets.
This function downloads selected rows to CSV file. The snippet is based on snippet 1697 and 2020. This function downloads all columns given in the list_display, including callable items.
Call resize_image to replace the image with a resized and normalized version of itself. I recommend doing this with celery, but you could also hook it up to the admin interface if you're not impatient.
This utility makes a text dump of a model instance, including objects related by a forward or reverse foreign key. The result is a hierarchical data structure where
* each instance is represented as a list of fields,
* each field as a (<name>, <value>) tuple,
* each <value> as a primitive type, a related object (as a list of fields), or a list of related objects.
See the docstring for examples.
We used this to make text dumps of parts of the database before and after running a batch job. The format was more useful than stock `dumpdata` output since all related data is included with each object. These dumps lend themselves particularly well for comparison with a visual diff tool like [Meld](http://meldmerge.org/).
You're looking at the most-bookmarked snippets on the site; if you'd like to help useful snippets show up here, sign up for an account and you'll get your own bookmarks list.