mirror of
https://github.com/postgres/pgweb.git
synced 2025-08-03 15:38:59 +00:00

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.
44 lines
1.7 KiB
Python
44 lines
1.7 KiB
Python
from django.contrib import admin
|
|
|
|
|
|
class PgwebAdmin(admin.ModelAdmin):
|
|
"""
|
|
ModelAdmin wrapper that will enable a few pg specific things:
|
|
* Markdown preview for markdown capable textfields (specified by
|
|
including them in a class variable named markdown_capable that is a tuple
|
|
of field names)
|
|
"""
|
|
|
|
change_form_template = 'admin/change_form_pgweb.html'
|
|
|
|
def formfield_for_dbfield(self, db_field, **kwargs):
|
|
fld = admin.ModelAdmin.formfield_for_dbfield(self, db_field, **kwargs)
|
|
|
|
if hasattr(self.model, 'markdown_fields'):
|
|
if db_field.name in self.model.markdown_fields:
|
|
fld.widget.attrs['class'] = fld.widget.attrs['class'] + ' markdown_preview'
|
|
return fld
|
|
|
|
# Remove the builtin delete_selected action, so it doesn't
|
|
# conflict with the custom one.
|
|
def get_actions(self, request):
|
|
actions = super(PgwebAdmin, self).get_actions(request)
|
|
del actions['delete_selected']
|
|
return actions
|
|
|
|
# Define a custom delete_selected action. This is required because the
|
|
# default one uses the delete functionality in QuerySet, which bypasses
|
|
# the delete() operation on the model, and thus won't send out our
|
|
# notifications. Manually calling delete() on each one will be slightly
|
|
# slower, but will send proper notifications - and it's not like this
|
|
# is something that happens often enough that we care about performance.
|
|
def custom_delete_selected(self, request, queryset):
|
|
for x in queryset:
|
|
x.delete()
|
|
custom_delete_selected.short_description = "Delete selected items"
|
|
actions = ['custom_delete_selected']
|
|
|
|
|
|
def register_pgwebadmin(model):
|
|
admin.site.register(model, PgwebAdmin)
|