The SplitTimeField and the corresponding widget SplitDateTimeWidget show two select boxes with one for hour from 0 to 23 and the other showing minutes 0,15,30 and 45 (can be customized very easily).
Usage:
-------
class TestForm(forms.Form):
start_time = SplitTimeField(widget=SplitTimeWidget)
end_time = SplitTimeField(widget=SplitTimeWidget)
This is a simple FCK editor widget that can be used in newforms in place of Textarea. Obviously it requires [FCKeditor](http://www.fckeditor.net/) and you will need to set the proper import path for that.
This is modification of Django's original adminapplist template tag. You can move your models from one app to other or completely hide them with this mod.
Copy django_dir/contrib/admin/templates/admin/index.html file to your templates/admin folder, open it, then change {% load adminapplist %} to {% load custom_adminapplist %} (or whatever you named the templatetag file)
After that, write your regrouping schema to settings.py file like this;
UPDATED, now using tupples instead of dicts in APP_SCHEMA to make it more DRY.
`
APP_SCHEMA=[
(
['Model','List'],
'From App',
'To App',
),
(
['FlatPage'],
'Flatpages',
'Site Content',
),
(
['Product']
'Product',
'Shop',
),
(
['Site']
'Sites',
#We are hiding Site model by not defining a target.
),
]
`
When writing clean and easy-to-read templates, it's usually good to have structural template tags (e.g. {%for%}, {%if%}) alone on their own line with proper indentation.
When such a template is rendered, the resulting HTML will have blank lines in place of the template tags. The leading blank space used for indentation is also intact.
This template tag strips all empty and all-whitespace lines when rendering the template. Be careful not to apply it when not intended, e.g. when empty lines are wanted inside PRE tags.
**This is a newforms field for OpenID 1 & 2.**
It normalizes and validates OpenID identifiers according to the [spec](http://openid.net/specs/openid-authentication-2_0.html#normalization):
* `xri://=joelwatts` to `=joelwatts`
* `joelwatts.com` to `http://joelwatts.com/`
* `www.joelwatts.com` to `http://joelwatts.com/`
An identifier that is well-formed, but not an OpenID (e.g. `example.com`), will cause a validation error.
Requires [Python OpenID Library](http://openidenabled.com/python-openid/) 2.x.x.
This middleware will add a log of the SQL queries executed at the top of every page, in the form of an IE-like 'infobar'. It also includes a query count and total and per-query execution times.
This snippet is based on snippet #344 "SQL Log Middleware + duplicates" by guettli.
I did some adjustments to the code, to also add support for the application/xhtml+xml mime type, aswell as add the code for the infobar.
Need DEBUG on, aswell as DEBUG_SQL, should not be used on production sites.
It also expects a 16x16 png image called infobar_icon.png, which it is looking for in the /media/images folder (or /static/images, depending on your MEDIA_URL setting). I used a little light bulb icon from the Tango icon set, but am unable to attach the image. Any 16x16 png will do off course.
Update 0.1.1: In the initial version of this middleware, the path to /media/images was hard-coded, and you had to adjust this middleware accordingly. Now, it correctly uses the MEDIA_URL setting from your settings.py file, so you no longer have to edit this middleware.
0.1.2: Made some adjustments to the CSS to get rid of a padding bug when the bar was displayed on a Django error page. Also if a page contains no queries, it won't bother printing an 'empty' table, with just column headers.
0.1.3: More tweaks to the CSS, odd/even row shading on queries table.
0.1.4: More CSS tweaks again
0.1.5: Minor tweaks
0.1.6: Sorry, I just realised that after some time, this snippet broke in the latest SVN of Django with a Unicode error, as arthur78 mentioned.
I have managed to fix it, by wrapping line 258 and 259 in an str() function.
This is a very simple script to do a **simple** migration from plone content to django.
ATNewsItems and PloneArticles are imported into the django model *Article* (with Foreignkey to the django models *File* and *Image*). ATDocuments are imported into the django model *Page*.
**Usage**
1. Make sure that the Python version running Zope can import django
2. The django database should be writeable from within the Zope environment
3. Set the shell variable *DJANGO_MODULE_SETTING* to the settings file of the django project you want to import your Plone content to
4. Start the Zope server in the debug modus:
$ bin/zopectl debug
Then import the python module above, and pass the site you want to migrate to the start function:
import simple_migration
mysite = app.mysite
simple_migration.start(mysite)
Found 1253 objects
Saved Test Document Type: ATNewsItem
...
Hope it helps someone.
Used for the migration of **Plone-2.5.3** content in a **Python-2.4.4** environment.
Formats a number in the local currency format. E.g., if `foo` is equal to `49277`, then
> ` {{ foo|currency }}`
would print
> `$49,277`
If your locale is the U.S. You can use this filter in your templates as described in the [Django documentation](http://www.djangoproject.com/documentation/templates_python/)
This tag is meant to override the current implementation of '{% spaceless %}' tag and remove spaces at the beginning of a line too. I.e. a template like this:
<div>
<div>useless space up front</div>
</div>
will become this
`<div>`
`<div>useless space up front</div>`
`</div>`
All the other behaviour of spaceless stays the same!
Put this in your app/name/templatetags/tags.py
And if you want it to override the default "spaceless"-tag to the following
from django.template import add_to_builtins
add_to_builtins('app.name.templatetags.tags')
In some cases we need to know if we were opened via https from template.
Usage:
{% ifsecure %}using https{% else %}not using https{% endifsecure %}
If you use fastcgi fastcgi_param HTTPS must exists.
This is useful especially during the model-creation stage, when things are in constant flux. The `freshdb` command will drop the project's database, then create a new one. A common use case:
manage.py freshdb
manage.py syncdb
This is a quick and dirty way to import blog entries and comments from Movable Type.
Sorry I don't have time to document it better. Hopefully it will help you get started if you're looking to move from MT to Django.
Almost too dumb to be worth posting but its saved me a lot of typing.
Instead of:
<div>
<a href="{{ object.get_absolute_url }} class="object-icon">{{ object }}</a>
</div>
just put:
<div>{{ object|link }}</div>
Since the decorators of your views are evaluated during parsing urls.py you have an 'chicken - egg' problem. The method reverse() can't be used since urls.py is not read.
This snippets evaluates reverse() lazy.
[Related ticket: 5925](http://code.djangoproject.com/ticket/5925)
Django 1.4 (current trunk) has a lazy reverse.
You're looking at the top-rated snippets currently on the site; if you'd like to contribute, sign up for an account and you'll be able to rate any snippet you see.