Convert numbers from base 10 integers to base X strings and back again.
Sample usage:
>>> base20 = BaseConverter('0123456789abcdefghij')
>>> base20.from_decimal(1234)
'31e'
>>> base20.to_decimal('31e')
1234
Slightly shonky implementation of a custom URL shortening view, as [described on my blog](http://simonwillison.net/2009/Apr/11/revcanonical/). Depends on [baseconv.py](http://www.djangosnippets.org/snippets/1431/)
This snipped get the latest rss links from delicious from a DELICIOUS_USER that you have to define in your settings.
I use this snippet in the [trespams code blog](http://trespams.com) to inform the visitor about the last links I have bookmarked.
This is a modified version of [snipped 819](http://www.djangosnippets.org/snippets/819/) to allow using any variable in the template to obtain the results.
It also added a 6 hours caché for the rss.
This piece of code allows the quickly set the locale to a different language. This can be used for instance in cron jobs to send emails to users in their specific language.
This is pretty rough code, it be better to create an object, having two functions: set_locale and reset_locale. set_locale would than contain steps 1 to 4 (and return the request object on succes), reset_locale would be step 6
Enjoy!
This is based on snippets 29 and 43, both of which had good ideas, and I thought, "why not combine them?"
Given the new_topic string above, the resulting slug will be:
"test-long-string-which-has-many-words-here"
John Crawford
Note - requires python 2.5, for list comprehensions. Otherwise you could just use a for loop to build the clean_list.
This is a more compact version of django's [timeuntil](http://docs.djangoproject.com/en/dev/ref/templates/builtins/#timeuntil) filter that only shows hours & minutes. If used like `{{ dt|timeto }}`, will produce output like "1hr 30min". If you know for sure that the server has the same timezone as the [datetime](http://docs.python.org/library/datetime.html#datetime-objects) value, then you don't need [datetutil.tz](http://labix.org/python-dateutil#head-587bd3efc48f897f55c179abc520a34330ee0a62) for utc time conversion.
Use this template filter to produce an ISO format UTC datetime string from a [timezone aware](http://docs.python.org/library/datetime.html#datetime.tzinfo) [datetime](http://docs.python.org/library/datetime.html#datetime.datetime) object. Usage example in a template:
`<input name="when" type="hidden" value="{{ dt|isoutc }}"`.
You must have [dateutil](http://labix.org/python-dateutil) installed for `tz.tzutc()` to work. And of course, you'll need to load it as a [custom tag](http://docs.djangoproject.com/en/dev/howto/custom-template-tags/#howto-custom-template-tags) to use it.
The output format differs from python's [datetime.isoformat](http://docs.python.org/library/datetime.html#datetime.datetime.isoformat) by ignoring the `microsecond` and including a "Z" suffix for the UTC timezone. For ease of use, it is also not double quoted as the standard suggests.
FuzzyDateTimeField is a drop in replacement for the standard [DateTimeField](http://docs.djangoproject.com/en/dev/ref/forms/fields/#datetimefield) that uses [dateutil.parser](http://labix.org/python-dateutil#head-a23e8ae0a661d77b89dfb3476f85b26f0b30349c) to clean the value. It has an extra keyword argument `fuzzy=True`, which allows it to be more liberal with the input formats it accepts. Set `fuzzy=False` for more strict validation.
This TemplateTag simply returns a True when it is Naked CSS Day allowing you to hide your CSS or display a custom message on that date. Allows allows for parameters should the date change (again).
This custom processor is meant for use with sorl-thumbnail to add letterboxing functionality.
Add to your THUMBNAIL_PROCESSORS like so:
`THUMBNAIL_PROCESSORS = (
'sorl.thumbnail.processors.colorspace',
'sorl.thumbnail.processors.autocrop',
'sorl.thumbnail.processors.scale_and_crop',
'sorl.thumbnail.processors.filters',
# custom processors
'utils.processors.ltbx',
)
`
and then use in your templates like so:
`
{% thumbnail model.img_field 200x150 ltbx as thumb %}
<img src="{{ thumb }}" width="{{ thumb.width }}" height="{{ thumb.height }}" />`
Enjoy.
This snippet is used to create a script for monitoring sphinx status with Nagios via [django-sphinx](http://code.google.com/p/django-sphinx/).
It returns 0 (OK) or 2 (CRITICAL).
Remember to change this strings `ModelToMonitor` and `app_name`.
Usage :
`./manage your-controls-command --log` > /your/script/name.py
This snippet is used to monitor sphinx status via [django-sphinx](http://code.google.com/p/django-sphinx/).
It returns 0 (OK) or 2 (CRITICAL).
Remember to change this strings `ModelToMonitor` and `app_name`.
Usage :
`./manage your-controls-command --log`