Decorator
[Understanding Python Decorators in 12 Easy Steps!] (http://simeonfranklin.com/blog/2012/jul/1/python-decorators-in-12-steps/)
- decorator
[Understanding Python Decorators in 12 Easy Steps!] (http://simeonfranklin.com/blog/2012/jul/1/python-decorators-in-12-steps/)
I wanted to be able to share common code among a subset of views without copy-and-pasting the code or the same function into each view, so I decided to wrap a class around the views so that the common code (i.e. loading a model that each of the views would affect) can go in the __init__ of that class. I created the controller_view function above to allow the urls to access those class methods. It would be called something like this: url(r'^someview$', controller_view(SomeController, 'someview'), name='someview'), Where the SomeController inherits (or is structured like) the Controller class above and implements __init__ and someview as methods. I'm new to Django so it's entirely possible I've missed something that already does this or that makes this unnecessary. If so, let me know so that I can figure out how to do this right, otherwise, hopefully this is helpful to someone else out there.
qwe
This is a javascript to call in the Media class of the ModelAdmin instance for the model, requires some additional css. The goal of such approach is that the add related functionality is supported, and works also with the django-mptt model fields. The new component can support resize functionality, in such case the jquery-ui resizable script is needed. For a complete documentation on this, and how to use it inside your project please visit this [blog post](http://www.abidibo.net/blog/2013/04/10/convert-select-multiple-widget-checkboxes-django-admin-form/)
Adds a CSV export action to any Django model admin that inherits it.
This snippet is an extension of [i18n base model for translatable content](http://djangosnippets.org/snippets/855/) so all the same usage applies. I have extended this module in several ways to make it more fully featured. * `I18NMixin` can be an additional (via multiple inheritance) or alternative superclass for your models juxtaposed with an `I18NModel`. * Adds a property `_` to access the appropriate I18NModel. `trans` aliases this (or rather vice versa) for template access. * In a call to `.filter` you can query on translated fields by wrapping those fields in a call to i18nQ. I like to import this as _ if I haven't already used that import. * A call to I18NFieldset will return an inline for use in the builtin admin app. I like to call this inline to the assignment to inlines. * If you need abstracted access to the I18N model from a model, I've added a property I18N referring to it. I've been using this with great convenience and stability.
nothing to see here...
In Django 1.5 url tags require you to pass in the name of the url as a string. So where you used to be able to do this {% url home_page %} you now have to do this {% url 'home_page' %} Upgrading an old project can be a pain, so here is a snippet for a py file that will update all your url tags. Just put it in a py file in your root directory and execute it. The error you get otherwise is: 'url' requires a non-empty first argument. The syntax changed in Django 1.5, see the docs.
[code] {% get_video_urls url as url_object %} or get object attribute: {% get_video_urls obj "url" as url_object %} {{ url_object }} original url {{ url_object.video_id }} original url or video_id {{ url_object.resource }} youtube, vimeo, None {{ url_object.iframe_url }} original url or iframe_url {{ url_object.js_api_url }} original url or js_api_url [/code]
Custom form widget for rendering an autocomplete (using jQuery UI's autocomplete widget) text input in a template. This arose from the need to have all fields asking for a state to use autocomplete, so I decided to make this.
Serializes all models of a resource to json. Borrowed from https://github.com/toastdriven/django-tastypie/issues/442
This is a authentication backend for Django, to authenticate via Active Directory. This pulls all group information out of Active Directory and allows for multiple group memberships.
This is my POC code for a progress bar backend (for delivering JSON to some AJAX frontend) in Django using Django-Celery (with RabbitMQ). It is quite concise, yet it took me a while to get there because Celery's Documentation is IMHO rather puristic. Web development is meant to be copy-paste! Here you go!
South documentation [contains a description](http://south.readthedocs.org/en/0.7.6/fixtures.html#fixtures-from-migrations) of the way you can load fixtures inside the data-migrations. def forwards(self, orm): from django.core.management import call_command call_command("loaddata", "my_fixture.json") It seems pretty clear and easy, but in fact it does not work the way you expect from south migrations, because the fixture loading does not engage the **orm** object. So, it allows **loaddata** management command to use standard models loading mechanism, and it would provide the most recent version of the models, obviously, which may not correspond to the schema of the fixture`s data. To be ensured that migration will use appropriate version of the models for fixture loading you could use code like follows: class Migration(DataMigration): def forwards(self, orm): load_fixture('my_fixture.json', orm) class Migration(DataMigration): def forwards(self, orm): with southern_models(orm): call_command("loaddata", "my_fixture.json")
Allows you to include content from flatpages in class-based views. You can specify the url for the flatpage you want, or let it be determined by request.path.
3109 snippets posted so far.