summaryrefslogtreecommitdiff
path: root/pgweb/util/helpers.py
diff options
context:
space:
mode:
authorMagnus Hagander2020-09-10 12:52:41 +0000
committerMagnus Hagander2020-09-10 12:52:41 +0000
commit5ffe6c389c020c718065b5d2146ce25ebe4b0c9b (patch)
treedb5699adf9daa7a65c1cfa0cb9e6dd87d1af4021 /pgweb/util/helpers.py
parentb3e9a962e4514962a1fdbf86b8cdbae3103e76e9 (diff)
Re-work moderation of submitted items
This includes a number of new features: * Move some moderation functionality into shared places, so we don't keep re-inventing the wheel. * Implement three-state moderation, where the submitter can edit their item and then explicitly say "i'm done, please moderate this now". This is currently only implemented for News, but done in a reusable way. * Move moderation workflow to it's own set of URLs instead of overloading it on the general admin interface. Admin interface remains for editing things, but these are now separated out into separate things. * Do proper stylesheet clearing for moderation of markdown fields, using a dynamic sandboxed iframe, so it's not ruined by the /admin/ css. * Move moderation email notification into dedicated moderation code, thereby simplifying the admin subclassing we did which was in some places quite fragile. * Reset date of news postings to the date of their approval, when approved. This avoids some annoying ordering issues.
Diffstat (limited to 'pgweb/util/helpers.py')
-rw-r--r--pgweb/util/helpers.py32
1 files changed, 22 insertions, 10 deletions
diff --git a/pgweb/util/helpers.py b/pgweb/util/helpers.py
index d2d71dd0..f594ea16 100644
--- a/pgweb/util/helpers.py
+++ b/pgweb/util/helpers.py
@@ -7,6 +7,7 @@ import django.utils.xmlutils
from django.conf import settings
from pgweb.util.contexts import render_pgweb
+from pgweb.util.moderation import ModerationState
import io
import re
@@ -34,7 +35,7 @@ def MarkdownValidator(val):
return val
-def simple_form(instancetype, itemid, request, formclass, formtemplate='base/form.html', redirect='/account/', navsection='account', fixedfields=None, createifempty=False):
+def simple_form(instancetype, itemid, request, formclass, formtemplate='base/form.html', redirect='/account/', navsection='account', fixedfields=None, createifempty=False, extracontext={}):
if itemid == 'new':
instance = instancetype()
is_new = True
@@ -56,6 +57,9 @@ def simple_form(instancetype, itemid, request, formclass, formtemplate='base/for
if not instance.verify_submitter(request.user):
raise PermissionDenied("You are not the owner of this item!")
+ if getattr(instance, 'block_edit', False):
+ raise PermissionDenied("You cannot edit this item")
+
if request.method == 'POST':
# Process this form
form = formclass(data=request.POST, instance=instance)
@@ -72,13 +76,18 @@ def simple_form(instancetype, itemid, request, formclass, formtemplate='base/for
do_notify = getattr(instance, 'send_notification', False)
instance.send_notification = False
- if not getattr(instance, 'approved', True) and not is_new:
- # If the object has an "approved" field and it's set to false, we don't
- # bother notifying about the changes. But if it lacks this field, we notify
- # about everything, as well as if the field exists and the item has already
- # been approved.
- # Newly added objects are always notified.
- do_notify = False
+ # If the object has an "approved" field and it's set to false, we don't
+ # bother notifying about the changes. But if it lacks this field, we notify
+ # about everything, as well as if the field exists and the item has already
+ # been approved.
+ # Newly added objects are always notified.
+ if not is_new:
+ if hasattr(instance, 'approved'):
+ if not getattr(instance, 'approved', True):
+ do_notify = False
+ elif hasattr(instance, 'modstate'):
+ if getattr(instance, 'modstate', None) == ModerationState.CREATED:
+ do_notify = False
notify = io.StringIO()
@@ -176,14 +185,17 @@ def simple_form(instancetype, itemid, request, formclass, formtemplate='base/for
'class': 'toggle-checkbox',
})
- return render_pgweb(request, navsection, formtemplate, {
+ ctx = {
'form': form,
'formitemtype': instance._meta.verbose_name,
'form_intro': hasattr(form, 'form_intro') and form.form_intro or None,
'described_checkboxes': getattr(form, 'described_checkboxes', {}),
'savebutton': (itemid == "new") and "Submit New" or "Save",
'operation': (itemid == "new") and "New" or "Edit",
- })
+ }
+ ctx.update(extracontext)
+
+ return render_pgweb(request, navsection, formtemplate, ctx)
def template_to_string(templatename, attrs={}):