From 7bbda0a72bb055ad7c34b25254e9c4438a4fbf0c Mon Sep 17 00:00:00 2001 From: Todd Dembrey <todd.dembrey@torchbox.com> Date: Wed, 24 Jan 2018 11:57:58 +0000 Subject: [PATCH] improve the round index page in model admin --- opentech/apply/funds/admin.py | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/opentech/apply/funds/admin.py b/opentech/apply/funds/admin.py index 1dbe45f48..27f91dd39 100644 --- a/opentech/apply/funds/admin.py +++ b/opentech/apply/funds/admin.py @@ -1,12 +1,42 @@ +from django.urls import reverse +from django.utils.text import mark_safe + from wagtail.contrib.modeladmin.options import ModelAdmin, ModelAdminGroup +from wagtail.contrib.modeladmin.helpers import PageButtonHelper from .models import ApplicationForm, FundType, Round from opentech.apply.categories.admin import CategoryAdmin +class ButtonsWithPreview(PageButtonHelper): + def preview_button(self, obj, classnames_add, classnames_exclude): + classnames = self.copy_button_classnames + classnames_add + cn = self.finalise_classname(classnames, classnames_exclude) + return { + 'url': reverse('wagtailadmin_pages:view_draft', args=(obj.id,)), + 'label': 'Preview', + 'classname': cn, + 'title': 'Preview this %s' % self.verbose_name, + } + + def get_buttons_for_obj(self, obj, exclude=list(), classnames_add=list(), + classnames_exclude=list()): + btns = super().get_buttons_for_obj(obj, exclude, classnames_add, classnames_exclude) + + # Put preview before delete + btns.insert(-1, self.preview_button(obj, classnames_add, classnames_exclude)) + + return btns + + class RoundAdmin(ModelAdmin): model = Round menu_icon = 'doc-empty' + list_display = ('title', 'fund', 'start_date', 'end_date') + button_helper_class = ButtonsWithPreview + + def fund(self, obj): + return obj.get_parent() class FundAdmin(ModelAdmin): -- GitLab