diff --git a/tasks/templates/tasks/taskDetail.djhtml b/tasks/templates/tasks/taskDetail.djhtml index e6235cd..5c4aae4 100644 --- a/tasks/templates/tasks/taskDetail.djhtml +++ b/tasks/templates/tasks/taskDetail.djhtml @@ -30,27 +30,29 @@ {% endif %} -
-

Log a Maintenance Event

-
- {% csrf_token %} -
- {{ form.date.label_tag }} - {% render_field form.date type="date" class="form-control" %} -
-
- {{ form.user.label_tag }} - {% render_field form.user class="form-control" %} -
-
- {{ form.notes.label_tag }} - {% render_field form.notes class="form-control form-control-sm" rows="2" %} -
- -
+ {% if user.is_authenticated %} +
+

Log a Maintenance Event

+
+ {% csrf_token %} +
+ {{ form.date.label_tag }} + {% render_field form.date type="date" class="form-control" %} +
+
+ {{ form.user.label_tag }} + {% render_field form.user class="form-control" %} +
+
+ {{ form.notes.label_tag }} + {% render_field form.notes class="form-control form-control-sm" rows="2" %} +
+ +
- {{ form.media }} -
+ {{ form.media }} +
+ {% endif %}

Event Log

@@ -62,15 +64,17 @@ - - - {% csrf_token %} - - - - - - + {% if user.is_authenticated %} + + + {% csrf_token %} + + + + + + + {% endif %} {% for event in events|dictsortreversed:"date" %} diff --git a/tasks/views.py b/tasks/views.py index de03d88..8d08729 100644 --- a/tasks/views.py +++ b/tasks/views.py @@ -31,11 +31,14 @@ def taskDetail(request, asset_tag, task_slug): events = task.event_set.all() if request.method == 'POST': - event = Event(task=task) - form = EventForm(request.POST, instance=event) - if form.is_valid(): - form.save() - pass + if request.user.is_authenticated: + event = Event(task=task) + form = EventForm(request.POST, instance=event) + if form.is_valid(): + form.save() + else: + form = EventForm(request.POST) + form.add_error(None, "Not authenticated: please login") else: form = EventForm(initial={ 'date': datetime.now(),
{% render_field form.date type="date" class="form-control" %} {% render_field form.user class="form-control" style="width: initial;" %} {% render_field form.notes class="form-control form-control-sm" rows="2" %}
{% render_field form.date type="date" class="form-control" %} {% render_field form.user class="form-control" style="width: initial;" %} {% render_field form.notes class="form-control form-control-sm" rows="2" %}
{{ event.date }}