Allow you to specify a "General case formset/modelformset" and then alter the attributes of that formset, specificly: extra, can_order, can_delete and max_num.
So you specify:
>>> formset = AuthorFormSet(queryset=Author.objects.filter(name__startswith='O'))
and then you want to dynamically add multiple fields with javascript and save the new ones. By default a formset only has 1 extra field. With this you can return a new formset (using the same queryset, forms, formset base class, etc) but with different attributes. So you could then add 10 extra fields if the user added 10 new forms.
Tag that can be used as `${ tags.csrf_token() }` in mako templates. Remember to import the tags namespace in your template, as such:
<%namespace name="tags" module="my_app.tags"/>
Small hack to inherit region content from the translated object.
code should be placed in models.py, where the Page object is created.
use feincms version 1.1.2 and above
feincms inherit region page moodboard language mulit-language translation
I'm using the Django Feeds Framework and it's really nice, very intuitive and easy to use. But, I think there is a problem when creating links to feeds in HTML.
For example:
<link rel="alternate" type="application/rss+xml" title="{{ feed_title }}" href="{{ url_of_feed }}" />
Link's `HREF` attribute can be easily found out, just use `reverse()`
But, what about the `TITLE` attribute? Where the template engine should look for this? Even more, what if the feed is build up dinamically and the title depends on parameters (like [this](http://docs.djangoproject.com/en/dev/ref/contrib/syndication/#a-complex-example))?
This is the solution I came up with. However, as you can see, there is some caveats:
* Requires Django 1.2 Class Feeds, don't know exactly how to do this with the old way of feeds.
* If the feed class uses the request object, the `request` [context processor](http://docs.djangoproject.com/en/dev/ref/templates/api/#django-core-context-processors-request) must be configured, since `None` is passed if it isn't present in the context.
* There's an oddity with Feed.__get_dynamic_attr(). The Feed subclass instance doesn't have this method; instead, it appears with another name. Don't know how to figure the name out at runtime...
I've posted this problem on [StackOverflow](http://stackoverflow.com/questions/2784659/django-dry-feeds), but didn't get a better answer.
Writing templatetags is obnoxious. Say you have a small blurb on all your pages that shows the latest 5 comments posted to the site -- using this filter, you could write the following:
{% for comment in "comments.comment"|latest:5 %}
...display comment here...
{% endfor %}
I found my self doing data migration for a client, and also found that their old system (CSV) had 4 text fields that were 2 to 4MB each and after about 2 minutes of hammering the mysql server as I was parsing this and trying to insert the data the server would drop all connections. In my testing I found that if I didnt send those 4 fields the mysql server was happy to let me migrate all my data all (240GB of it). So I started thinking, "I should just store these fields compress anyways, a little over head to render the data, but thats fine by me."
So thus was born a CompressedTextField. It bz2 compresses the contents then does a base64 encode to play nice with the server storage of text fields. Once I started using this my data migration, though a bit slower then without the field data, ran along all happy.
Add `FakeSSLMiddleware` to the top of your `MIDDLEWARE_CLASSES` stack when running tests or developing locally to allow https:// links to operate correctly. Can be used in conjunction with other SSL middleware to allow critical tests to be performed.
It's fixed the right and bottom for each use.
A vertical line is a line with the same right and left, so it fixed the right attribute to be the same value of the left attribute.
A horizontal line is a line with the same bottom and top, so it fixed the bottom to be the same value of the top attribute.
This module contains functions and classes that help integrate the Dojo Toolkit javascript library with Django. Supports defining theme, stylesheets, required modules, and addOnLoad functions from Django. Django form fields can be instrumented to be instantiated as Dijit form objects programmatically.
Full instructions on [limscoder.com](http://www.limscoder.com/2010/04/django-dojo.html).
This is useful when you need to convert a datetime.datetime.now() or datetime.date.today() into a unix epoch seconds, with microsecond precision (precision only applies to datetime.datetime, as datetime.date won't have any microseconds).
I have found this is necessary for when storing the DateTime in the models as a FloatField, in order to keep the usec/microsecond precision.
At some point, I will probably create a custom model field called DateTimeWithUSec or something like that, but for now, this will do :)
This is the same as [{% widthratio %}](http://docs.djangoproject.com/en/dev/ref/templates/builtins/#widthratio) but when the given value is greater than the max_value it just uses the max_value. This way the result is never greater than max_value. It also returns max_width if the max_value is 0 instead of returning a blank string. Usage example: {% smart_widthratio this_value max_value 100 %}
Overrides the `_send` method of the default SMTP `EmailBackend` class to include a [DKIM](http://www.dkim.org/) signature based on settings:
1. `DKIM_SELECTOR` -- e.g. `'selector'` if using `selector._domainkey.example.com`
2. `DKIM_DOMAIN` -- e.g. `'example.com'`
3. `DKIM_PRIVATE_KEY` -- full private key string, including `"""-----BEGIN RSA PRIVATE KEY-----"""`, etc
You'll need [pydkim](http://hewgill.com/pydkim/).
Just include this code in `project_name.email_backend.py`, for example, and select it in your settings file; e.g. `EMAIL_BACKEND = 'project_name.email_backend.DKIMBackend'`
You're looking at the most-bookmarked snippets on the site; if you'd like to help useful snippets show up here, sign up for an account and you'll get your own bookmarks list.