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
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.
ResizeImageField
================
(extension of RemovableImageField)
=================================
by Wim Feijen, Go2People.
What does it do?
----------------
ResizeImageField is a replacement for django's ImageField. It has two major benefits:
1. Creation of thumbnails and scaled images.
1. Extends the image upload form and adds a preview and a checkbox to remove the existing image.
It's easy to use:
- Replace ImageField by ResizeImageField
- No further changes are necessary
Requirements:
-------------
Working installation of PIL, the Python Imaging Library
Usage
-----
- add resize_image to your app
- add resize_filters.py to your templatetags
- in settings.py, set a PHOTO_DIR, f.e. photos/original
- in models.py, add:
- from settings import PHOTO_DIR
- from resize_image import ResizeImageField
- photo = ResizeImageField(upload_to=PHOTO_DIR, blank=True)
Scaled images will be stored in 'photos/scaled',
thumbnails will be stored in 'photos/thumb'.
Access your images from your template. Add::
{% load resize_filters %}
{{ address.photo.url|thumb }}
or::
{{ address.photo.url|scaled }}
Defaults
-------
- Scaled images are max. 200x200 pixels by default
- Thumbnails are 50x50 pixels.
Override the default behaviour in settings.py
Scaling is done by PIL's thumbnail function, transparency is conserved.
Credits
------
This code is an adaptation from python snippet 636 by tomZ: "Updated Filefield / ImageField with a delete checkbox"
This allows you to exclude certain apps when doing standard tests (manage.py test) by default. You set the settings/local_settings variable EXCLUDE_APPS and it will exclude those apps (like django, registration, south... etc). This makes running tests much faster and you don't have to wait for a bunch of tests you don't care about (per say).
You can override it by adding the app to the command line still. So if 'south' is in the excluded apps you can still run:
'python manage.py test south'
and it will run the south tests.
You will also need to tell django to use this as the test runner:
TEST_RUNNER = 'testing.simple.AdvancedTestSuiteRunner'
The popular [soaplib snippet](http://djangosnippets.org/snippets/979/) works only with older soaplib (0.8, for example). This snippet is modifed to work with newer soaplib: it was tested with 0.9.2-alpha3 and 1.0.0-beta4. I've tested suds python client and .NET client.
Automatically activates the virtualenv when running manage.py command.
Just create requirements.pip file inside the root of django project and run ./manage.py update_ve in first time.
Code checks requirements.pip and virtual env timestamps and require to recreate outdated environment.
This decorator function wraps a normal view function
so that it can be read through a jsonp callback.
Usage:
@AllowJSONPCallback
def my_view_function(request):
return HttpResponse('this should be viewable through jsonp')
It looks for a GET parameter called "callback", and if one exists,
wraps the payload in a javascript function named per the value of callback.
Using AllowJSONPCallback implies that the user must be logged in
(and applies automatically the login_required decorator).
If callback is passed and the user is logged out, "notLoggedIn" is
returned instead of a normal redirect, which would be hard to interpret
through jsonp.
If the input does not appear to be json, wrap the input in quotes
so as not to throw a javascript error upon receipt of the response.