diff --git a/opentech/apply/activity/templates/activity/include/comment_form.html b/opentech/apply/activity/templates/activity/include/comment_form.html index 06a11b9a96a12198ba7d7702bc2722cb92941837..c20300aec2bd4315b05c7d672885b34c9c9e602d 100644 --- a/opentech/apply/activity/templates/activity/include/comment_form.html +++ b/opentech/apply/activity/templates/activity/include/comment_form.html @@ -1,5 +1,5 @@ -<form method="post"> +<form method="post" id="comment-form"> {% csrf_token %} {{ comment_form }} - <input type="submit" value="Comment"> + <input id="comment-form-submit" name="form-submitted" type="submit" form="comment-form" value="Comment"> </form> diff --git a/opentech/apply/funds/forms.py b/opentech/apply/funds/forms.py index 478f3a9edb9f603efa018473d0bc4b0da9b8bab8..e4a66f7c990a357d88f0c786d84ba5d8829dd064 100644 --- a/opentech/apply/funds/forms.py +++ b/opentech/apply/funds/forms.py @@ -4,9 +4,19 @@ from .models import ApplicationSubmission class ProgressSubmissionForm(forms.ModelForm): + action = forms.ChoiceField() + class Meta: model = ApplicationSubmission - fields = ('status',) + fields = [] def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) + choices = [(action, action) for action in self.instance.phase.action_names] + self.fields['action'].choices = choices + self.fields['action'].label = self.instance.phase.name + + def save(self, *args, **kwargs): + new_phase = self.instance.workflow.process(self.instance.phase, self.cleaned_data['action']) + self.instance.status = str(new_phase) + return super().save(*args, **kwargs) diff --git a/opentech/apply/funds/templates/funds/includes/progress_form.html b/opentech/apply/funds/templates/funds/includes/progress_form.html index 434c6d783992396a4086a513c553f39c48c9fe9d..29a256a5ab1d33c01b4f5443a5f5794f8c8aeb23 100644 --- a/opentech/apply/funds/templates/funds/includes/progress_form.html +++ b/opentech/apply/funds/templates/funds/includes/progress_form.html @@ -1,5 +1,5 @@ -<form method="post"> +<form method="post" id="progress-form"> {% csrf_token %} {{ progress_form }} - <input type="submit" value="Progress"> + <input id="progress-form-submit" name="form-submitted" type="submit" form="progress-form" value="Progress"> </form> diff --git a/opentech/apply/funds/views.py b/opentech/apply/funds/views.py index de22ef1bd4026ea56074232bdbaf5ec81ed3c8a2..3a1f60d24c3d14f596b761ea0d2c5134baa5ac36 100644 --- a/opentech/apply/funds/views.py +++ b/opentech/apply/funds/views.py @@ -53,12 +53,20 @@ class ProgressContextMixin: class ProgressSubmissionView(DelegatedViewMixin, UpdateView): - form_class = ProgressSubmissionForm - context_name = 'progress_form' + model = ApplicationSubmission + form_class = ProgressSubmissionForm + context_name = 'progress_form' + + def form_valid(self, form): + return super().form_valid(form) class SubmissionDetailView(CommentContextMixin, ProgressContextMixin, DetailView): model = ApplicationSubmission + form_views = { + 'progress': ProgressSubmissionView, + 'comment': CommentFormView, + } def get_context_data(self, **kwargs): return super().get_context_data( @@ -75,8 +83,8 @@ class SubmissionDetailView(CommentContextMixin, ProgressContextMixin, DetailView kwargs['template_names'] = self.get_template_names() kwargs['context'] = self.get_context_data() - import pudb; pudb.set_trace() - view = CommentFormView.as_view() + form_submitted = request.POST['form-submitted'].lower() + view = self.form_views[form_submitted].as_view() return view(request, *args, **kwargs)