From ec05f9fd774b236c41c6cf22a01b0f87fa6ba0e0 Mon Sep 17 00:00:00 2001 From: Todd Dembrey <todd.dembrey@torchbox.com> Date: Wed, 7 Aug 2019 16:15:33 +0100 Subject: [PATCH] Add the document category model and integrate into the page (#1370) * Add the document category model and integrate into the page * Fix document category migration tree --- opentech/apply/projects/admin.py | 17 +++++++++++++ .../migrations/0009_documentcategory.py | 25 +++++++++++++++++++ opentech/apply/projects/models.py | 12 +++++++++ .../includes/supporting_documents.html | 13 +++++++++- opentech/apply/projects/views.py | 8 +++++- opentech/apply/projects/wagtail_hooks.py | 6 +++++ 6 files changed, 79 insertions(+), 2 deletions(-) create mode 100644 opentech/apply/projects/admin.py create mode 100644 opentech/apply/projects/migrations/0009_documentcategory.py create mode 100644 opentech/apply/projects/wagtail_hooks.py diff --git a/opentech/apply/projects/admin.py b/opentech/apply/projects/admin.py new file mode 100644 index 000000000..711563188 --- /dev/null +++ b/opentech/apply/projects/admin.py @@ -0,0 +1,17 @@ +from wagtail.contrib.modeladmin.options import ModelAdmin, ModelAdminGroup + +from .models import DocumentCategory + + +class DocumentCategoryAdmin(ModelAdmin): + model = DocumentCategory + menu_icon = 'doc-full' + list_display = ('name', 'recommended_minimum',) + + +class ManageAdminGoup(ModelAdminGroup): + menu_label = 'Manage' + menu_icon = 'folder-open-inverse' + items = ( + DocumentCategoryAdmin, + ) diff --git a/opentech/apply/projects/migrations/0009_documentcategory.py b/opentech/apply/projects/migrations/0009_documentcategory.py new file mode 100644 index 000000000..6925bcfa6 --- /dev/null +++ b/opentech/apply/projects/migrations/0009_documentcategory.py @@ -0,0 +1,25 @@ +# Generated by Django 2.0.13 on 2019-08-06 22:08 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('application_projects', '0008_add_value_validator'), + ] + + operations = [ + migrations.CreateModel( + name='DocumentCategory', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('name', models.CharField(max_length=254)), + ('recommended_minimum', models.PositiveIntegerField()), + ], + options={ + 'ordering': ('name',), + 'verbose_name_plural': 'Document Categories', + }, + ), + ] diff --git a/opentech/apply/projects/models.py b/opentech/apply/projects/models.py index fbe5e4e11..7d8364d07 100644 --- a/opentech/apply/projects/models.py +++ b/opentech/apply/projects/models.py @@ -78,3 +78,15 @@ class Project(models.Model): def get_absolute_url(self): return reverse('apply:projects:detail', args=[self.id]) + + +class DocumentCategory(models.Model): + name = models.CharField(max_length=254) + recommended_minimum = models.PositiveIntegerField() + + def __str__(self): + return self.name + + class Meta: + ordering = ('name',) + verbose_name_plural = 'Document Categories' diff --git a/opentech/apply/projects/templates/application_projects/includes/supporting_documents.html b/opentech/apply/projects/templates/application_projects/includes/supporting_documents.html index beea493b8..4fb310d07 100644 --- a/opentech/apply/projects/templates/application_projects/includes/supporting_documents.html +++ b/opentech/apply/projects/templates/application_projects/includes/supporting_documents.html @@ -41,7 +41,18 @@ <div class="docs-block__row-inner"> <a data-fancybox data-src="#upload-supporting-doc" class="docs-block__link" href="#">Upload new</a> </div> - <p class="docs-block__info-text">Every project requires a XXXXXX and XXXXXX to be uploaded</p> + {% if remaining_document_categories %} + <div class="docs-block__info-text"> + <p> + Every project should include the following documents: + </p> + <ul> + {% for category in remaining_document_categories %} + <li>{{ category.name }} ({{ category.recommended_minimum }})</li> + {% endfor %} + </ul> + </div> + {% endif %} <!-- Example document list <ul class="docs-block__document-list"> <li class="docs-block__document"> diff --git a/opentech/apply/projects/views.py b/opentech/apply/projects/views.py index 07b525ebe..63e88bc5d 100644 --- a/opentech/apply/projects/views.py +++ b/opentech/apply/projects/views.py @@ -10,7 +10,7 @@ from opentech.apply.utils.views import (DelegateableView, DelegatedViewMixin, ViewDispatcher) from .forms import ProjectEditForm, UpdateProjectLeadForm -from .models import Project +from .models import Project, DocumentCategory @method_decorator(staff_required, name='dispatch') @@ -44,6 +44,12 @@ class AdminProjectDetailView(ActivityContextMixin, DelegateableView, DetailView) model = Project template_name_suffix = '_admin_detail' + def get_context_data(self, **kwargs): + return super().get_context_data( + remaining_document_categories=DocumentCategory.objects.all(), + **kwargs, + ) + class ApplicantProjectDetailView(DetailView): model = Project diff --git a/opentech/apply/projects/wagtail_hooks.py b/opentech/apply/projects/wagtail_hooks.py new file mode 100644 index 000000000..b33974ab8 --- /dev/null +++ b/opentech/apply/projects/wagtail_hooks.py @@ -0,0 +1,6 @@ +from wagtail.contrib.modeladmin.options import modeladmin_register + +from .admin import ManageAdminGoup + + +modeladmin_register(ManageAdminGoup) -- GitLab