From 0a8d594878308e3e5a63e22206f127a102800617 Mon Sep 17 00:00:00 2001 From: "piotr.atyjaszyk" <piotrmk1@gmail.com> Date: Wed, 1 Feb 2017 13:29:31 +0100 Subject: [PATCH] Now can add assignments from visit view --- smash/web/forms.py | 6 ++ smash/web/models.py | 4 +- smash/web/templates/assignments/add.html | 91 ++++++++++++++++++++ smash/web/templates/assignments/details.html | 2 +- smash/web/templates/visits/add.html | 4 +- smash/web/templates/visits/details.html | 8 ++ smash/web/urls.py | 1 + smash/web/views.py | 17 +++- 8 files changed, 128 insertions(+), 5 deletions(-) create mode 100644 smash/web/templates/assignments/add.html diff --git a/smash/web/forms.py b/smash/web/forms.py index 40869248..dc593518 100644 --- a/smash/web/forms.py +++ b/smash/web/forms.py @@ -47,6 +47,12 @@ class AppointmentDetailForm(ModelForm): model = Appointment fields = '__all__' + +class AppointmentAddForm(ModelForm): + class Meta: + model = Appointment + exclude = ['is_finished'] + class VisitDetailForm(ModelForm): class Meta: model = Visit diff --git a/smash/web/models.py b/smash/web/models.py index 1e16a369..0a96b6f6 100644 --- a/smash/web/models.py +++ b/smash/web/models.py @@ -152,9 +152,11 @@ class Visit(models.Model): verbose_name='Has ended', default=False ) + def __unicode__(self): + return "%s %s" % (self.subject.first_name, self.subject.last_name) def __str__(self): - return "%s %s %d" % (self.subject.first_name, self.subject.last_name, self.assesmentNo) + return "%s %s" % (self.subject.first_name, self.subject.last_name) class Item (models.Model): diff --git a/smash/web/templates/assignments/add.html b/smash/web/templates/assignments/add.html new file mode 100644 index 00000000..699842b6 --- /dev/null +++ b/smash/web/templates/assignments/add.html @@ -0,0 +1,91 @@ +{% 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 %}'assignments'{% endblock page_title %} +{% block page_header %}New appointment{% endblock page_header %} +{% block page_description %}{% endblock page_description %} + +{% block title %}{{ block.super }} - Add new appoitnment{% endblock %} + +{% block breadcrumb %} +{% include "assignments/breadcrumb.html" %} +{% endblock breadcrumb %} + +{% block maincontent %} + +{% block content %} +<div class="box box-info"> + <div class="box-header with-border"> + <a href="{% url 'web.views.assignments' %}" class="btn btn-block btn-default">Cancel</a> + </div> + + {% comment %} <div class="box-header with-border"> + <h3 class="box-title">Adding an assignment</h3> + </div>{% endcomment %} + + <form method="post" action="" class="form-horizontal"> + {% csrf_token %} + + <div class="box-body"> + <div class="col-sm-6"> + {% for field in form %} + <div class="form-group {% if field.errors %}has-error{% endif %}"> + <label for="inputEmail3" 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> + </div><!-- /.box-body --> + + <div class="box-footer"> + <div class="col-sm-6"> + <button type="submit" class="btn btn-block btn-success">Add</button> + </div> + <div class="col-sm-6"> + <a href="{% url 'web.views.visits' %}" class="btn btn-block btn-default">Cancel</a> + </div> + </div><!-- /.box-footer --> + </form> +</div> + +{% 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/assignments/details.html b/smash/web/templates/assignments/details.html index 39a97f2d..727ce3b8 100644 --- a/smash/web/templates/assignments/details.html +++ b/smash/web/templates/assignments/details.html @@ -7,7 +7,7 @@ <link rel="stylesheet" href="{% static 'AdminLTE/plugins/datatables/dataTables.bootstrap.css' %}"> {% endblock styles %} -{% block page_title %}'Assignments'{% endblock page_title %} +{% block page_title %}'assignments'{% endblock page_title %} {% block page_header %}Assignment's details{% endblock page_header %} {% block page_description %}details{% endblock page_description %} diff --git a/smash/web/templates/visits/add.html b/smash/web/templates/visits/add.html index 852234f4..f21345d8 100644 --- a/smash/web/templates/visits/add.html +++ b/smash/web/templates/visits/add.html @@ -12,10 +12,10 @@ {% block page_header %}New visit{% endblock page_header %} {% block page_description %}{% endblock page_description %} -{% block title %}{{ block.super }} - Add new subject{% endblock %} +{% block title %}{{ block.super }} - Add new visit{% endblock %} {% block breadcrumb %} -{% include "subjects/breadcrumb.html" %} +{% include "visits/breadcrumb.html" %} {% endblock breadcrumb %} {% block maincontent %} diff --git a/smash/web/templates/visits/details.html b/smash/web/templates/visits/details.html index daa13cf8..19e2e5aa 100644 --- a/smash/web/templates/visits/details.html +++ b/smash/web/templates/visits/details.html @@ -82,6 +82,14 @@ <h3 class="box-title">Visit's assignments</h3> </div> +<div> + <a href="{% url 'web.views.assignment_add' vid %}" class="btn btn-app"> + <i class="fa fa-plus"></i> + Add new assignment + </a> +</div> + + {% if loApp %} <table id="table" class="table table-bordered table-striped"> <thead> diff --git a/smash/web/urls.py b/smash/web/urls.py index 33bec411..bf8d87bd 100644 --- a/smash/web/urls.py +++ b/smash/web/urls.py @@ -19,6 +19,7 @@ from web import views urlpatterns = [ url(r'assignments$', views.assignments, name='web.views.assignments'), url(r'assignments/details/(?P<id>\d+)$', views.assignment_details, name='web.views.assignment_details'), + url(r'assignments/add/(?P<id>\d+)$', views.assignment_add, name='web.views.assignment_add'), url(r'visits$', views.visits, name='web.views.visits'), url(r'visits/details/(?P<id>\d+)$', views.visit_details, name='web.views.visit_details'), diff --git a/smash/web/views.py b/smash/web/views.py index 30b06e6e..bb4b1a28 100644 --- a/smash/web/views.py +++ b/smash/web/views.py @@ -65,12 +65,13 @@ def visits(request): def visit_details(request, id): displayedVisit = Visit.objects.get(id=id) visFinished = displayedVisit.is_finished + vid = displayedVisit.id displayedSubject = displayedVisit.subject listOfAppointments = displayedVisit.appointment_set.all() vform = VisitDetailForm(instance=displayedVisit) sform = SubjectDetailForm(instance=displayedSubject) - return wrap_response(request, 'visits/details.html', {'vform': vform, 'sform': sform, 'loApp': listOfAppointments, 'visFinished': visFinished}) + return wrap_response(request, 'visits/details.html', {'vform': vform, 'sform': sform, 'loApp': listOfAppointments, 'visFinished': visFinished, 'vid': vid}) def visit_add(request): @@ -240,3 +241,17 @@ def assignments(request): def assignment_details(request, id): form = AppointmentDetailForm(instance=Appointment.objects.get(id=id)) return wrap_response(request, 'assignments/details.html', {'form': form}) + + +def assignment_add(request, id): + if request.method == 'POST': + form = AppointmentAddForm(request.POST, request.FILES) + if form.is_valid(): + form.save() + return redirect(visit_details, id=id) + else: + form = AppointmentAddForm(initial={'visit': id}) + form.fields['visit'].widget = forms.HiddenInput() + + vid = id + return wrap_response(request, 'assignments/add.html', {'form': form, 'visitID': vid}) -- GitLab