From 2d9a3ba03b2df90c303462991d62c7bdce228249 Mon Sep 17 00:00:00 2001
From: "piotr.atyjaszyk" <piotrmk1@gmail.com>
Date: Wed, 1 Feb 2017 10:12:55 +0100
Subject: [PATCH] Added robust details view for visit

---
 smash/web/forms.py                      |   5 +
 smash/web/templates/visits/details.html | 176 ++++++++++++++++++++++++
 smash/web/templates/visits/index.html   |   3 +-
 smash/web/urls.py                       |   1 +
 smash/web/views.py                      |  10 ++
 5 files changed, 194 insertions(+), 1 deletion(-)
 create mode 100644 smash/web/templates/visits/details.html

diff --git a/smash/web/forms.py b/smash/web/forms.py
index d3acb5f4..24053d95 100644
--- a/smash/web/forms.py
+++ b/smash/web/forms.py
@@ -46,3 +46,8 @@ class AppointmentDetailForm(ModelForm):
     class Meta:
         model = Appointment
         fields = '__all__'
+
+class VisitDetailForm(ModelForm):
+    class Meta:
+        model = Subject
+        fields = '__all__'
diff --git a/smash/web/templates/visits/details.html b/smash/web/templates/visits/details.html
new file mode 100644
index 00000000..936f8889
--- /dev/null
+++ b/smash/web/templates/visits/details.html
@@ -0,0 +1,176 @@
+{% extends "_base.html" %}
+{% load static %}
+{% load filters %}
+
+{% block styles %}
+{{ block.super }}
+	<!-- DataTables -->
+  <link rel="stylesheet" href="{% static 'AdminLTE/plugins/datatables/dataTables.bootstrap.css' %}">
+{% endblock styles %}
+
+{% block page_title %}'visits'{% endblock page_title %}
+{% block page_header %}Details of the visit{% endblock page_header %}
+{% block page_description %}{% endblock page_description %}
+
+{% block title %}{{ block.super }} - Details of visit {% endblock %}
+
+{% block breadcrumb %}
+{% include "subjects/breadcrumb.html" %}
+{% endblock breadcrumb %}
+
+{% block maincontent %}
+
+{% block content %}
+<div class="box box-info">
+	<div class="box-header with-border">
+		<a href="{% url 'web.views.visits' %}" class="btn btn-block btn-default" onclick="history.back()">Back</a>
+	</div>
+
+	{% comment %} <div class="box-header with-border">
+		<h3 class="box-title">Details of visit</h3>
+	</div>{% endcomment %}
+
+	<form class="form-horizontal">
+		<div class="box-body">
+      {% for field in vform %}
+				<div class="col-md-6 form-group  {% if field.errors %}has-error{% endif %}">
+					<label for="{# TODO #}" class="col-sm-4 control-label">
+						{{ field.label }}
+					</label>
+
+					<div class="col-sm-8">
+						{{ field|add_class:'form-control' }}
+					</div>
+
+          {% if field.errors %}
+            <span class="help-block">
+              {{ field.errors }}
+            </span>
+          {% endif %}
+				</div>
+			{% endfor %}
+		</div><!-- /.box-body -->
+
+		<div class="box-footer">
+			<a href="{% url 'web.views.subjects' %}" class="btn btn-block btn-default" onclick="history.back()">Back</a>
+		</div><!-- /.box-footer -->
+	</form>
+</div>
+
+</form>
+
+
+
+
+
+
+
+
+
+
+
+{% comment %} <div class="box-header with-border">
+  <h3 class="box-title">Visit's assignments</h3>
+</div>{% endcomment %}
+
+{% if loApp %}
+<table id="table" class="table table-bordered table-striped">
+  <thead>
+    <tr>
+      <th>No.</th>
+      <th>Type</th>
+      <th>Date</th>
+      <th>Time</th>
+      <th>Length</th>
+      <th>Responsible</th>
+    </tr>
+  </thead>
+<tbody>
+  {% for app in loApp %}
+  <tr>
+    <td>{{ forloop.counter }}</td>
+    <td>{{ app.appDateTime | date:"d-M-Y" }}</td>
+    <td>{{ app.appDateTime | time:"H:i" }}</td>
+    <td>{{ app.appLength }}</td>
+    <td>
+      {% if app.flyingTeam %}{{ app.workerAssigned.firstName }} {{app.workerAssigned.lastName}}
+      {% else %} {{ app.flyingTeam }}
+      {% endif %}
+    </td>
+  </tr>
+  {% endfor %}
+
+</tbody>
+</table>
+{% else %}
+  <p>No appointments found.</p>
+{% endif %}
+
+
+
+
+
+
+
+
+
+
+
+{% comment %} <div class="box-header with-border">
+  <h3 class="box-title">Subject's details</h3>
+</div>{% endcomment %}
+
+<form class="form-horizontal">
+  <div class="box-body">
+    {% for field in vform %}
+      <div class="col-md-6 form-group  {% if field.errors %}has-error{% endif %}">
+        <label for="{# TODO #}" class="col-sm-4 control-label">
+          {{ field.label }}
+        </label>
+
+        <div class="col-sm-8">
+          {{ field|add_class:'form-control' }}
+        </div>
+
+        {% if field.errors %}
+          <span class="help-block">
+            {{ field.errors }}
+          </span>
+        {% endif %}
+      </div>
+    {% endfor %}
+  </div><!-- /.box-body -->
+
+  <div class="box-footer">
+    <a href="{% url 'web.views.subjects' %}" class="btn btn-block btn-default" onclick="history.back()">Back</a>
+  </div><!-- /.box-footer -->
+</form>
+</div>
+
+</form>
+{% endblock %}
+
+
+
+
+
+{% endblock maincontent %}
+
+{% block scripts %}
+	{{ block.super }}
+
+	<script src="{% static 'AdminLTE/plugins/datatables/jquery.dataTables.min.js' %}"></script>
+	<script src="{% static 'AdminLTE/plugins/datatables/dataTables.bootstrap.min.js' %}"></script>
+	<script>
+		$(function () {
+			$('#table').DataTable({
+			  "paging": true,
+			  "lengthChange": false,
+			  "searching": true,
+			  "ordering": true,
+			  "info": true,
+			  "autoWidth": false
+			});
+		});
+	</script>
+{% endblock scripts %}
diff --git a/smash/web/templates/visits/index.html b/smash/web/templates/visits/index.html
index b83917eb..c18b0a5d 100644
--- a/smash/web/templates/visits/index.html
+++ b/smash/web/templates/visits/index.html
@@ -1,6 +1,7 @@
 {% extends "_base.html" %}
 {% load static %}
 
