An email address obfuscation template filter based on the ROT13 Encryption function in Textmate's HTML bundle.
The filter should be applied to a string representing an email address. You can optionally pass the filter an argument that will be used as the email link text (otherwise it will simply use the email address itself).
Example usage:
{{ email_address|obfuscate:"Contact me!" }}
or
{{ email_address|obfuscate }}
Of course, you can also use this on hardcoded email addresses, like this:
{{ "[email protected]"|obfuscate }}
Get the referer view of a request.
**Example:**
def some_view(request):
...
referer_view = get_referer_view(request)
return HttpResponseRedirect(referer_view, '/accounts/login/')
TwitterBackend is the twitter authentication backend. This backend makes use of OAuth based "Sign-in with Twitter"
Configure your settings.py as per [Django - Specifying Authentication Backends](http://docs.djangoproject.com/en/dev/topics/auth/#specifying-authentication-backends)
If you want all the objects in your models' admin interface to have a direct link to their databrowse page (just like the *history* link).. follow these steps:
1) copy the *change_form.html* admin template in mytemplates/admin/
2) edit *change_form.html* by adding this code right next to (before or after) the following line (=the history button markup):
`<li><a href="history/" class="historylink">History</a></li>`
3) Make sure that all of you models are registered with [databrowse](http://docs.djangoproject.com/en/dev/ref/contrib/databrowse/)
That's it. Obviously if you don't want ALL the models to have this link, you should use a different recipe, for example this one: [http://www.djangosnippets.org/snippets/1016/](http://docs.djangoproject.com/en/dev/ref/contrib/databrowse/)
Caches a view based on the users language code, a cache_key and optional
function arguments. The cache_key can be a string, a callable or None. If
it's None, the the name of the decorated function is used.
You can pass a tuple `func_args` of arguments. If passed, these arguments
are part of the cache key. See examples for details.
This is just a reusable convenience parent class to allow you to create and administer an automatic user profile class using the following code:
class UserProfile(UserProfileModel):
likes_kittens = models.BooleanField(default=True)
Whenever a `User` object is created, a corresponding `UserProfile` will also be created. That's it.
NB: You will still need to set `AUTH_PROFILE_MODULE` in your settings :-)
(PS: It would also be nice to have the resulting class proxy the `User` object's attributes like django's model inheritance does, while still automatically creating a `UserProfile` object when a `User` object is created :-)
Takes a float number (23.456) and uses the decimal.quantize to round it to a fixed exponent. This allows you to specify the exponent precision, along with the rounding method. And is perfect for monetary formatting taking into account precision.
This snippet monkey-patches Django's reverse() method (use for generating URLs from vew functions and parameters) to allow certain areas of your site to automatically have URLs with the correct SSL domain in place.
This saves you from having to use unnecessary redirects to guide users to an SSL-encrypted version of a page. This should still be used alongside a redirect-based method (such as [this snippet](http://www.djangosnippets.org/snippets/85/)) to ensure that the user can't access an unencrypted version of the page
Simply add the code to the files mentioned in the code.
This obviously won't work anywhere that doesn't use reverse(), the admin app seems to be an example of this.
A template filter which wraps imagemagick's `convert` command. The filter acts upon a source image path, and returns the filtered image path.
usage: {{ source_path|convert:"-resize 64x64\!" }}
The filter parameter is the processing arguments for an ImageMagick 'convert' command. See e.g. http://www.imagemagick.org/Usage/resize/
Every image created is saved in a cache folder. This code does not handle removing obsolete cached images. If the filtered image path exists already, no image processing is carried out, and the path is returned.
If you would like to see the latest queries you have done when running a unittest, this is not so easy. You have to initialize the queries list and set DEBUG to True manually. Then you have to figure out a way to print the queries you want to see just now and format them. I.e., monitoring queries when doing TDD is a bit of a hassle, and this should help.
This little helper does all this for you; your UnitTest only needs to import django.db.connection and store the current length (offset) of the queries list. Then, using Python's coroutine functionality, all you have to do is send that offset to the QueryPrinter coroutine (which you can, for example, initialize as a global variable or a class variable of your UnitTest) and you get the latest SQL printed as a simple table.
This is a custom field for multiple emails separated by comma. Original code was replaced by code from Django documentation: http://docs.djangoproject.com/en/dev/ref/forms/validation/ (MultiEmailField) so i'm not the author of the code, but just put it here to replace an outdated solution.
Uses code from mksoft comment http://www.djangosnippets.org/snippets/1093/
The template filter is use for split a string such as "foo|foobar|bar" to select option widget.
You can define the splitter of the string by yourself.
**Usage:**
Add the code into templatetags folder of a installed app, then add below code into your template file.
`
{% load split_as_option %}
<select name="widget_name">
{{ QuerySet.values|split_as_option:"|" }}
</select>
`
Let's say you have a dataset and you want to render a page with sections/subsections/subsubsections down to some arbitrary depth and with arbitrary keys. For example, you might want to show cars broken out by year/price_range or price_range/year or price_range/manufacturer/model. The outliner template tag allows you to support multiple breakdowns of your data in a DRY sort of way.
In order to use it, you supply four things:
1. a template for surrounding each subsection (think turtles all the way down)
2. a queryset (really anything iterable)
3. sectionizer dictionary/objects (see sample code, you must supply key_method)
4. inner html to render the lowest subsections
The template provides the following:
1. It recursively uses each of your sectionizers' key methods to divvy up data sets.
2. It surrounds each section with templates of your choosing.
3. It renders the inner template for all the "leaf" elements of your tree.
4. It supplies some handy context vars for things like depth and outline ids.
What this is not:
1. this is not for arbitrary tree data--think of the tree as fixed depth
2. this is not as simple as the regroup tag--if you have a concrete organization to your data, you should keep it simple and hand-code your templates
DEPRECATED: Django has cookie based messages since version 1.2
This messages stores messages for the user in a cookie. I prefer this to session based messages, because the session column is a hot spot in the database if one user
works with several browser tabs/windows.