Login

Snippets by blackrobot

Snippet List

Generic CSV export admin action factory with relationship spanning fields and labels

Based on [#2712](../2712/) "This snippet creates a simple generic export to csv action that you can specify the fields you want exported and the labels used in the header row for each field. It expands on #2020 by using list comprehensions instead of sets so that you also control the order of the fields as well." The additions here allow you to span foreign keys in the list of field names, and you can also reference callables.

  • admin
  • generic
  • export
  • csv
  • admin-actions
  • export-csv
Read More

Automatically create urls for templates in a directory

When developing a site, I sometimes want to be able to visually reference the HTML before it's given a real context, and a view. This extra bit of code will allow you to add a directory within your templates dir, and pull any html files and subdirectories from it. I added the if statement to automatically use an index.html file if there's no file and extension at the end. You can substitute anything you like for the "html" in "(?P<base>html)". That's just passed as an argument to prepend to the template as a base directory for the templates.

  • urls
  • templates
  • direct_to_template
Read More

blackrobot has posted 2 snippets.