Login

Snippets by shacker

Snippet List

Possessive-aware unicode for models

For a model FK'd to a user or profile, you might want every instance of that thing to appear in your site and in the admin as say "Joe's bucketlist." But if Joe's name is Ross, you want "Ross' bucketlist", not "Ross's bucketlist."

  • model
  • unicode
  • possessive
Read More

Unzip a .zip file uploaded with FileBrowser

Django Filebrowser (http://code.google.com/p/django-filebrowser/) provides a signal called filebrowser_post_upload. Adding this method to a model that has a FileBrowse field will cause uploaded .zip files to be detected and unzipped on the server in place, then deleted (leaving their folder behind). It will also delete the garbage __MACOSX folder created by Mac zip files. This is probably not safe to do for publicly uploaded files. The use case here was to allow journalists to upload entire SoundSlides projects into a custom CMS.

  • filebrowser
  • zip
  • unzip
Read More

Non-Javascript select list navigator

If you need a simple select list (picklist) containing all site categories (or some other taxonomic group) and don't want to depend on Javascript, here's how to build a simple category navigator in Django, using HttpResponseRedirect.

  • form
  • select
  • picklist
Read More

shacker has posted 3 snippets.