Login

Most bookmarked snippets

Snippet List

CompressedTextField

A CompressedTextField to transparently save data gzipped in the database and uncompress at retrieval. Full description at my blog: [arnebrodowski.de/...Field-for-Django.html](http://www.arnebrodowski.de/blog/435-Implementing-a-CompressedTextField-for-Django.html)

  • text
  • model
  • field
  • compressed
Read More

If modulo template tag

Usage: {% ifmodulo forloop.counter 4 0 %} <!-- do something --> {% else %} <!-- do something else --> {% endifmodulo %} or {% ifnotmodulo 5 3 %} <!-- do something --> {% else %} <!-- do something else --> {% endifmodulo %} When the third parameter does not exist, it is assumed you're checking for values different than 0.

  • template
  • tag
  • if
  • modulo
Read More

E-mail quoting filters and tags

Ttemplates and filters for quoting e-mails in templates. The `quoted_email` tag takes a template, renders it and quotes the result. The `quote_text` filter puts one or more levels of quotes around the passed text.

  • filter
  • tag
  • filters
  • email
  • tags
  • quoting
Read More

assigning many partially deviant variables

This was a much better way of incrementing variables that only changed a small amount in name. deltab in #python also said I could have used tuples, but I'm not familiar with them yet, so I added this to a list of things to look into.

  • assignment
  • variable
  • for-loop
Read More

split filter

**Usage** (*in template*): <img src="{{ MEDIA_URL }}2007/images/{% filter split:","|random %}theimage1.jpg,something2.jpg,thirdisthecharm.jpg{% endfilter %}" /> I decided to make it simple, because one template creator wanted to add random images to different places of templates. Creating something huge, like external image filename parsing was not necessary in this case.

  • filter
  • split
Read More

Month list for a select drop down

month_ids is a list of months like this... [('Apr07', 'April 2007'), ('Mar07', 'March 2007'), ('Feb07', 'February 2007')] which can be used in a select box like this.. month = forms.ChoiceField(choices=(months))

  • months
  • select
Read More

Save disk space by hard-linking multiple Django installations

If you work with Django like I do, you have a separate installation or Subversion check-out of Django for each of your projects. Currently each one of them eats 22 MB of disk space. This utility hard-links all identical files between copies of Django. They can even be different versions or svn revisions, and you'll still be able to free a good amount of disk space. Run this every now and then if you update installed copies of Django or add new ones. This utility is available also [here](http://trac.ambitone.com/ambidjangolib/browser/trunk/hardlink_django_instances/hardlink_django_instances.py).

  • disk
  • disk-space
Read More

Digg Style URL String Parser

Does a digg url effect to a string, can be useful for using an item's title in the url, from this: .hi's., is (a) $ [test], will it "work"/ \ to this: his_is_a_test_will_it_work I understand this isn't a very well made script, I am not very good at string manipulation. But I would be happy if someone would recode it in a faster, more managable way. I recomend saving the rendering.

  • url
  • clean
  • simatic
Read More

truncate letters

filter for truncating strings similar to truncatewords only with letters.

  • filter
  • truncate
  • letters
Read More

Win32 Read Registry Tag

Sometimes you need to grab information from the registry. This will only work if you have admin rights on the box you're querying.

  • win32
  • registry
Read More
Author: mpa
  • 1
  • 0

gettext parachut for python 2.3 with unicode and utf-8

I ran into this because my development system is django on python 2.4 and I deploy to 2.3. It's a corner case where you use gettext, the \# -\*- coding: utf-8 -\*- header and want to have a consistant style in your file. It is encouraged to use the unicode marker like u'string', but this does not work for __str__ methods of your models as they are called by the ``str'' function and that function again can not handle unicode. It would be really nice to have all unicode intern and only do the appropriated encoding on the output. Anyway. With this little helper you can clutter your files with _('stirng of heart with € äüöß') ... With the coding directive in the header python 2.4 and gettext can handle this on 2.3 though they can't. So this script adds a parachut to the gettext wrapper that kicks in if gettext is failing.

  • unicode
  • gettext
  • utf-8
  • 2.4
  • 2.3
Read More

3109 snippets posted so far.