Check if user is authenticated for showing/accepting task event form

This commit is contained in:
Adam Goldsmith 2020-12-22 15:32:58 -05:00
parent 86fe80b375
commit e4b45ad948
2 changed files with 41 additions and 34 deletions

View File

@ -30,6 +30,7 @@
</div>
{% endif %}
{% if user.is_authenticated %}
<div class="d-md-none">
<h2> Log a Maintenance Event </h2>
<form class="form-group" method="post">
@ -51,6 +52,7 @@
{{ form.media }}
</div>
{% endif %}
<h2> Event Log </h2>
<table class="table table-striped table-hover">
@ -62,6 +64,7 @@
</tr>
</thead>
<tbody>
{% if user.is_authenticated %}
<tr class="d-none d-md-table-row">
<form method="post">
{% csrf_token %}
@ -71,6 +74,7 @@
<td> <input type="submit" class="btn btn-primary" value="Submit"> </td>
</form>
</tr>
{% endif %}
{% for event in events|dictsortreversed:"date" %}
<tr>
<td class="text-nowrap"> {{ event.date }} </td>

View File

@ -31,11 +31,14 @@ def taskDetail(request, asset_tag, task_slug):
events = task.event_set.all()
if request.method == 'POST':
if request.user.is_authenticated:
event = Event(task=task)
form = EventForm(request.POST, instance=event)
if form.is_valid():
form.save()
pass
else:
form = EventForm(request.POST)
form.add_error(None, "Not authenticated: please login")
else:
form = EventForm(initial={
'date': datetime.now(),