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

Add the ability to submit to the demo

parent 756376a6
No related branches found
No related tags found
No related merge requests found
...@@ -17,6 +17,14 @@ ...@@ -17,6 +17,14 @@
<section class="container"> <section class="container">
<h2>{{ workflow}}</h2> <h2>{{ workflow}}</h2>
<h3>{{ phase.stage }}</h3> <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>OTF: {{ phase.name }}</h4>
<h4>Public: {{ phase.public_name }}</h4> <h4>Public: {{ phase.public_name }}</h4>
<form method="post"> <form method="post">
...@@ -28,12 +36,23 @@ ...@@ -28,12 +36,23 @@
<h4>There are no actions</h4> <h4>There are no actions</h4>
{% endfor %} {% endfor %}
</form> </form>
</section>
<section class="container">
<h3>Logs</h3>
<ul> <ul>
{% for log in logs %} {% for log in logs %}
<li>{{ log }}</li> <li>{{ log }}</li>
{% endfor %} {% endfor %}
</ul> </ul>
</section> </section>
<section class="container">
<h3>Submission</h3>
{% for key, value in data.items %}
<h4>{{ key }}</h4>
{{ value }}
{% endfor %}
</section>
{% endif %}
<section class="container"> <section class="container">
<a class="button" href="">Reset</a> <a class="button" href="">Reset</a>
</section> </section>
......
from django.forms import Form from django import forms
from django.shortcuts import render from django.shortcuts import render
from django.template.response import TemplateResponse from django.template.response import TemplateResponse
...@@ -9,26 +9,54 @@ workflows = [SingleStage, DoubleStage] ...@@ -9,26 +9,54 @@ workflows = [SingleStage, DoubleStage]
logs = [] logs = []
submission = {}
class BasicSubmissionForm(forms.Form):
who_are_you = forms.CharField()
def demo_workflow(request, wf_id): def demo_workflow(request, wf_id):
wf = int(wf_id) wf = int(wf_id)
workflow_class = workflows[wf-1] workflow_class = workflows[wf-1]
workflow = workflow_class([Form()] * wf) workflow = workflow_class([BasicSubmissionForm] * wf)
current_phase = request.POST.get('current') current_phase = request.POST.get('current')
current = workflow.current(current_phase)
if request.POST: if request.POST:
current = workflow.current(current_phase) if current.stage.name not in submission:
phase = workflow.process(current_phase, request.POST['action']) submitted_form = current.stage.form(request.POST)
logs.append( if submitted_form.is_valid():
f'{current.stage}: {current.name} was updated to {phase.stage}: {phase.name}' 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: else:
phase = workflow.current(current_phase) phase = current
logs.clear() logs.clear()
submission.clear()
if phase.stage.name not in submission:
form = phase.stage.form
else:
form = None
context = { context = {
'workflow': workflow, 'workflow': workflow,
'phase': phase, 'phase': phase,
'logs': logs, 'logs': logs,
'data': submission,
'form': form,
} }
return TemplateResponse(request, 'apply/demo_workflow.html', context) return TemplateResponse(request, 'apply/demo_workflow.html', context)
......
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