summaryrefslogtreecommitdiff
path: root/pgweb/util/helpers.py
diff options
context:
space:
mode:
authorMagnus Hagander2009-12-28 13:18:15 +0000
committerMagnus Hagander2009-12-28 13:18:15 +0000
commitab1b585e539bb14cc2a6dcedcfdfa46896f3a3df (patch)
tree9ad4819776f14dd516e0263724e9302119d445ea /pgweb/util/helpers.py
parentffd7084fe50d09bd968857898c4c5e96acc7e2c9 (diff)
Support filtering by indirect usernames when building default forms
(such as looking up the user through an intermediate model)
Diffstat (limited to 'pgweb/util/helpers.py')
-rw-r--r--pgweb/util/helpers.py10
1 files changed, 8 insertions, 2 deletions
diff --git a/pgweb/util/helpers.py b/pgweb/util/helpers.py
index b9b647f3..aa43aa65 100644
--- a/pgweb/util/helpers.py
+++ b/pgweb/util/helpers.py
@@ -8,8 +8,12 @@ def simple_form(instancetype, itemid, request, formclass, formtemplate='base/for
else:
# Regular news item, attempt to edit it
instance = get_object_or_404(instancetype, pk=itemid)
- if not instance.submitter == request.user:
- raise Exception("You are not the owner of this item!")
+ if hasattr(instance, 'submitter'):
+ if not instance.submitter == request.user:
+ raise Exception("You are not the owner of this item!")
+ elif hasattr(instance, 'verify_submitter'):
+ if not instance.verify_submitter(request.user):
+ raise Exception("You are not the owner of this item!")
if request.method == 'POST':
# Process this form
@@ -22,6 +26,8 @@ def simple_form(instancetype, itemid, request, formclass, formtemplate='base/for
else:
# Generate form
form = formclass(instance=instance)
+ if hasattr(form, 'filter_by_user'):
+ form.filter_by_user(request.user)
if hasattr(instancetype, 'markdown_fields'):
markdownfields = instancetype.markdown_fields