Login

Tag "zip"

Snippet List

Dictionary of choices based in models

Sometimes we need to build a ChoiceField from data in a Model or more than just one model via fk's but the ModelChoiceField is not *that* flexible. So, in order to obtain a list of tuples with pk and a descriptive text for the choices parameter of the ChoiceField use this little function.

  • forms
  • choicefield
  • zip
  • list-of-tuples
  • orm-and-forms
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

3 snippets posted so far.