Humanized and localized version of built-in *timesince* template filter.
Based on [Joey Bratton's idea](http://www.joeyb.org/blog/2009/10/08/custom-django-template-filter-for-humanized-timesince).
This slugify correctly transliterates special characters using the translitcodec package from PyPI.
Make sure you've installed http://pypi.python.org/pypi/translitcodec/ before using this.
look ma, no api!
a python method for [fabric](fabfile.org) script to send a message to your [campfire](campfirenow.com) chat room.
not really a django script but I didn't know where else to put it. I use it to send a deployment messages to campfire when we deploy new revisions. like the comment mentions, put your api key in ~/.fabricrc.
the example api key is garbage so don't waste your time.
This assumes that you have a method called **decode_signed_request** which will validate the signed_request parameter and return None if the validation check fails.
A similar method can be found here - https://github.com/iplatform/pyFaceGraph/blob/70e456c79f1ac1c7eddece03af323346a00481ef/src/facegraph/canvas.py
In one situation I needed to join strings in template, so I wrote this filter.
Use it like this:
1)
var = 23
{{"I have eat %d apples today."|joinstrings:var}}
-> "I have eat 23 apples today."
var = '23'
{{"I have eat %s apples today."|joinstrings:var}}
-> "I have eat 23 apples today."
2)
var = [23, 45] #or any iterable object (except string - see pt. 1)
{{"I have eat %d apples and %d pears today."|joinstrings:var}}
-> "I have eat 23 apples and 45 pears today."
Ok let's descrive what i have done
I subclassed the django admin to create a form that makes you choose if activate a delete and replace login inside your admin.
Then i have added a form with a modelChoiceField to make you select another model instance when you are selecting an istance to delete. If you select another instance the current instance will be replaced.
A custom templatetag for inlining image in the browser.
The principe is to base64 encode the image and avoid a http request.
There is a cache handling, you just have to specify a writable directory.
An example of the utilisation (template part): [http://djangosnippets.org/snippets/2267/](http://djangosnippets.org/snippets/2267/)
The explication on [http://raphaelbeck.wordpress.com/2010/11/14/make-inline-images-to-improve-performance-with-django-template-tags/](http://raphaelbeck.wordpress.com/2010/11/14/make-inline-images-to-improve-performance-with-django-template-tags/)
The example of the Image inlining template tag lib which inline images in the browser instead of making an Http request.
The lib is available at : [http://djangosnippets.org/snippets/2268/](http://djangosnippets.org/snippets/2268/)
Example usage:
Add static var with static value to get :
{% urlget 'var'='val' %}
Add dynamic val (from template vars) to static variable:
{% urlget 'var'=val %}
Using dynamic variable names works similiar - adding dynamic varialbe (from template vars) :
{% urlget var='val' %}
Clearing variable from GET string :
{% urlget 'var'='' %}
Retrieving GET string:
{% urlget %}
An accept middleware, which is based on the code of http://djangosnippets.org/snippets/1042/ but adds a workaround for the buggy accept header, sent from webkit browsers such as safari and chrome.
The workaround affects any accept header, that has xml and (x)html in the best q, but also the xml mediatype at first place in the list.
If this is the case, the header is rearanged, by shifting the xml mediatype to become the last element of the best quality entries in the header.
If the workaround did manipulate the header, and there is a html entry in the list with lower quality as an xhtml entry that is also in the list (with best q), then the html entry is also raised in q to be one entry in front of xml.
This is an expanded version of ["Resolve URLs to view name"](http://djangosnippets.org/snippets/1378/) without the monkey-patching.
Simply pass in a URL such as '/events/rsvp/some_conference/' and you'll get back the view name or function (if name isn't available) and the arguments to it, eg 'events_rsvp', [], {'event_slug':'some_conference'}.
Example (blatantly copied from previous snippet):
=== urlconf ====
urlpatterns = patterns(''
(r'/some/url', 'app.views.view'),
url(r'/some/other/(?P<url>\w+)', 'app.views.other.view', name='this_is_a_named_view'),
url(r'/yet/another/(?P<url>\w+)/(\d+)', 'app.views.yetanother.view', name='one_with_args'),
)
=== example usage in interpreter ===
>>> from some.where import resolve_to_name
>>> print resolve_to_name('/some/url')
('app.views.view',[],{})
>>> print resolve_to_name('/some/other/url')
('this_is_a_named_view',[],{'url':'url'})
>>> print resolve_to_name('/yet/another/url/5')
('one_with_args',[5],{'url':'url'})
From [fahhem.com](http://fahhem.com/) and [Recrec Labs](http://recreclabs.com/)
This is an updated snippet based on http://djangosnippets.org/snippets/2260/
The updated snippet can limit the filtering options for a foreign key field to only those entries that are related to the current model. I.e. if you have an Author model with a FK to Institution model, you can configure Author's changelist to include a filter on Institution, but only allow you to select institutions that have authors. Institutions that do not have authors won't show up on the list.
To enable this, in your model's ModelAdmin class, set
<fieldname>_fk_filter_related_only=True
<fieldname>_fk_filter_name_field=<display this field of the related model in filter list>
For example, in your AuthorAdmin class, you can do
institution_fk_filter_related_only=True
institution_fk_filter_name_field='name'
Note that for the effect described above to work, you just need the last few lines of the big else clause in __init__, so if you don't care about filtering by FK property, you can just grab those few lines and create a simpler FilterSpec.