From 362c3483e52785db8b78cdf7ad25f7dcbdd604d2 Mon Sep 17 00:00:00 2001 From: Parbhat Puri <parbhatpuri17@gmail.com> Date: Tue, 9 Jul 2019 11:45:03 +0000 Subject: [PATCH] Archive option for meta categories and other options --- opentech/apply/categories/admin_helpers.py | 4 +++ ...rchive_and_other_fields_meta_categories.py | 34 +++++++++++++++++++ opentech/apply/categories/models.py | 22 ++++++++++++ .../includes/meta_category_list_header.html | 6 +++- 4 files changed, 65 insertions(+), 1 deletion(-) create mode 100644 opentech/apply/categories/migrations/0003_archive_and_other_fields_meta_categories.py diff --git a/opentech/apply/categories/admin_helpers.py b/opentech/apply/categories/admin_helpers.py index 9f786fced..69f77a6cb 100644 --- a/opentech/apply/categories/admin_helpers.py +++ b/opentech/apply/categories/admin_helpers.py @@ -19,6 +19,10 @@ class MetaCategoryButtonHelper(ButtonHelper): def add_child_button(self, pk, child_verbose_name, **kwargs): """Build a add child button, to easily add a child under category.""" + instance = self.model.objects.get(pk=pk) + if instance.is_archived or instance.get_parent() and instance.get_parent().is_archived: + return + classnames = self.prepare_classnames( start=self.edit_button_classnames + ['icon', 'icon-plus'], add=kwargs.get('classnames_add'), diff --git a/opentech/apply/categories/migrations/0003_archive_and_other_fields_meta_categories.py b/opentech/apply/categories/migrations/0003_archive_and_other_fields_meta_categories.py new file mode 100644 index 000000000..c8bda155c --- /dev/null +++ b/opentech/apply/categories/migrations/0003_archive_and_other_fields_meta_categories.py @@ -0,0 +1,34 @@ +# Generated by Django 2.0.13 on 2019-07-09 11:14 + +from django.db import migrations, models +import wagtail.core.fields + + +class Migration(migrations.Migration): + + dependencies = [ + ('categories', '0002_metacategory'), + ] + + operations = [ + migrations.AddField( + model_name='metacategory', + name='available_to_applications', + field=models.BooleanField(default=True, help_text='Make available for applications'), + ), + migrations.AddField( + model_name='metacategory', + name='filter_on_dashboard', + field=models.BooleanField(default=True, help_text='Make available to filter on dashboard'), + ), + migrations.AddField( + model_name='metacategory', + name='help_text', + field=wagtail.core.fields.RichTextField(blank=True), + ), + migrations.AddField( + model_name='metacategory', + name='is_archived', + field=models.BooleanField(default=False, verbose_name='Archived'), + ), + ] diff --git a/opentech/apply/categories/models.py b/opentech/apply/categories/models.py index 09ad45ddc..e9f329274 100644 --- a/opentech/apply/categories/models.py +++ b/opentech/apply/categories/models.py @@ -2,14 +2,17 @@ from django import forms from django.core.exceptions import PermissionDenied from django.db import models from django.template.loader import render_to_string +from django.utils.translation import ugettext_lazy as _ from modelcluster.fields import ParentalKey from modelcluster.models import ClusterableModel from wagtail.admin.edit_handlers import ( FieldPanel, InlinePanel, + MultiFieldPanel, ) from wagtail.admin.forms import WagtailAdminModelForm +from wagtail.core.fields import RichTextField from wagtail.core.models import Orderable from wagtail.search import index @@ -48,6 +51,15 @@ class MetaCategory(index.Indexed, MP_Node): name = models.CharField( max_length=50, unique=True, help_text='Keep the name short, ideally one word.' ) + is_archived = models.BooleanField(default=False, verbose_name=_("Archived")) + help_text = RichTextField(features=[ + 'h2', 'h3', 'bold', 'italic', 'link', 'hr', 'ol', 'ul'], blank=True) + filter_on_dashboard = models.BooleanField( + default=True, help_text='Make available to filter on dashboard' + ) + available_to_applications = models.BooleanField( + default=True, help_text='Make available for applications' + ) # node tree specific fields and attributes node_order_index = models.IntegerField(blank=True, default=0, editable=False) @@ -59,6 +71,15 @@ class MetaCategory(index.Indexed, MP_Node): panels = [ FieldPanel('parent'), FieldPanel('name'), + FieldPanel('is_archived'), + MultiFieldPanel( + [ + FieldPanel('help_text'), + FieldPanel('filter_on_dashboard'), + FieldPanel('available_to_applications'), + ], + heading="Options", + ), ] def get_as_listing_header(self): @@ -70,6 +91,7 @@ class MetaCategory(index.Indexed, MP_Node): 'depth_minus_1': depth - 1, 'is_root': self.is_root(), 'name': self.name, + 'is_archived': self.is_archived, } ) return rendered diff --git a/opentech/apply/categories/templates/categories/admin/includes/meta_category_list_header.html b/opentech/apply/categories/templates/categories/admin/includes/meta_category_list_header.html index b6a816694..1c5c28672 100644 --- a/opentech/apply/categories/templates/categories/admin/includes/meta_category_list_header.html +++ b/opentech/apply/categories/templates/categories/admin/includes/meta_category_list_header.html @@ -4,6 +4,10 @@ <span> <span class="inline-block" style="margin-left:{{ depth }}em; font-size:{% if depth is 1 %}90{% elif depth is 2 %}80{% else %}100{% endif %}%;"></span> <i class="icon icon-fa-level-up icon-fa-rotate-90" style="display: inline-block;"></i> - {{ name }} + {% if is_archived %} + <span style="color: LightGray">{{ name }} (archived)</span> + {% else %} + {{ name }} + {% endif %} </span> {% endif %} -- GitLab