This is a simple way to embed images in emails, rather than use absolute links, which many clients will not show by default. It has not undergone extensive testing but it should get you started. Comments / suggestions welcome.
A simple template filter for breaking a list into sublists of a given length, you might use this on an ecommerce product grid where you want an arbitrary number of rows of fixed columns. Unlike the other partitioning filters I've seen, this doesn't try to distribute the rows evenly, instead it fills each row for moving onto the next.
This filter preserves the ordering of the input list.
This code monkey-patches the default User model to rather use a primary key of UUIDField (see http://www.djangosnippets.org/snippets/1496/). This code also makes the email field required. This code is wildly dangerous, not completely future proof, and probably not advisable to use. If you do wish to use it, it will be easiest to implement on a fresh db with a syncdb. If you need to migrate existing user data the onus is on you to figure out an appropriate db migration plan.
I placed this code in a models.py, but it is probably more reliably placed in urls.py
A simple jQuery javascript that collapses all stacked inline rows for better handling of large inline fieldsets.
It also adds "Show"/"Hide"-buttons for showing/hiding each row, which could be customized and styled using css.
**Usage (see below for example):**
Include the javascript on your admin page, together with jQuery, and it'll automatically affect all stacked inlines.
**Developed for:**
* jQuery 1.3.2
* Django trunk (tested in Django v1.0.2)
* (Might work with other versions with or without adjustments, but not tested)
**Use example: **
*admin.py:*
class DateInline(admin.StackedInline):
model = Date
extra = 10
class EventAdmin(admin.ModelAdmin):
inlines = [DateInline]
class Media:
js = ['js/jquery-1.3.2.min.js', 'js/collapsed_stacked_inlines.js',]
admin.site.register(Event, EventAdmin)
A simple tag to render breadcrumbs.
Usage:
{% load breadcrumbs %}
{% breadcrumbs "['Home','Home','home']" "['Articles','Articles','articles']" "['object','object','object.get_absolute_url']" %}
Loads up the template in "modules/breadcrumbs.html" and renders it with a list of items.
You can provide the tag either with plain text stuff and named urls as the third argument ( any more arguments per bracket-block is parsed as args / kwargs for the reverse() call ) or the object directly, and the script tries after failing the reverse() to resolve the provided arguments.
Have pun.
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)
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.
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.
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>
`
Shows the timesince to the user and then on mouseover it will display the exact time for allowing the user to see the exact time.
Example: shows "about 1 day, 3 hours ago" and then changes on mouseover to read "at 3:05pm on Wednesday 22nd April 2009"
Based on [http://www.djangosnippets.org/snippets/662/](http://www.djangosnippets.org/snippets/662/) and updated to be runnable as custom django management command. Also added option support for --exclude=someapp --exclude=otherapp.SomeModel
From original description:
InnoDB tables within MySQL have no ability to defer reference checking until after a transaction is complete. This prevents most dumpdata/loaddata cycles unless the dump order falls so that referenced models are dumped before models that depend on them.
Caveats
1. You use this snippet to dump the data and the built in manage.py loaddata to load the fixture output by this program. A similar solution could be applied to the XML processing on the loaddata side but this sufficed for my situations.
2. This code does not handle Circular or self-references. The loaddata for those needs to be much smarter
This is an extended version of django wizard with the ability to go back
and execute any step directly.
To define next step to execute use the form field with the name
"wizard_next_step".
Don't forget to specify in your form the wizard_max_step field, so the
knows the step number with the highest number, where the user was.
An other improvement is the variable "wizard_data". It's a QueryDict with
data from all wizard forms. It can be used to retrieve values from the
field values of the forms from other steps. It could be helpfully for
the latest step, where the user should see an overview of his input.
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
You're looking at the top-rated snippets currently on the site; if you'd like to contribute, sign up for an account and you'll be able to rate any snippet you see.