mirror of
https://github.com/postgres/pgweb.git
synced 2025-08-01 15:54:53 +00:00
Support filtering by indirect usernames when building default forms
(such as looking up the user through an intermediate model)
This commit is contained in:
@ -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
|
||||
|
Reference in New Issue
Block a user