clean validation for dynamic form fields
I needed a way to validate non-required, dynamically generated form fields, and clean provided the best solution for this problem.
- forms
- validation
- dynamic-forms
I needed a way to validate non-required, dynamically generated form fields, and clean provided the best solution for this problem.
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 %}
Say you'd like to cache one of your template filters. This decorator acts sort of like memoize, caching a result set based on the arguments passed in (which are used as the cache key).
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.
A middleware to set the httponly flag on the session cookie. Including monkey patching for support for Python <2.6.
A modified version of the original SMTP sink server: [http://www.djangosnippets.org/snippets/96/](http://www.djangosnippets.org/snippets/96/). I've added some nicer, more verbose terminal messages.
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.
Helper function which adds some niceties to the auth/user admin views. Needs django 1.2 to work. ### Usage Define a UserProfile class and set `AUTH_PROFILE_MODULE` as per the [django docs](http://docs.djangoproject.com/en/dev/topics/auth/#storing-additional-information-about-users) In your admin.py file (or anywhere else) add the following: from models import UserProfile from [path to snippet] import upgrade_user_admin upgrade_user_admin(UserProfile)
Adds a View Link button next to the field that opens the contents of the field in a new window.
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'`
Katakana in UTF-8 check
This is just a `AdminDateWidget` with missing JSs added. Don't forget to call `{{ from.media }}` in template.
Middleware to set "sessionid" (ou your session cookie) with httponly (see ["Django bug report"](http://code.djangoproject.com/ticket/3304)). To work, you need put it before "SessionMiddleware"
Inspired by this [terse blog post](http://www.ghastlyfop.com/blog/2008/12/strip-html-tags-from-string-python.html). This filter was designed to simplify the stripping out of all (x)html in a given template var, while preserving some meta information from anchor, and image tags. Why is this even useful? If you have pre-assembled portions of templates, or model fields containing html, that you want to use to populate a *search index* like [django-haystack](http://haystacksearch.org/) you can safely discard all the markup, while keeping the text that should be still searchable. Alt text, and title attributes are worth keeping!
3110 snippets posted so far.