Add this to any admin changelist and your actions drop-down will be replaced with user-friendly buttons.
Why mess around with templates and subclassing admin classes when you can just mangle the page with jQuery! ;-)
It also adds a 'select all' label to explain the mystery top check-box (well it was a mystery to several of my clients).
The line "if ($('div.actions option:gt(0)').length<=8)" checks that there aren't more than 8 actions and falls back to the drop-down if there are.
Requires jQuery to be loaded.
A general AntiSpamModelForm using some tricks to prevent spam based on current [django.contrib.comments.forms](http://code.djangoproject.com/browser/django/trunk/django/contrib/comments/forms.py). It uses a timestamp, a security hash and a honeypot field. See [AntiSpamForm](http://www.djangosnippets.org/snippets/1925/) too.
This is a basic view for exporting data from models. It is designed so that you can provide the GET variables used for searching/filtering within listdisplay pages in the admin, and the code will filter the same way.
It allows ouputting of model data in various formats using serializers.
This should be used as a urlpattern through get_url, so that you can use the admin_view decorator to properly secure the data.
Add the decorator to an already defined templatetag that returns a Node object:
@with_as
def do_current_time(parser, token):
...
return a_node
The decorator will patch the node's render method when the "as" syntax is specified and will update the context with the new variable. The following syntaxes are available:
{% current_time %}
{% current_time as time %}
{{ time }}
When running the Django development server, this middleware causes all executed SQL queries to get printed out to the console.
This is based on [Snippet 161](http://www.djangosnippets.org/snippets/161/). The big difference is that 161 logs by adding stuff to your response text, which isn't very convenient IMO.
This tag is designed to facilitate pagination in the case where both the page number and other parameters (eg. search criteria) are passed via GET.
It takes one argument - a dictionary of GET variables to be added to the current url
Example usage:
{% for page_num in results.paginator.page_range %}
<a href="{% append_to_get p=page_num %}">{{ page_num }}</a>
{% endfor %}
Note that the passed arguments are evaluated within the template context.
This is a small approach to have a middleware which automatically creates a ticket in an existing Trac environment.
**Note:** you must have the [XML-RPC-Plugin](http://trac-hacks.org/wiki/XmlRpcPlugin) installed.
Extend the attrs-dict to your needs. For example: in my case I have the SensitiveTicket-Plugin installed - automatically created tickets are marked as sensitive and are not visible to the public.
this function invalidates a template-fragment cache bit.
say you have:
{% load cache %}
{% cache 600 user_cache user.id %}
something expensive here
{% endcache %}
maybe you want to force an update. With this function you can, just call:
invalidate_template_cache("user_cache", user.id)
List of countries based on the ISO 3166-1 standard.
List adapated from http://opencountrycodes.appspot.com/python/
This is useful for certain services such as Protx that requires countries in the two letter standard.
This filter links twitter user names prefixed with '@', hash tags, and URLs.
Usage example:
`{{var|twitterize}}`
Note: Do not use this in conjunction with the urlize filter. Twitterize does this for you.
Hook the show_url_patterns view function in to your URLconf to get a page which simply lists all of the named URL patterns in your system - useful for if your template developers need a quick reference as to what patterns they can use in the {% url %} tag.
Call a function for each element in a queryset (actually, any list).
Features:
* stable memory usage (thanks to Django paginators)
* progress indicators
* wraps batches in transactions
* can take managers or even models (e.g., `Assertion.objects`)
* warns about `DEBUG`.
* handles failures of single items without dying in general.
* stable even if items are added or removed during processing (gets a list of ids at the start)
Returns a `Status` object, with the following interesting attributes
* `total`: number of items in the queryset
* `num_successful`: count of successful items
* `failed_ids`: list of ids of items that failed
You're looking at the most-bookmarked snippets on the site; if you'd like to help useful snippets show up here, sign up for an account and you'll get your own bookmarks list.