This Field, Widget and the three lines of code in the form's clean method allow an easy (and hopefully general) way to add simple, unchangable text to a form.
Example use:
class OnlyTextForm(forms.ModelForm):
points = StaticField(label=_('Points'))
reviewer = StaticField(label=_('Reviewer'))
def clean(self):
for name, field in self.fields.items():
if isinstance(field, StaticField):
self.cleaned_data.update({name: self.initial[name]})
return self.cleaned_data
This is the pavement file I use to deploy a django site. It's in early stages. Right now it copies everything up to the desired server over scp. But I think I'll change it to rsync in the future.
It requires pavement, and pexpect.
The pavement file takes slight instruction from your settings.py file. For server information, and "lib_apps" to copy into the lib directory.
An example of a settings file that I use with this pavement file:
http://gitweb.codeendeavor.com/?p=django_empty.git;a=blob_plain;f=settings.py;h=23bda7d2a1eb2a52ca0859004ecccd206dade4ec;hb=5d672178dab282caeed5ff0de7ed807c72e44f74
Specifically, check out the bottom for two vars: "LIB_APPS" and "DEPLOYMENTS"
A good example of my empty django project is here:
http://gitweb.codeendeavor.com/?p=django_empty.git;a=tree;h=5d672178dab282caeed5ff0de7ed807c72e44f74;hb=5d672178dab282caeed5ff0de7ed807c72e44f74
I think the one thing that's missing is a way to re-spawn fcgi processes. Which I'll hopefully get around to adding sometime soon.
Also, I need to do a little work at making sure source control files don't get pushed through scp.
For most applications, simplejson.dumps() is enough. But I’m especially fond of iterators, generators, functors (objects with a `__call__()` method) and closures, dense components that express one thought well: the structure of a tree, or the rows of a database, to be sent to the browser. The routine dumps() doesn’t understand any of those things, but with a simple addition, you can plug them into your code and be on your way without headache. Dumps() just calls JSONEncoder(), and JSONEncoder has a routine for extending its functionality.
The routine is to override a method named default() (why “default?” I have no idea) and add the object types and signatures you want to send to the browser. Normally, this exists for you to provide custom “object to JSON” handlers for your objects, but there’s nothing custom about iterators, generators, functors and closures. They are native Python objects. This snippet provides the functionality needed by JSONEncoder to correctly dereference these useful Python objects and render their contents.
(Originally posted [here](http://www.elfsternberg.com/2009/05/20/fixing-an-omission-from-djangos-simplejson-iterators-generators-functors-and-closures/) )
This class generates a crows-foot notation ERD for your models (currently does not include fields) using GraphViz. The cardinality/modality of the relationships isn't perfect, but it works for 99% of cases out there.
This snippet parses the output file of inspectdb and does some alterations. Mostly useful for people who regenerates models from constantly changing legacy databases.
The snippet will:
*Add quotes around foreign key classes, so the ordering is not significant
*Append a related_name property to each foreign key with the value
model class name + db_column name to evade collisions in reverse queries like:
example.model: Reverse query name for field 'foreignkey' clashes with related field 'model2.foreignkey'. Add a related_name argument to the definition for 'foreignkey'.
There's a slight performance degradation with using quotes class name instead of passing the class though.
A mixin to define permissions on models. This is more of an abstract model to subclass/customise than a plug-in solution. Explanations are [here](http://www.muhuk.com/2009/05/django-permission-system/).
This commands runs a Python interactive interpreter with test database and data from the given fixture(s). It is usable if you want to play with test database.
See also testserver docs
Default to a static template.
**Example:**
urlpatterns = patterns('',
...
# this rule SHOULD BE the last one
(r'^(?P<template>[a-z-_/]+/?)?$',
'myproj.apps.myapp.views.static_template'),
)
Put it in appname/templatetags/truncatehtml.py and load it with {% load truncatehtml %}, then for instance {{ some_story|truncatehtml:100 }} to truncate the story to 100 characters.
Tags are not counted in the length given, and character entities count as one character.
The filter should never break an open-tag text close-tag sequence without adding in the close tag. It will also preserve character entities. It won't sanitize the HTML, though: garbage in, garbage out.
There's a bit more info about how it works in a [blog post](http://ole-laursen.blogspot.com/2009/05/safe-truncation-of-html.html) I wrote.
List of countries based on the ISO 3166-1 standard.
List adapated from http://opencountrycodes.appspot.com/python/
This is useful for certain services such as Protx that requires countries in the two letter standard.
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.