2 Makes an iteratable object out of the given value. If value is already
3 iterable, it is simply returned. An exception is made for strings, which
4 are treated as non-iterable (It is assumed that you never want to have a
5 list of characters). For non iteratable values or strings, a list
6 containing only value is returned.
9 if (not isinstance(value, basestring)):
16 # vim: set sts=4 sw=4 expandtab:
19 Decarator that catches any exception raised by the decorated function,
20 prints it to stdout and raises it again.
23 def show(*args, **kwargs):
25 return func(*args, **kwargs)
32 def make_choices(objects):
34 Transforms a list (or iteratable) of model objects to a list
35 suitable to be used as a list of choices in form widgets like
38 This fullfills a similar (but simpler) function as
39 django.forms.models.ModelChoiceIterator, but that one requires a
40 FormField and is not public.
42 return [(o.pk, o) for o in objects]
44 def filter_choices(choices, filter):
46 Returns the given choices list with only the choices with the names
47 in filter left. For example, when a model defines
55 you can later define a modelfield using
57 foo = ChoiceField(choices=filter_choices(Foo.FOO_CHOICES, [Foo.A]))
59 return [(name, value) for (name, value) in choices if name in filter]