For those interested in making a mobile site geared toward the higher end devices, and wanting a little leverage over device-specific quirks.
These are the big players in the U.S. market, but of course, add your own User-Agents to match your audience's popular browsers.
Usage:
<html class="{{ device.classes }}">
You can also leverage template logic:
{% if device.iphone %}
<p>You are browsing on
{% if device.iphone = "iphone4" %} iPhone 4
{% else %} an iPhone pre-version 4{% endif %}
</p>
{% endif %}
This view has the same functionality as Django's builtin static view function but when the configuration option `USE_XSENDFILE = True` is specified in the settings it returns the absolute path of the file instead of its contents.
This allows the mod_xsendfile module in Apache or Lighttpd to take care of efficiently serving the file while still allowing for Django to take care of other processing of the request, like access control or counting the amount of downloads.
This very simple templatetag can take event objects from django-event-calendar and create the appropriate URLs to automatically allow users to add events from your website to Google calendar.
This is a fairly straightforward view to generate iCalendar (.ics) files, with a unique UUID, a proper filename, and the basic fields needed to export an event from a public calendar (using the django-events-calendar app). While it can certainly be extended and adapted, it works very well as-is.
launch python manage.py yourcommand
and command output paste into http://www.yuml.me/diagram/scruffy/class/draw
todo:
1.implement other relation attributes
2.add class inheritance
3.download image automatically
4.generate diagram for specific app
I'm on my own personal writing challenge (see 750words.com for inspiration). I needed a way to get a dynamic word count, so I threw this together. Tied into django-basic-blog easily.
This snippet implements an authentication backend for MoinMoin user accounts. If you have a MoinMoin running on the same server which has users, you can allow those users to sign into a Django site with the same username and password.
To use, define the following settings:
MOIN_DATA_DIR = "/path/to/moinmoin/data/dir"
AUTH_BACKENDS = (
'django.contrib.auth.backends.ModelBackend',
'<this snippet module>.MoinMoinBackend',
)
# optional list of groups that authenticating users must be in
MOIN_AUTH_GROUPS = ["EditorGroup",]
**UPDATE: Now works in Django 1.4**
Based on luc_j:s snippet (http://djangosnippets.org/snippets/2108/) to show values in ManyToManyFields in the admin. This snippets does that, but also links each value to its corresponding admin change page.
To use, just set the raw_id_fields to the value you want, and let your form inherit from ImproveRawIdFieldsForm.
This is a different take on polymorphic inheritance, inspired by SQLAlchemy's approach to the problem.
The common Django approach (e.g. snippets 1031 & 1034, [django_polymorphic](http://github.com/bconstantin/django_polymorphic)) is to use a foreign key to `ContentType` on the parent model and override `save()` to set the right content type automatically. That works fine but it might not always be possible or desirable, for example if there is another field that determines the "real type" of an instance.
In contrast this snippet (which is actually posted and maintained at [gist.github](http://gist.github.com/608595)) allows the user to explicitly specify the field that determines the real type of an instance. The basic idea and the terminology (`polymorphic_on` field, `polymorphic_identity` value) are taken from [SQLAlchemy](http://www.sqlalchemy.org/docs/orm/inheritance.html).
Some other features:
* It works for proxy child models too, with almost no overhead compared to non-polymorphic managers (since there's no need to hit another DB table as for multi-table inheritance).
* It does not override the default (or any other) model Manager. Regular (non-polymorphic) managers and querysets are still available if desired.
* It does not require extending a custom Model base class, using a custom metaclass, monkeypatching the models or any kind of magic.
This will allow you to attach HTML multipart emails (HTML/text) and use inline images.
In my example, I'm attaching an image that's stored as an 'attachment' to an 'event.' The file name of the attachment is called "inline.jpg" and I'm referencing it in my HTML message. I'm also attaching a VCAL file (.ics) file that has some information about an associated event.
This basically takes the debug you get from setting debug=True, but instead, pipes it into an email and sends it over to you.
I have extracted this out of our de framework, it should work, but some modifications may be necessary.