aboutsummaryrefslogtreecommitdiff
path: root/budget/utils.py
diff options
context:
space:
mode:
authorAlexis Metaireau <alexis@notmyidea.org>2011-10-08 13:22:18 +0200
committerAlexis Metaireau <alexis@notmyidea.org>2011-10-08 13:27:30 +0200
commit48bc551853b8b0067cdaeef98b3e454c3249f98f (patch)
tree75332a6548aba9d95e0771de2af0e9e19d53efbc /budget/utils.py
parent402dbce153639668d47db00fdc7a0479d9ebc3f6 (diff)
downloadihatemoney-mirror-48bc551853b8b0067cdaeef98b3e454c3249f98f.zip
ihatemoney-mirror-48bc551853b8b0067cdaeef98b3e454c3249f98f.tar.gz
ihatemoney-mirror-48bc551853b8b0067cdaeef98b3e454c3249f98f.tar.bz2
Complete the REST API + Tests. Fix #27
Diffstat (limited to 'budget/utils.py')
-rw-r--r--budget/utils.py17
1 files changed, 16 insertions, 1 deletions
diff --git a/budget/utils.py b/budget/utils.py
index 88b8580..df165b5 100644
--- a/budget/utils.py
+++ b/budget/utils.py
@@ -17,6 +17,22 @@ def slugify(value):
value = unicode(re.sub('[^\w\s-]', '', value).strip().lower())
return re.sub('[-\s]+', '-', value)
+
+def get_billform_for(project, set_default=True, **kwargs):
+ """Return an instance of BillForm configured for a particular project.
+
+ :set_default: if set to True, on GET methods (usually when we want to
+ display the default form, it will call set_default on it.
+
+ """
+ form = BillForm(**kwargs)
+ form.payed_for.choices = form.payer.choices = [(str(m.id), m.name) for m in project.active_members]
+ form.payed_for.default = [str(m.id) for m in project.active_members]
+
+ if set_default and request.method == "GET":
+ form.set_default()
+ return form
+
class Redirect303(HTTPException, RoutingException):
"""Raise if the map requests a redirect. This is for example the case if
`strict_slashes` are activated and an url that requires a trailing slash.
@@ -39,4 +55,3 @@ def for_all_methods(decorator):
setattr(cls, name, decorator(method))
return cls
return decorate
-