Jcrop Form
Implements a Django form that integrates image uploading plus cropping using the awesome Jcrop plugin (http://deepliquid.com/content/Jcrop.html). NOTE: Still lacks proper error handling...
- image
- jquery
- form
- jcrop
Implements a Django form that integrates image uploading plus cropping using the awesome Jcrop plugin (http://deepliquid.com/content/Jcrop.html). NOTE: Still lacks proper error handling...
forbidden the porn image
This is a small and useful decorator that you can use to protect yourself from bad users or bots hitting your site.
A template tag that includes a modified version of the GET query string. the query string can be manipulated by adding and removing fields. If a value is given that resolves to a context variable that the value of the variable is used. Based on [this snippet by dnordberg](http://djangosnippets.org/snippets/826/), but with the ability to use context and done in a cleaner manner, without the need to add an arbitrary template.
This is a CheckboxSelectMultiple widget that will render its choices divided evenly into multiple ul elements that can be styled nicely into columns. Pass in a css class to the constructor to be assigned to the ul's. See also: http://code.djangoproject.com/ticket/9230
This snippet adds support for OSM maps for GeometryField in Admin TabularInlines. The one possible issue with this snippet is that the OSMGeoInlineForm has to know about the parent ModelAdmin which it does through the code `model_admin_instance = admin.sites.site._registry[self.parent_model]` which won't work if you don't use the default model admin to register the model admin. I'll try and come up with a work around and edit the snippet. Due to the need to mess around with inline style sheets and IE not playing ball with just copying the innerHTML I've settled on using the jQuery.Rule plugin which I've included here as the last version published on the site was incompatible with jQuery 1.4.2 and I found a pathced version online, I also had to modify it due to the Django admin using the compatibility mode of jQuery so there is no global jQuery variable it's django.jQuery instead. 1. Create an osmgeo_inline.py file in your app and copy the top code into it. 2. Create the template file in a directory called admin within a template directory for your app, the template file must be called osmgeo_tabular_inline.html, and copy the middle code into it. 3. Create the jquery rule plugin file in your media or admin-media js directory and copy the bottom code into it. Don't forget to change the OSMGeoInlineForm's class Media's js = ('.....',) to the correct path to the file if need be. 4. In your admin.py you can create inline models using OSMGeoTabularInline just as you would TabularInline. Examples all based on the following in models.py from django.contrib.gis.db import models class MyModel(models.Model): name = models.CharField(max_length=64) route = models.LineStringField(srid=settings.WGS_SRID) class MySubModel(models.Model): mymodel = models.ForeignKey(MyModel) name = models.CharField(max_length=64) location = models.PointField(srid=settings.WGS_SRID) Example 1 - basic usage (admin.py): from django.contrib.gis.admin import OSMGeoAdmin from myapp.osmgeo_inline import OSMGeoTabularInline from myapp.models import MyModel, MySubModel class MySubModelInline(OSMGeoTabularInline): model = MySubModel class MyModelAdmin(OSMGeoAdmin): inlines = [MySubModelInline] admin.site.register(MyModel, MyModelAdmin) Example 2 - overriding the default map widget params and setting the inline map's centre point to match the main models map centre (admin.py): from django.contrib.gis.admin import OSMGeoAdmin from myapp.osmgeo_inline import OSMGeoTabularInline from myapp.models import MyModel, MySubModel class MySubModelInline(OSMGeoTabularInline): model = MySubModel class MyModelAdmin(OSMGeoAdmin): inlines = [MySubModelInline] params = {'map_width: 200, 'map_height': 200] def get_formset(self, request, obj=None, **kwargs): centre = None if obj is not None: centre = obj.route.centroid.transform(900913, clone=True) self.params['default_lon'] = centre.coords[0] self.params['default_lat'] = centre.coords[1] self.params['default_zoom'] = 12 return super(TrailSubmissionInlineBase, self).get_formset(request, obj, **kwargs) admin.site.register(MyModel, MyModelAdmin) I've not looked at StackedInlines because I don't use them but all that would be needed is to add a class OSMGeoStackedInline(StackedInline) that was a copy of OSMGeoTabularInline but with a template based on the StackedInline template - the javascript code in var initMap = function(row) would probably have to be adapted though.
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 is a merge function for django admin
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'
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.
Use django_openid_auth from https://launchpad.net/django-openid-auth to authenticate your users with their Google Account. This snippet will allow your users having a Google Account address as username to log in using it.
A simple template filter for parsing tweets (linking @ replies, hashtages and standard URLs whilst stripping out links to yFrog and TwitPic images), and two simple tags for displaying the yFrog and TwitPic images linked to in tweets. If you put the snippet in a file called tweets.py, as long as it lives in an app's templatetags directory, you should be able to do the following (where `text` refers to the text of a tweet): {% load twitter %} <p>{{ text|tweet }}</p> {% yfrog_images text 1 'fancybox' %} {% twitpic_images text 1 'fancybox' %} The first argument in the two tags controls how many images to render. Set this to -1 for an unlimited number, per tweet. Thumbnail images are displayed, and you can specify the class that is applied to the `<a>` tags rendered. Here I've used 'fancybox', and I would normally include jQuery code to turn the images inside the `<a>` tags into lightboxes.
Using jQuery UI (with Grappelli in use) to add "drag and drop" reordering of items in the admin list view. The model must have an "order" field to store the order value in.
Sometimes you want more rendering control than common widgets give you. We wrote this, for example, to allow rendering the checkboxes of a multi select field with checkbox widget, as multiple columns. Place this in the templatetags subdirectory of an app you are loading (be sure it has a __init__.py file), and load it something like this (you may want to shorten the name): {% load checkboxiterator_filter %} Then you can say something like: {% for checkbox in form.categories|checkboxiterator %} {# other code #}{{ checkbox }}{# other code #} {% endfor %} where form.categories is a multiple select field (no doubt this technique could be applied to radio buttons and a single select field). The filter does use some internal interfaces, but may well still work on newer Django version.
3110 snippets posted so far.