diff --git a/smash/web/forms.py b/smash/web/forms.py index a461805b1a2f5c4ebe7e7e7676943971a784986c..d1b4f2b7afa452499322314ead0cb253cdaa9c95 100644 --- a/smash/web/forms.py +++ b/smash/web/forms.py @@ -4,7 +4,7 @@ from django import forms from django.forms import ModelForm, Form from django.utils.dates import MONTHS -from models import Subject, Worker, Appointment, Visit +from models import Subject, Worker, Appointment, Visit, AppointmentType """ Possible redundancy, but if need arises, contents of forms can be easily customized @@ -133,6 +133,8 @@ class AppointmentEditForm(ModelForm): datetime_when = forms.DateTimeField(label='Appointment on (YYYY-MM-DD HH:MM)', widget=forms.DateTimeInput(DATETIMEPICKER_DATE_ATTRS) ) + appointment_types = forms.ModelMultipleChoiceField(required=False, widget=forms.CheckboxSelectMultiple, + queryset=AppointmentType.objects.all()) def __init__(self, *args, **kwargs): user = kwargs.pop('user', None) @@ -160,6 +162,8 @@ class AppointmentAddForm(ModelForm): datetime_when = forms.DateTimeField(label='Appointment on (YYYY-MM-DD HH:MM)', widget=forms.DateTimeInput(DATETIMEPICKER_DATE_ATTRS) ) + appointment_types = forms.ModelMultipleChoiceField(required=False, widget=forms.CheckboxSelectMultiple, + queryset=AppointmentType.objects.all()) def __init__(self, *args, **kwargs): user = kwargs.pop('user', None) @@ -188,6 +192,8 @@ class VisitDetailForm(ModelForm): ) post_mail_sent = forms.RadioSelect() + appointment_types = forms.ModelMultipleChoiceField(required=False, widget=forms.CheckboxSelectMultiple, + queryset=AppointmentType.objects.all()) class Meta: model = Visit @@ -202,6 +208,8 @@ class VisitAddForm(ModelForm): datetime_end = forms.DateField(label="Visit ends on", widget=forms.TextInput(attrs=DATEPICKER_DATE_ATTRS) ) + appointment_types = forms.ModelMultipleChoiceField(required=False, widget=forms.CheckboxSelectMultiple, + queryset=AppointmentType.objects.all()) class Meta: model = Visit diff --git a/smash/web/models.py b/smash/web/models.py index 56811396e49cb1b461671646cd84a363813e1913..1a4c1f6214b3cc5726eb78f84e3666e3cadba603 100644 --- a/smash/web/models.py +++ b/smash/web/models.py @@ -322,11 +322,14 @@ class AppointmentType(models.Model): default='ANY' ) + class Meta: + ordering = ['description'] + def __str__(self): - return self.code + return self.description def __unicode__(self): - return self.code + return self.description class Worker(models.Model): diff --git a/smash/web/static/css/smash.css b/smash/web/static/css/smash.css new file mode 100644 index 0000000000000000000000000000000000000000..ca1d8dc0ecdbdac2987a5d6fb91b2fd4691abfb9 --- /dev/null +++ b/smash/web/static/css/smash.css @@ -0,0 +1,21 @@ +.multi-checkboxes ul { + list-style: none; + column-count: 3; + -moz-column-count: 3; + -webkit-column-count: 3; +} + +.multi-checkboxes li { + margin: 0; + padding: 0; +} + +.flag-icon { + height: 20px; +} + +.multi-checkboxes .form-control:not(select) { + -moz-appearance: initial; + -webkit-appearance: initial; + appearance: initial; +} \ No newline at end of file diff --git a/smash/web/templates/_base.html b/smash/web/templates/_base.html index feceaeed1ec4f054a4670257224e0743880e5dfa..e7d27b5557a333a0de52174215e012c6a585f258 100644 --- a/smash/web/templates/_base.html +++ b/smash/web/templates/_base.html @@ -22,17 +22,14 @@ <link rel="stylesheet" href="{% static 'AdminLTE/css/skins/skin-green.min.css' %}"> - <style> - .flag-icon { - height: 20px; - } - </style> + <link rel="stylesheet" href="{% static 'css/smash.css' %}"> + <!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries --> <!--[if lt IE 9]> - <script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script> - <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script> - <![endif]--> + <script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script> + <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script> + <![endif]--> {% endblock styles %} </head> <!-- @@ -260,6 +257,7 @@ desired effect <!-- Default to the left --> 2017, Parkinson Research Clinic <!--(eg. <small> + <strong>Copyright © 2016 <a href="#">Company</a>.</strong> All rights reserved. </small>)--> {% endblock footer %} diff --git a/smash/web/templates/appointments/add.html b/smash/web/templates/appointments/add.html index 07b201acf2ac1faa2db151a7fe48ed68e269298d..493367200aa38eeb6caf3dcb62d8b2b6b3fac552 100644 --- a/smash/web/templates/appointments/add.html +++ b/smash/web/templates/appointments/add.html @@ -38,11 +38,10 @@ <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 %}"> + <div class="form-group {% if field.errors %}has-error{% endif %} {% if field|is_checkbox %}multi-checkboxes{% endif %}"> <label class="col-sm-4 control-label"> {{ field.label }} </label> diff --git a/smash/web/templates/appointments/edit.html b/smash/web/templates/appointments/edit.html index 93ff194ab063c0799e0391d39e336babcbcb557d..eb50e3b8357f47ce2692b75f82ff31083ac6ec31 100644 --- a/smash/web/templates/appointments/edit.html +++ b/smash/web/templates/appointments/edit.html @@ -38,11 +38,10 @@ <div class="box-body"> {% for field in form %} - <div class="col-md-6 form-group {% if field.errors %}has-error{% endif %}"> + <div class="col-md-6 form-group {% if field.errors %}has-error{% endif %} {% if field|is_checkbox %}multi-checkboxes{% endif %}"> <label for="{# TODO #}" class="col-sm-4 control-label"> {{ field.label }} </label> - <div class="col-sm-8"> {{ field|add_class:'form-control' }} </div> diff --git a/smash/web/templates/visits/add.html b/smash/web/templates/visits/add.html index d82401432851415ef92cede1b3853e323e5d14f7..74a84ab4f6481ec5410cf13f54d59e151654249e 100644 --- a/smash/web/templates/visits/add.html +++ b/smash/web/templates/visits/add.html @@ -35,11 +35,10 @@ <div class="box-body"> <div class="col-sm-6"> {% for field in form %} - <div class="form-group {% if field.errors %}has-error{% endif %}"> + <div class="form-group {% if field.errors %}has-error{% endif %} {% if field|is_checkbox %}multi-checkboxes{% endif %}"> <label class="col-sm-4 control-label"> {{ field.label }} </label> - <div class="col-sm-8"> {{ field|add_class:'form-control' }} </div> diff --git a/smash/web/templates/visits/details.html b/smash/web/templates/visits/details.html index 5f4454951c9d2ec4ac1a017463343a83f37aa181..c215b15eeacf4900e2b724056eb4c7da5b39d480 100644 --- a/smash/web/templates/visits/details.html +++ b/smash/web/templates/visits/details.html @@ -41,7 +41,7 @@ {% csrf_token %} <div class="box-body"> {% for field in vform %} - <div class="col-md-6 form-group {% if field.errors %}has-error{% endif %}"> + <div class="col-md-6 form-group {% if field.errors %}has-error{% endif %} {% if field|is_checkbox %}multi-checkboxes{% endif %}"> <label for="{# TODO #}" class="col-sm-4 control-label"> {{ field.label }} </label> diff --git a/smash/web/templatetags/filters.py b/smash/web/templatetags/filters.py index 45f03ee0f9e2a18ca2eb368001e24a63d4c7b75a..6bf38bfc188195b39fe80d6accd5167811f06874 100644 --- a/smash/web/templatetags/filters.py +++ b/smash/web/templatetags/filters.py @@ -1,5 +1,6 @@ # See: http://stackoverflow.com/a/18962481 from django import template +from django.forms import CheckboxSelectMultiple from django.utils.safestring import mark_safe register = template.Library() @@ -8,6 +9,8 @@ register = template.Library() @register.filter(name='add_class') def add_class(value, arg): # Get all the field's initial css-classes + if isinstance(value.field.widget, CheckboxSelectMultiple): + return value css_classes = value.field.widget.attrs.get('class', ' ').split(' ') # Filter out zero-length class names ('') css_classes = filter(lambda x: len(x) > 0, css_classes) @@ -24,6 +27,10 @@ def disable(value): return value +@register.filter(name='is_checkbox') +def is_checkbox(value): + return isinstance(value.field.widget, CheckboxSelectMultiple) + @register.filter(name="render_appointments") def render_appointments(statistics, appointment_type): html = ""