diff --git a/opentech/apply/categories/admin.py b/opentech/apply/categories/admin.py index 2eb24d179ee07a77d238c5cb068d6458ab2b1162..0ada958a07ba7abfa88ba19862a6ea52728462b1 100644 --- a/opentech/apply/categories/admin.py +++ b/opentech/apply/categories/admin.py @@ -1,9 +1,9 @@ from django.conf.urls import url from wagtail.contrib.modeladmin.options import ModelAdmin -from .admin_helpers import MetaCategoryButtonHelper -from .admin_views import AddChildMetaCategoryViewClass -from .models import Category, MetaCategory +from .admin_helpers import MetaTermButtonHelper +from .admin_views import AddChildMetaTermViewClass +from .models import Category, MetaTerm class CategoryAdmin(ModelAdmin): @@ -12,8 +12,8 @@ class CategoryAdmin(ModelAdmin): model = Category -class MetaCategoryAdmin(ModelAdmin): - model = MetaCategory +class MetaTermAdmin(ModelAdmin): + model = MetaTerm menu_icon = 'tag' @@ -24,11 +24,11 @@ class MetaCategoryAdmin(ModelAdmin): inspect_view_enabled = True inspect_view_fields = ('name', 'get_parent', 'id') - button_helper_class = MetaCategoryButtonHelper + button_helper_class = MetaTermButtonHelper def add_child_view(self, request, instance_pk): kwargs = {'model_admin': self, 'parent_pk': instance_pk} - view_class = AddChildMetaCategoryViewClass + view_class = AddChildMetaTermViewClass return view_class.as_view(**kwargs)(request) def get_admin_urls_for_registration(self): diff --git a/opentech/apply/categories/admin_helpers.py b/opentech/apply/categories/admin_helpers.py index 69f77a6cb0e527221e98e7d67279ba90afeb0710..6937b6b342ff387d1a9d293d97bd725f87470a36 100644 --- a/opentech/apply/categories/admin_helpers.py +++ b/opentech/apply/categories/admin_helpers.py @@ -3,9 +3,9 @@ from django.contrib.admin.utils import quote from wagtail.contrib.modeladmin.helpers import ButtonHelper -class MetaCategoryButtonHelper(ButtonHelper): +class MetaTermButtonHelper(ButtonHelper): def delete_button(self, pk, *args, **kwargs): - """Ensure that the delete button is not shown for root category.""" + """Ensure that the delete button is not shown for root meta term.""" instance = self.model.objects.get(pk=pk) if instance.is_root(): return @@ -18,7 +18,7 @@ class MetaCategoryButtonHelper(ButtonHelper): return self.finalise_classname(classnames, exclude or []) def add_child_button(self, pk, child_verbose_name, **kwargs): - """Build a add child button, to easily add a child under category.""" + """Build a add child button, to easily add a child under meta term.""" instance = self.model.objects.get(pk=pk) if instance.is_archived or instance.get_parent() and instance.get_parent().is_archived: return diff --git a/opentech/apply/categories/admin_views.py b/opentech/apply/categories/admin_views.py index 890bccbe451363c024e42286f885067a66515838..98faa64a6489dfcc4e50e8eab0c00a52445faab5 100644 --- a/opentech/apply/categories/admin_views.py +++ b/opentech/apply/categories/admin_views.py @@ -4,7 +4,7 @@ from django.shortcuts import get_object_or_404 from wagtail.contrib.modeladmin.views import CreateView -class AddChildMetaCategoryViewClass(CreateView): +class AddChildMetaTermViewClass(CreateView): """View class that can take an additional URL param for parent id.""" parent_pk = None diff --git a/opentech/apply/categories/migrations/0003_archive_and_other_fields_for_meta_categories.py b/opentech/apply/categories/migrations/0003_archive_and_other_fields_for_meta_categories.py deleted file mode 100644 index 9bf56cd45740bbc4117fdcd05455e92586cf0468..0000000000000000000000000000000000000000 --- a/opentech/apply/categories/migrations/0003_archive_and_other_fields_for_meta_categories.py +++ /dev/null @@ -1,34 +0,0 @@ -# Generated by Django 2.0.13 on 2019-07-16 06:01 - -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_applicants', - field=models.BooleanField(default=False, help_text='Make available to applicants'), - ), - 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/migrations/0003_rename_meta_categories_to_meta_terms.py b/opentech/apply/categories/migrations/0003_rename_meta_categories_to_meta_terms.py new file mode 100644 index 0000000000000000000000000000000000000000..ec7168cba720ad3e3e4aa5ff1bfe8b649896e22b --- /dev/null +++ b/opentech/apply/categories/migrations/0003_rename_meta_categories_to_meta_terms.py @@ -0,0 +1,35 @@ +# Generated by Django 2.0.13 on 2019-07-30 07:53 + +from django.db import migrations, models +import wagtail.core.fields +import wagtail.search.index + + +class Migration(migrations.Migration): + + dependencies = [ + ('categories', '0002_metacategory'), + ] + + operations = [ + migrations.CreateModel( + name='MetaTerm', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('path', models.CharField(max_length=255, unique=True)), + ('depth', models.PositiveIntegerField()), + ('numchild', models.PositiveIntegerField(default=0)), + ('name', models.CharField(help_text='Keep the name short, ideally one word.', max_length=50, unique=True)), + ('is_archived', models.BooleanField(default=False, verbose_name='Archived')), + ('help_text', wagtail.core.fields.RichTextField(blank=True)), + ('filter_on_dashboard', models.BooleanField(default=True, help_text='Make available to filter on dashboard')), + ('available_to_applicants', models.BooleanField(default=False, help_text='Make available to applicants')), + ('node_order_index', models.IntegerField(blank=True, default=0, editable=False)), + ], + options={ + 'verbose_name': 'Meta Term', + 'verbose_name_plural': 'Meta Terms', + }, + bases=(wagtail.search.index.Indexed, models.Model), + ), + ] diff --git a/opentech/apply/categories/migrations/0004_rename_meta_categories_to_meta_terms.py b/opentech/apply/categories/migrations/0004_rename_meta_categories_to_meta_terms.py new file mode 100644 index 0000000000000000000000000000000000000000..8dc262d4756303184a9e7e6e7836d56cc5e4bada --- /dev/null +++ b/opentech/apply/categories/migrations/0004_rename_meta_categories_to_meta_terms.py @@ -0,0 +1,17 @@ +# Generated by Django 2.0.13 on 2019-07-30 07:53 + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('categories', '0003_rename_meta_categories_to_meta_terms'), + ('funds', '0066_rename_meta_categories_to_meta_terms'), + ] + + operations = [ + migrations.DeleteModel( + name='MetaCategory', + ), + ] diff --git a/opentech/apply/categories/models.py b/opentech/apply/categories/models.py index 7310eec04d10b71659f7105dd628500e49405bb3..829230633312cc0e58211c6391af2832c9ac639e 100644 --- a/opentech/apply/categories/models.py +++ b/opentech/apply/categories/models.py @@ -46,8 +46,8 @@ class Category(ClusterableModel): verbose_name_plural = 'Categories' -class MetaCategory(index.Indexed, MP_Node): - """ Hierarchal "Meta" category """ +class MetaTerm(index.Indexed, MP_Node): + """ Hierarchal "Meta" terms """ name = models.CharField( max_length=50, unique=True, help_text='Keep the name short, ideally one word.' ) @@ -85,7 +85,7 @@ class MetaCategory(index.Indexed, MP_Node): def get_as_listing_header(self): depth = self.get_depth() rendered = render_to_string( - 'categories/admin/includes/meta_category_list_header.html', + 'categories/admin/includes/meta_term_list_header.html', { 'depth': depth, 'depth_minus_1': depth - 1, @@ -108,13 +108,13 @@ class MetaCategory(index.Indexed, MP_Node): def delete(self): if self.is_root(): - raise PermissionDenied('Cannot delete root Category.') + raise PermissionDenied('Cannot delete root term.') else: super().delete() @classmethod def get_root_descendants(cls): - # Meta categories queryset without Root node + # Meta terms queryset without Root node root_node = cls.get_first_root_node() if root_node: return root_node.get_descendants() @@ -124,20 +124,20 @@ class MetaCategory(index.Indexed, MP_Node): return self.name class Meta: - verbose_name = 'Meta Category' - verbose_name_plural = 'Meta Categories' + verbose_name = 'Meta Term' + verbose_name_plural = 'Meta Terms' -class MetaCategoryChoiceField(forms.ModelChoiceField): +class MetaTermChoiceField(forms.ModelChoiceField): def label_from_instance(self, obj): depth_line = '-' * (obj.get_depth() - 1) return "{} {}".format(depth_line, super().label_from_instance(obj)) -class MetaCategoryForm(WagtailAdminModelForm): - parent = MetaCategoryChoiceField( +class MetaTermForm(WagtailAdminModelForm): + parent = MetaTermChoiceField( required=True, - queryset=MetaCategory.objects.all(), + queryset=MetaTerm.objects.all(), empty_label=None, ) @@ -145,20 +145,20 @@ class MetaCategoryForm(WagtailAdminModelForm): super().__init__(*args, **kwargs) instance = kwargs['instance'] - if instance.is_root() or MetaCategory.objects.count() == 0: + if instance.is_root() or MetaTerm.objects.count() == 0: self.fields['parent'].disabled = True self.fields['parent'].required = False - self.fields['parent'].empty_label = 'N/A - Root Category' + self.fields['parent'].empty_label = 'N/A - Root Term' self.fields['parent'].widget = forms.HiddenInput() - self.fields['name'].label += ' (Root - First category can be named root)' + self.fields['name'].label += ' (Root - First term can be named root)' elif instance.id: self.fields['parent'].initial = instance.get_parent() def clean_parent(self): parent = self.cleaned_data['parent'] - if parent.is_archived: + if parent and parent.is_archived: raise forms.ValidationError('The parent is archived therefore can not add child under it.') return parent @@ -171,8 +171,8 @@ class MetaCategoryForm(WagtailAdminModelForm): return instance if instance.id is None: - if MetaCategory.objects.all().count() == 0: - MetaCategory.add_root(instance=instance) + if MetaTerm.objects.all().count() == 0: + MetaTerm.add_root(instance=instance) else: instance = parent.add_child(instance=instance) else: @@ -182,4 +182,4 @@ class MetaCategoryForm(WagtailAdminModelForm): return instance -MetaCategory.base_form_class = MetaCategoryForm +MetaTerm.base_form_class = MetaTermForm diff --git a/opentech/apply/categories/templates/categories/admin/includes/meta_category_list_header.html b/opentech/apply/categories/templates/categories/admin/includes/meta_term_list_header.html similarity index 100% rename from opentech/apply/categories/templates/categories/admin/includes/meta_category_list_header.html rename to opentech/apply/categories/templates/categories/admin/includes/meta_term_list_header.html diff --git a/opentech/apply/funds/admin.py b/opentech/apply/funds/admin.py index fe8a56644834d090aa18b0b8940d0cb31e5539b0..ccecd965741aab3cdcf1d0d7b13e3ebcfd26a080 100644 --- a/opentech/apply/funds/admin.py +++ b/opentech/apply/funds/admin.py @@ -12,7 +12,7 @@ from .admin_helpers import ( RoundFundChooserView, ) from .models import ApplicationForm, FundType, LabType, RequestForPartners, Round, SealedRound -from opentech.apply.categories.admin import CategoryAdmin, MetaCategoryAdmin +from opentech.apply.categories.admin import CategoryAdmin, MetaTermAdmin class BaseRoundAdmin(ModelAdmin): @@ -148,5 +148,5 @@ class ApplyAdminGroup(ModelAdminGroup): CategoryAdmin, ScreeningStatusAdmin, ReviewerRoleAdmin, - MetaCategoryAdmin, + MetaTermAdmin, ) diff --git a/opentech/apply/funds/forms.py b/opentech/apply/funds/forms.py index df7ce6d8a9e0446ae2f674598dc59d17d65d6e06..be01520db4d66f263567a089e061d3fb6a0e418b 100644 --- a/opentech/apply/funds/forms.py +++ b/opentech/apply/funds/forms.py @@ -8,12 +8,12 @@ from django.utils.translation import ugettext_lazy as _ from django.utils.safestring import mark_safe from django_select2.forms import Select2Widget -from opentech.apply.categories.models import MetaCategory +from opentech.apply.categories.models import MetaTerm from opentech.apply.users.models import User from .models import AssignedReviewers, ApplicationSubmission, ReviewerRole from .utils import render_icon -from .widgets import Select2MultiCheckboxesWidget, MetaCategorySelect2Widget +from .widgets import Select2MultiCheckboxesWidget, MetaTermSelect2Widget from .workflow import get_action_mapping @@ -390,14 +390,14 @@ class GroupedModelMultipleChoiceField(forms.ModelMultipleChoiceField): return {'label': super().label_from_instance(obj), 'disabled': not obj.is_leaf()} -class UpdateMetaCategoriesForm(ApplicationSubmissionModelForm): - meta_categories = GroupedModelMultipleChoiceField( +class UpdateMetaTermsForm(ApplicationSubmissionModelForm): + meta_terms = GroupedModelMultipleChoiceField( queryset=None, # updated in init method - widget=MetaCategorySelect2Widget(attrs={'data-placeholder': 'Meta categories'}), - label='Meta categories', + widget=MetaTermSelect2Widget(attrs={'data-placeholder': 'Meta terms'}), + label='Meta terms', choices_groupby='get_parent', required=False, - help_text='Meta categories are hierarchical in nature.', + help_text='Meta terms are hierarchical in nature.', ) class Meta: @@ -407,4 +407,4 @@ class UpdateMetaCategoriesForm(ApplicationSubmissionModelForm): def __init__(self, *args, **kwargs): kwargs.pop('user') super().__init__(*args, **kwargs) - self.fields['meta_categories'].queryset = MetaCategory.get_root_descendants().exclude(depth=2) + self.fields['meta_terms'].queryset = MetaTerm.get_root_descendants().exclude(depth=2) diff --git a/opentech/apply/funds/migrations/0066_rename_meta_categories_to_meta_terms.py b/opentech/apply/funds/migrations/0066_rename_meta_categories_to_meta_terms.py new file mode 100644 index 0000000000000000000000000000000000000000..72cbf8cd54abead54df006b815af251eec6220bd --- /dev/null +++ b/opentech/apply/funds/migrations/0066_rename_meta_categories_to_meta_terms.py @@ -0,0 +1,23 @@ +# Generated by Django 2.0.13 on 2019-07-30 07:53 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('categories', '0003_rename_meta_categories_to_meta_terms'), + ('funds', '0065_applicationsubmission_meta_categories'), + ] + + operations = [ + migrations.RemoveField( + model_name='applicationsubmission', + name='meta_categories', + ), + migrations.AddField( + model_name='applicationsubmission', + name='meta_terms', + field=models.ManyToManyField(blank=True, related_name='submissions', to='categories.MetaTerm'), + ), + ] diff --git a/opentech/apply/funds/models/submissions.py b/opentech/apply/funds/models/submissions.py index a6df3d877f198d8d3b0281429afd3a173aad5ef7..83ee44cefefeff3e52d66b31b9d5d010c74359d7 100644 --- a/opentech/apply/funds/models/submissions.py +++ b/opentech/apply/funds/models/submissions.py @@ -32,7 +32,7 @@ from wagtail.core.fields import StreamField from wagtail.contrib.forms.models import AbstractFormSubmission from opentech.apply.activity.messaging import messenger, MESSAGES -from opentech.apply.categories.models import MetaCategory +from opentech.apply.categories.models import MetaTerm from opentech.apply.determinations.models import Determination from opentech.apply.review.models import ReviewOpinion from opentech.apply.review.options import MAYBE, AGREE, DISAGREE @@ -393,8 +393,8 @@ class ApplicationSubmission( limit_choices_to=LIMIT_TO_PARTNERS, blank=True, ) - meta_categories = models.ManyToManyField( - MetaCategory, + meta_terms = models.ManyToManyField( + MetaTerm, related_name='submissions', blank=True, ) diff --git a/opentech/apply/funds/templates/funds/applicationsubmission_admin_detail.html b/opentech/apply/funds/templates/funds/applicationsubmission_admin_detail.html index e8e3b36fb373cc59d855baa6e7e02a49f9199ac5..09bcc3383be42f8cb71627c2f8496352cb8458e3 100644 --- a/opentech/apply/funds/templates/funds/applicationsubmission_admin_detail.html +++ b/opentech/apply/funds/templates/funds/applicationsubmission_admin_detail.html @@ -25,7 +25,7 @@ {% if PROJECTS_ENABLED %} {% include "funds/includes/create_project_form.html" %} {% endif %} - {% include "funds/includes/update_meta_categories_form.html" %} + {% include "funds/includes/update_meta_terms_form.html" %} {% endblock %} {% block reviews %} @@ -48,7 +48,7 @@ {% endblock %} {% block meta_categories %} - {% include 'funds/includes/meta_categories_block.html' %} + {% include 'funds/includes/meta_terms_block.html' %} {% endblock %} {% block determination %} diff --git a/opentech/apply/funds/templates/funds/includes/actions.html b/opentech/apply/funds/templates/funds/includes/actions.html index 0dcfc3d8ab1b46e8b71842c04a74545f8aa037e5..20f84c073537ee2acebafe912800dbe47eef856e 100644 --- a/opentech/apply/funds/templates/funds/includes/actions.html +++ b/opentech/apply/funds/templates/funds/includes/actions.html @@ -27,4 +27,4 @@ <a class="button button--white button--full-width button--bottom-space" href="{% url 'funds:submissions:revisions:list' submission_pk=object.id %}">Revisions</a> -<a data-fancybox data-src="#update-meta-categories" class="button button--white button--full-width button--bottom-space" href="#">Meta Categories</a> +<a data-fancybox data-src="#update-meta-terms" class="button button--white button--full-width button--bottom-space" href="#">Meta Terms</a> diff --git a/opentech/apply/funds/templates/funds/includes/meta_categories_block.html b/opentech/apply/funds/templates/funds/includes/meta_categories_block.html deleted file mode 100644 index 48adf136a2e544bd4096b8437cd1b5bd0dce621d..0000000000000000000000000000000000000000 --- a/opentech/apply/funds/templates/funds/includes/meta_categories_block.html +++ /dev/null @@ -1,10 +0,0 @@ -<div class="sidebar__inner"> - <h5>Meta Categories</h5> - <ul> - {% for meta_category in object.meta_categories.all %} - <li>{{ meta_category.name }}</li> - {% empty %} - None. Meta categories can be added to a submission using Meta categories button at top. - {% endfor %} - </ul> -</div> diff --git a/opentech/apply/funds/templates/funds/includes/meta_terms_block.html b/opentech/apply/funds/templates/funds/includes/meta_terms_block.html new file mode 100644 index 0000000000000000000000000000000000000000..b6f78ea86077fa184561c840ca61f583c005e7b8 --- /dev/null +++ b/opentech/apply/funds/templates/funds/includes/meta_terms_block.html @@ -0,0 +1,10 @@ +<div class="sidebar__inner"> + <h5>Meta Terms</h5> + <ul> + {% for meta_term in object.meta_terms.all %} + <li>{{ meta_term.name }}</li> + {% empty %} + None. Meta terms can be added to a submission using Meta terms button at top. + {% endfor %} + </ul> +</div> diff --git a/opentech/apply/funds/templates/funds/includes/update_meta_categories_form.html b/opentech/apply/funds/templates/funds/includes/update_meta_categories_form.html deleted file mode 100644 index 44395f61d0657c1e08d0ec59e768e6da4491b7ac..0000000000000000000000000000000000000000 --- a/opentech/apply/funds/templates/funds/includes/update_meta_categories_form.html +++ /dev/null @@ -1,4 +0,0 @@ -<div class="modal" id="update-meta-categories"> - <h4 class="modal__header-bar">Update Meta Categories</h4> - {% include 'funds/includes/delegated_form_base.html' with form=meta_categories_form value='Update' %} -</div> diff --git a/opentech/apply/funds/templates/funds/includes/update_meta_terms_form.html b/opentech/apply/funds/templates/funds/includes/update_meta_terms_form.html new file mode 100644 index 0000000000000000000000000000000000000000..a754d3f17b625b303c1d122fcecee794cf0ba5b3 --- /dev/null +++ b/opentech/apply/funds/templates/funds/includes/update_meta_terms_form.html @@ -0,0 +1,4 @@ +<div class="modal" id="update-meta-terms"> + <h4 class="modal__header-bar">Update Meta Terms</h4> + {% include 'funds/includes/delegated_form_base.html' with form=meta_terms_form value='Update' %} +</div> diff --git a/opentech/apply/funds/views.py b/opentech/apply/funds/views.py index af01e3a39e0e0ad6b51f1d5d86778c65865d9e6c..b134a851bdbef3bdc382ce6d7870e6940c4c44d5 100644 --- a/opentech/apply/funds/views.py +++ b/opentech/apply/funds/views.py @@ -44,7 +44,7 @@ from .forms import ( UpdateReviewersForm, UpdateSubmissionLeadForm, UpdatePartnersForm, - UpdateMetaCategoriesForm, + UpdateMetaTermsForm, ) from .models import ( ApplicationSubmission, @@ -524,10 +524,10 @@ class UpdatePartnersView(DelegatedViewMixin, UpdateView): @method_decorator(staff_required, name='dispatch') -class UpdateMetaCategoriesView(DelegatedViewMixin, UpdateView): +class UpdateMetaTermsView(DelegatedViewMixin, UpdateView): model = ApplicationSubmission - form_class = UpdateMetaCategoriesForm - context_name = 'meta_categories_form' + form_class = UpdateMetaTermsForm + context_name = 'meta_terms_form' class AdminSubmissionDetailView(ReviewContextMixin, ActivityContextMixin, DelegateableView, DetailView): @@ -541,7 +541,7 @@ class AdminSubmissionDetailView(ReviewContextMixin, ActivityContextMixin, Delega UpdateReviewersView, UpdatePartnersView, CreateProjectView, - UpdateMetaCategoriesView, + UpdateMetaTermsView, ] def dispatch(self, request, *args, **kwargs): diff --git a/opentech/apply/funds/widgets.py b/opentech/apply/funds/widgets.py index 4af3d76a77449c16687f19891d9e5705ba988ea2..3c0b8101d2d663114b83bc02c616f970aeb9ce3c 100644 --- a/opentech/apply/funds/widgets.py +++ b/opentech/apply/funds/widgets.py @@ -22,7 +22,7 @@ class Select2MultiCheckboxesWidget(Select2MultipleWidget): return attrs -class MetaCategorySelect2Widget(Select2MultipleWidget): +class MetaTermSelect2Widget(Select2MultipleWidget): def create_option(self, name, value, label, selected, index, subindex=None, attrs=None): disabled = False