Skip to content
Snippets Groups Projects
Commit d62963b7 authored by Todd Dembrey's avatar Todd Dembrey
Browse files

Make review forms behave the same way as application forms

a new instance is copied onto the round
parent 3ab95bf8
No related branches found
No related tags found
No related merge requests found
# Generated by Django 2.0.2 on 2018-08-09 11:29
from django.db import migrations, models
import django.db.models.deletion
import modelcluster.fields
class Migration(migrations.Migration):
dependencies = [
('review', '0006_remove_review_review'),
('funds', '0039_add_rfps_and_sealed_rounds'),
]
operations = [
migrations.CreateModel(
name='RoundBaseReviewForm',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('sort_order', models.IntegerField(blank=True, editable=False, null=True)),
('form', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, to='review.ReviewForm')),
('round', modelcluster.fields.ParentalKey(on_delete=django.db.models.deletion.CASCADE, related_name='review_forms', to='funds.RoundBase')),
],
options={
'ordering': ['sort_order'],
'abstract': False,
},
),
]
...@@ -115,7 +115,9 @@ class RoundBase(WorkflowStreamForm, SubmittableStreamForm): # type: ignore ...@@ -115,7 +115,9 @@ class RoundBase(WorkflowStreamForm, SubmittableStreamForm): # type: ignore
], heading="Dates"), ], heading="Dates"),
FieldPanel('reviewers'), FieldPanel('reviewers'),
ReadOnlyPanel('get_workflow_name_display', heading="Workflow"), ReadOnlyPanel('get_workflow_name_display', heading="Workflow"),
# Forms comes from parental key in models/forms.py
ReadOnlyInlinePanel('forms', help_text="Are copied from the parent fund."), ReadOnlyInlinePanel('forms', help_text="Are copied from the parent fund."),
ReadOnlyInlinePanel('review_forms', help_text="Are copied from the parent fund."),
] ]
edit_handler = TabbedInterface([ edit_handler = TabbedInterface([
...@@ -156,13 +158,22 @@ class RoundBase(WorkflowStreamForm, SubmittableStreamForm): # type: ignore ...@@ -156,13 +158,22 @@ class RoundBase(WorkflowStreamForm, SubmittableStreamForm): # type: ignore
if is_new and hasattr(self, 'parent_page'): if is_new and hasattr(self, 'parent_page'):
# Would be nice to do this using model clusters as part of the __init__ # Would be nice to do this using model clusters as part of the __init__
for form in self.parent_page.forms.all(): self._copy_forms('forms')
# Create a copy of the existing form object self._copy_forms('review_forms')
new_form = form.form
new_form.id = None def _copy_forms(self, field):
new_form.name = '{} for {} ({})'.format(new_form.name, self.title, self.get_parent().title) for form in getattr(self.parent_page, field).all():
new_form.save() new_form = self._meta.get_field(field).related_model
RoundBaseForm.objects.create(round=self, form=new_form) self._copy_form(form, new_form)
def _copy_form(self, form, new_class):
# Create a copy of the existing form object
new_form = form.form
new_form.id = None
new_form.name = '{} for {} ({})'.format(new_form.name, self.title, self.get_parent().title)
new_form.save()
new_class.objects.create(round=self, form=new_form)
def get_submit_meta_data(self, **kwargs): def get_submit_meta_data(self, **kwargs):
return super().get_submit_meta_data( return super().get_submit_meta_data(
......
...@@ -90,5 +90,9 @@ class ApplicationBaseReviewForm(AbstractRelatedReviewForm): ...@@ -90,5 +90,9 @@ class ApplicationBaseReviewForm(AbstractRelatedReviewForm):
application = ParentalKey('ApplicationBase', related_name='review_forms') application = ParentalKey('ApplicationBase', related_name='review_forms')
class RoundBaseReviewForm(AbstractRelatedReviewForm):
round = ParentalKey('RoundBase', related_name='review_forms')
class LabBaseReviewForm(AbstractRelatedReviewForm): class LabBaseReviewForm(AbstractRelatedReviewForm):
lab = ParentalKey('LabBase', related_name='review_forms') lab = ParentalKey('LabBase', related_name='review_forms')
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment