From 6c5b32e40460c8c0dc1ebf9b55eba1860d09e146 Mon Sep 17 00:00:00 2001
From: Parbhat Puri <parbhatpuri17@gmail.com>
Date: Tue, 16 Jul 2019 06:36:31 +0000
Subject: [PATCH] Add validation for archive check to parent and minor updates

---
 ...hive_and_other_fields_for_meta_categories.py} |  6 +++---
 opentech/apply/categories/models.py              | 16 ++++++++++++----
 2 files changed, 15 insertions(+), 7 deletions(-)
 rename opentech/apply/categories/migrations/{0003_archive_and_other_fields_meta_categories.py => 0003_archive_and_other_fields_for_meta_categories.py} (81%)

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_for_meta_categories.py
similarity index 81%
rename from opentech/apply/categories/migrations/0003_archive_and_other_fields_meta_categories.py
rename to opentech/apply/categories/migrations/0003_archive_and_other_fields_for_meta_categories.py
index c8bda155c..9bf56cd45 100644
--- a/opentech/apply/categories/migrations/0003_archive_and_other_fields_meta_categories.py
+++ b/opentech/apply/categories/migrations/0003_archive_and_other_fields_for_meta_categories.py
@@ -1,4 +1,4 @@
-# Generated by Django 2.0.13 on 2019-07-09 11:14
+# Generated by Django 2.0.13 on 2019-07-16 06:01
 
 from django.db import migrations, models
 import wagtail.core.fields
@@ -13,8 +13,8 @@ class Migration(migrations.Migration):
     operations = [
         migrations.AddField(
             model_name='metacategory',
-            name='available_to_applications',
-            field=models.BooleanField(default=True, help_text='Make available for applications'),
+            name='available_to_applicants',
+            field=models.BooleanField(default=False, help_text='Make available to applicants'),
         ),
         migrations.AddField(
             model_name='metacategory',
diff --git a/opentech/apply/categories/models.py b/opentech/apply/categories/models.py
index e9f329274..7310eec04 100644
--- a/opentech/apply/categories/models.py
+++ b/opentech/apply/categories/models.py
@@ -57,8 +57,8 @@ class MetaCategory(index.Indexed, MP_Node):
     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'
+    available_to_applicants = models.BooleanField(
+        default=False, help_text='Make available to applicants'
     )
 
     # node tree specific fields and attributes
@@ -71,12 +71,12 @@ class MetaCategory(index.Indexed, MP_Node):
     panels = [
         FieldPanel('parent'),
         FieldPanel('name'),
-        FieldPanel('is_archived'),
         MultiFieldPanel(
             [
+                FieldPanel('is_archived'),
                 FieldPanel('help_text'),
                 FieldPanel('filter_on_dashboard'),
-                FieldPanel('available_to_applications'),
+                FieldPanel('available_to_applicants'),
             ],
             heading="Options",
         ),
@@ -155,6 +155,14 @@ class MetaCategoryForm(WagtailAdminModelForm):
         elif instance.id:
             self.fields['parent'].initial = instance.get_parent()
 
+    def clean_parent(self):
+        parent = self.cleaned_data['parent']
+
+        if parent.is_archived:
+            raise forms.ValidationError('The parent is archived therefore can not add child under it.')
+
+        return parent
+
     def save(self, commit=True, *args, **kwargs):
         instance = super().save(commit=False, *args, **kwargs)
         parent = self.cleaned_data['parent']
-- 
GitLab