+
 {% block styles %}
 {{ block.super }}
   <!-- DataTables -->
@@ -41,7 +42,7 @@
 		  		<tr>
 		  			<td>{{ visit.subject.firstName }} {{ visit.subject.lastName }}</td>
 		        	<td>
-		        		<button type="button" class="btn btn-block btn-default btn-xs">See full information</button>
+                <a href="{% url 'web.views.visit_details' visit.id %}" type="button" class="btn btn-block btn-default">Details</a>
 		        	</td>
 		        	<td>
 		        		{{ visit.visitBegin }}
diff --git a/smash/web/urls.py b/smash/web/urls.py
index a46b4add..1a5b7bb3 100644
--- a/smash/web/urls.py
+++ b/smash/web/urls.py
@@ -21,6 +21,7 @@ urlpatterns = [
     url(r'assignments/details/(?P<id>\d+)$', views.assignment_details, name='web.views.assignment_details'),
 
     url(r'visits$', views.visits, name='web.views.visits'),
+    url(r'visits/details/(?P<id>\d+)$', views.visit_details, name='web.views.visit_details'),
 
     url(r'subjects$', views.subjects, name='web.views.subjects'),
     url(r'subjects/add$', views.subject_add, name='web.views.subject_add'),
diff --git a/smash/web/views.py b/smash/web/views.py
index 7d36df20..b74e4f20 100644
--- a/smash/web/views.py
+++ b/smash/web/views.py
@@ -62,6 +62,16 @@ def visits(request):
 	return wrap_response(request, 'visits/index.html', context)
 
 
+def visit_details(request, id):
+	displayedVisit = Visit.objects.get(id=id)
+	displayedSubject = displayedVisit.subject
+	listOfAppointments = displayedVisit.appointment_set
+	vform = VisitDetailForm(instance=displayedVisit)
+	sform = SubjectDetailForm(instance=displayedSubject)
+
+	return wrap_response(request, 'visits/details.html', {'vform': vform, 'sform': sform, 'loApp': listOfAppointments})
+
+
 def subjects(request):
 	subjects_list = Subject.objects.order_by('-lastName')
 	context = {
-- 
GitLab