diff --git a/opentech/apply/templates/apply/demo_workflow.html b/opentech/apply/templates/apply/demo_workflow.html index 035647802e5a29572c5fd8c2574c4cf8552da698..9d0e5264f01d9d0b0e4ef9f8bd5e48d69cb66b07 100644 --- a/opentech/apply/templates/apply/demo_workflow.html +++ b/opentech/apply/templates/apply/demo_workflow.html @@ -17,6 +17,14 @@ <section class="container"> <h2>{{ workflow}}</h2> <h3>{{ phase.stage }}</h3> + {% if form %} + <form method="post"> + {% csrf_token %} + {{ form }} + <input id="current" type="hidden" name="current" value="{{ phase }}" /> + <button id="submit" name="submit">Submit</button> + </form> + {% else %} <h4>OTF: {{ phase.name }}</h4> <h4>Public: {{ phase.public_name }}</h4> <form method="post"> @@ -28,12 +36,23 @@ <h4>There are no actions</h4> {% endfor %} </form> + </section> + <section class="container"> + <h3>Logs</h3> <ul> {% for log in logs %} <li>{{ log }}</li> {% endfor %} </ul> </section> + <section class="container"> + <h3>Submission</h3> + {% for key, value in data.items %} + <h4>{{ key }}</h4> + {{ value }} + {% endfor %} + </section> + {% endif %} <section class="container"> <a class="button" href="">Reset</a> </section> diff --git a/opentech/apply/views.py b/opentech/apply/views.py index e4c712df72d9c67348b8a34c8634ba585f2b8c49..96cc77207f1714cfec1e3d7723462478864df629 100644 --- a/opentech/apply/views.py +++ b/opentech/apply/views.py @@ -1,4 +1,4 @@ -from django.forms import Form +from django import forms from django.shortcuts import render from django.template.response import TemplateResponse @@ -9,26 +9,54 @@ workflows = [SingleStage, DoubleStage] logs = [] +submission = {} + + +class BasicSubmissionForm(forms.Form): + who_are_you = forms.CharField() + + def demo_workflow(request, wf_id): wf = int(wf_id) workflow_class = workflows[wf-1] - workflow = workflow_class([Form()] * wf) + workflow = workflow_class([BasicSubmissionForm] * wf) current_phase = request.POST.get('current') + current = workflow.current(current_phase) + if request.POST: - current = workflow.current(current_phase) - phase = workflow.process(current_phase, request.POST['action']) - logs.append( - f'{current.stage}: {current.name} was updated to {phase.stage}: {phase.name}' - ) + if current.stage.name not in submission: + submitted_form = current.stage.form(request.POST) + if submitted_form.is_valid(): + submission[current.stage.name] = submitted_form + phase = current + logs.append( + f'{phase.stage}: Form was submitted' + ) + form = None + else: + form = submitted_form + else: + phase = workflow.process(current_phase, request.POST['action']) + logs.append( + f'{current.stage}: {current.name} was updated to {phase.stage}: {phase.name}' + ) else: - phase = workflow.current(current_phase) + phase = current logs.clear() + submission.clear() + + if phase.stage.name not in submission: + form = phase.stage.form + else: + form = None context = { 'workflow': workflow, 'phase': phase, 'logs': logs, + 'data': submission, + 'form': form, } return TemplateResponse(request, 'apply/demo_workflow.html', context)