diff --git a/smash/web/forms/forms.py b/smash/web/forms/forms.py index e59536a3c6d8e6b7866d6a593f80ffcbc3bed321..1aa33b920dd8735547cc2b8c786b81ef79e369d6 100644 --- a/smash/web/forms/forms.py +++ b/smash/web/forms/forms.py @@ -6,8 +6,9 @@ from django import forms from django.forms import ModelForm, Form from django.utils.dates import MONTHS -from web.models import StudySubject, Worker, Appointment, Visit, AppointmentType, ContactAttempt, AppointmentTypeLink, \ - Availability, Holiday +from web.models import Appointment, AppointmentType, AppointmentTypeLink, \ + Availability, ContactAttempt, FlyingTeam, Holiday, StudySubject, \ + Worker, Visit, VoucherType, VoucherTypePrice from web.models.constants import SUBJECT_TYPE_CHOICES from web.views.notifications import get_filter_locations @@ -368,6 +369,18 @@ def validate_availability_conflict(self, cleaned_data, availability): self.add_error('available_till', error) +class FlyingTeamAddForm(ModelForm): + class Meta: + model = FlyingTeam + fields = "__all__" + + +class FlyingTeamEditForm(ModelForm): + class Meta: + model = FlyingTeam + fields = "__all__" + + class HolidayAddForm(ModelForm): datetime_start = forms.DateTimeField(widget=forms.DateTimeInput(DATETIMEPICKER_DATE_ATTRS), initial=datetime.datetime.now().replace(hour=8, minute=0), diff --git a/smash/web/templates/equipment_and_rooms/flying_teams/add.html b/smash/web/templates/equipment_and_rooms/flying_teams/add.html new file mode 100644 index 0000000000000000000000000000000000000000..c96adb11be9490cf8c377d49808f15f47a498a6f --- /dev/null +++ b/smash/web/templates/equipment_and_rooms/flying_teams/add.html @@ -0,0 +1,62 @@ +{% extends "_base.html" %} +{% load static %} +{% load filters %} + +{% block styles %} + {{ block.super }} + <link rel="stylesheet" href="{% static 'AdminLTE/plugins/awesomplete/awesomplete.css' %}"/> +{% endblock styles %} + +{% block ui_active_tab %}'equipment_and_rooms'{% endblock ui_active_tab %} +{% block page_header %}New flying team{% endblock page_header %} +{% block page_description %}{% endblock page_description %} + +{% block title %}{{ block.super }} - Add new flying team{% endblock %} + +{% block breadcrumb %} + {% include "equipment_and_rooms/flying_teams/breadcrumb.html" %} +{% endblock breadcrumb %} + +{% block maincontent %} + + <div class="box box-info"> + <div class="box-header with-border"> + <a href="{% url 'web.views.equipment_and_rooms.flying_teams' %}" class="btn btn-block btn-default">Go back (without changes)</a> + </div> + + <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="{# 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> + </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.equipment_and_rooms.flying_teams' %}" class="btn btn-block btn-default">Cancel</a> + </div> + </div><!-- /.box-footer --> + </form> + </div> + {% endblock %} diff --git a/smash/web/templates/equipment_and_rooms/flying_teams/breadcrumb.html b/smash/web/templates/equipment_and_rooms/flying_teams/breadcrumb.html new file mode 100644 index 0000000000000000000000000000000000000000..1259da09b4464c8cc63a417b77d527b05c3505f5 --- /dev/null +++ b/smash/web/templates/equipment_and_rooms/flying_teams/breadcrumb.html @@ -0,0 +1,3 @@ +<li><a href="{% url 'web.views.appointments' %}"><i class="fa fa-dashboard"></i> Dashboard</a></li> +<li><a href="{% url 'web.views.equipment_and_rooms' %}">Equipment and rooms</a></li> +<li class="active"><a href="{% url 'web.views.equipment_and_rooms.flying_teams' %}">Flying teams</a></li> diff --git a/smash/web/templates/equipment_and_rooms/flying_teams/edit.html b/smash/web/templates/equipment_and_rooms/flying_teams/edit.html new file mode 100644 index 0000000000000000000000000000000000000000..a94f80cc7783e6500b2a16f933da50511175312d --- /dev/null +++ b/smash/web/templates/equipment_and_rooms/flying_teams/edit.html @@ -0,0 +1,62 @@ +{% extends "_base.html" %} +{% load static %} +{% load filters %} + +{% block styles %} + {{ block.super }} + <link rel="stylesheet" href="{% static 'AdminLTE/plugins/awesomplete/awesomplete.css' %}"/> +{% endblock styles %} + +{% block ui_active_tab %}'equipment_and_rooms'{% endblock ui_active_tab %} +{% block page_header %}Edit flying team{% endblock page_header %} +{% block page_description %}{% endblock page_description %} + +{% block title %}{{ block.super }} - Edit flying team{% endblock %} + +{% block breadcrumb %} + {% include "equipment_and_rooms/flying_teams/breadcrumb.html" %} +{% endblock breadcrumb %} + +{% block maincontent %} + + <div class="box box-info"> + <div class="box-header with-border"> + <a href="{% url 'web.views.equipment_and_rooms.flying_teams' %}" class="btn btn-block btn-default">Go back (without changes)</a> + </div> + + <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="{# 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> + </div><!-- /.box-body --> + + <div class="box-footer"> + <div class="col-sm-6"> + <button type="submit" class="btn btn-block btn-success">Save</button> + </div> + <div class="col-sm-6"> + <a href="{% url 'web.views.equipment_and_rooms.flying_teams' %}" class="btn btn-block btn-default">Cancel</a> + </div> + </div><!-- /.box-footer --> + </form> + </div> + {% endblock %} diff --git a/smash/web/templates/equipment_and_rooms/flying_teams/index.html b/smash/web/templates/equipment_and_rooms/flying_teams/index.html new file mode 100644 index 0000000000000000000000000000000000000000..4a55f8953d80f6144bb0112cebbebee8f1412882 --- /dev/null +++ b/smash/web/templates/equipment_and_rooms/flying_teams/index.html @@ -0,0 +1,52 @@ +{% extends "_base.html" %} +{% load static %} + +{% block styles %} + {{ block.super }} + <!-- DataTables --> + <link rel="stylesheet" href="{% static 'AdminLTE/plugins/datatables/dataTables.bootstrap.css' %}"> +{% endblock styles %} + +{% block ui_active_tab %}'equipment_and_rooms'{% endblock ui_active_tab %} +{% block page_header %}Flying teams{% endblock page_header %} +{% block page_description %}management{% endblock page_description %} + +{% block breadcrumb %} + {% include "equipment_and_rooms/flying_teams/breadcrumb.html" %} +{% endblock breadcrumb %} + +{% block maincontent %} +<div> + <a href="{% url 'web.views.equipment_and_rooms.flying_teams_add' %}" class="btn btn-app"> + <i class="fa fa-plus"></i> + Add new flying team</a> +</div> + +<div class="box-body"> + {% if flying_team_list %} + <table id="table" class="table table-bordered table-striped"> + <thead> + <tr> + <th>No.</th> + <th>Location</th> + <th>Edit</th> + </tr> + </thead> + <tbody> + {% for flying_team in flying_team_list %} + <tr> + <td>{{ forloop.counter }}</td> + <td>{{ flying_team.place }}</td> + <td> + <a href="{% url 'web.views.equipment_and_rooms.flying_teams_edit' flying_team.id %}" type="button" + class="btn btn-block btn-default">Change</a></td> + </td> + </tr> + {% endfor %} + + </tbody> + </table> + {% else %} + <p>No flying teams found.</p> + {% endif %} +{% endblock maincontent %} diff --git a/smash/web/templates/equipment_and_rooms/index.html b/smash/web/templates/equipment_and_rooms/index.html index d9ba8764cd81623bdf3a057e8d9ce708ca61dabc..d4e27c7147abcb32c52818c5358bd6d49d36ab36 100644 --- a/smash/web/templates/equipment_and_rooms/index.html +++ b/smash/web/templates/equipment_and_rooms/index.html @@ -61,20 +61,6 @@ Edit <i class="fa fa-arrow-circle-right"></i> </a> </div> - - <div class="bg-red disabled small-box"> - <div class="inner"> - <h4>Flying teams</h4> - - <p> </p> - </div> - <div class="icon"> - <i class="ion ion-android-car"></i> - </div> - <a href="#" class="small-box-footer"> - Edit <i class="fa fa-arrow-circle-right"></i> - </a> - </div> </div> {% endcomment %} @@ -93,6 +79,20 @@ </a> </div> + <div class="bg-red small-box"> + <div class="inner"> + <h4>Flying teams</h4> + + <p> </p> + </div> + <div class="icon"> + <i class="ion ion-android-car"></i> + </div> + <a href="{% url 'web.views.equipment_and_rooms.flying_teams' %}" class="small-box-footer"> + Manage <i class="fa fa-arrow-circle-right"></i> + </a> + </div> + {% comment %} <div class="bg-yellow small-box"> <div class="inner"> diff --git a/smash/web/templates/equipment_and_rooms/kit_requests/breadcrumb.html b/smash/web/templates/equipment_and_rooms/kit_requests/breadcrumb.html new file mode 100644 index 0000000000000000000000000000000000000000..b2e3801aaee04939f8c6b2ff00a28d2731a518b2 --- /dev/null +++ b/smash/web/templates/equipment_and_rooms/kit_requests/breadcrumb.html @@ -0,0 +1,3 @@ +<li><a href="{% url 'web.views.appointments' %}"><i class="fa fa-dashboard"></i> Dashboard</a></li> +<li><a href="{% url 'web.views.equipment_and_rooms' %}">Equipment and rooms</a></li> +<li class="active"><a href="{% url 'web.views.kit_requests' %}">Kit requests</a></li> diff --git a/smash/web/templates/equipment_and_rooms/kit_requests.html b/smash/web/templates/equipment_and_rooms/kit_requests/kit_requests.html similarity index 98% rename from smash/web/templates/equipment_and_rooms/kit_requests.html rename to smash/web/templates/equipment_and_rooms/kit_requests/kit_requests.html index 764d3b4bcc8a1e4b7d2decf037b3beaaa8988499..3d5b0bafa76f151581b5c364426c241de1fc9381 100644 --- a/smash/web/templates/equipment_and_rooms/kit_requests.html +++ b/smash/web/templates/equipment_and_rooms/kit_requests/kit_requests.html @@ -14,7 +14,7 @@ {% endblock styles %} {% block breadcrumb %} - {% include "equipment_and_rooms/breadcrumb.html" %} + {% include "equipment_and_rooms/kit_requests/breadcrumb.html" %} {% endblock breadcrumb %} {% block maincontent %} diff --git a/smash/web/templates/equipment_and_rooms/kit_requests_send_mail.html b/smash/web/templates/equipment_and_rooms/kit_requests/kit_requests_send_mail.html similarity index 100% rename from smash/web/templates/equipment_and_rooms/kit_requests_send_mail.html rename to smash/web/templates/equipment_and_rooms/kit_requests/kit_requests_send_mail.html diff --git a/smash/web/templates/sidebar.html b/smash/web/templates/sidebar.html index 71c325a1cc768df50f5898b59b8e3e1b1aeefa6a..05498fc5bf407bdd307a8e554214a598a5105953 100644 --- a/smash/web/templates/sidebar.html +++ b/smash/web/templates/sidebar.html @@ -30,11 +30,17 @@ </a> </li> - <li data-desc="equipment_and_rooms"> + <li data-desc="equipment_and_rooms" class="treeview"> <a href="{% url 'web.views.equipment_and_rooms' %}"> - <i class="fa fa-building-o"></i> - <span>Equipment&rooms</span> + <i class="fa fa-building-o"></i> <span>Equipment&rooms</span> + <span class="pull-right-container"> + <i class="fa fa-angle-left pull-right"></i> + </span> </a> + <ul class="treeview-menu"> + <li><a href="{% url 'web.views.kit_requests' %}">Kit requests</a></li> + <li><a href="{% url 'web.views.equipment_and_rooms.flying_teams' %}">Flying teams</a></li> + </ul> </li> <li data-desc="statistics"> @@ -79,4 +85,4 @@ </ul> </li> -</ul> \ No newline at end of file +</ul> diff --git a/smash/web/tests/view/test_flying_teams.py b/smash/web/tests/view/test_flying_teams.py new file mode 100644 index 0000000000000000000000000000000000000000..32cfe22ff9d0ac7cbd073f66dd3691ff051a06b9 --- /dev/null +++ b/smash/web/tests/view/test_flying_teams.py @@ -0,0 +1,58 @@ +import logging + +from django.urls import reverse + +from web.tests.functions import create_flying_team +from web.models import FlyingTeam +from web.tests import LoggedInTestCase + +logger = logging.getLogger(__name__) + + +class FlyingTeamTests(LoggedInTestCase): + @staticmethod + def generate_more_or_less_random_name(): + import random + letters = [chr(x) for x in range(97, 122)] + return 'Random' + ''.join(random.choice(letters) for x in range(15)) + + def test_flying_team_requests(self): + pages = [ + 'web.views.equipment_and_rooms.flying_teams', + 'web.views.equipment_and_rooms.flying_teams_add', + ] + + for page in pages: + response = self.client.get(reverse(page)) + self.assertEqual(response.status_code, 200) + + def test_flying_team_add(self): + page = reverse('web.views.equipment_and_rooms.flying_teams_add') + data = { + 'place': self.generate_more_or_less_random_name() + } + response = self.client.post(page, data) + self.assertEqual(response.status_code, 302) + + freshly_created = FlyingTeam.objects.filter(place=data['place']) + self.assertEqual(len(freshly_created), 1) + + def test_flying_team_edit(self): + flying_team = create_flying_team() + page = reverse('web.views.equipment_and_rooms.flying_teams_edit', + kwargs={'flying_team_id': str(flying_team.id)}) + data = { + 'place': self.generate_more_or_less_random_name() + } + response = self.client.post(page, data) + self.assertEqual(response.status_code, 302) + + freshly_edited = FlyingTeam.objects.get(id=flying_team.id) + self.assertEqual(freshly_edited.place, data["place"]) + + def test_flying_team_edit_request(self): + flying_team = create_flying_team() + page = reverse('web.views.equipment_and_rooms.flying_teams_edit', + kwargs={'flying_team_id': str(flying_team.id)}) + response = self.client.get(page) + self.assertEqual(response.status_code, 200) diff --git a/smash/web/urls.py b/smash/web/urls.py index 567ef50b4e736c0d4b80d319f9592ef508be8b66..c58aa7bb6a3cebcf9310718f5c7042e1ca58e02f 100644 --- a/smash/web/urls.py +++ b/smash/web/urls.py @@ -128,6 +128,9 @@ urlpatterns = [ name='web.views.kit_requests_send_mail'), url(r'^equipment_and_rooms/kit_requests/(?P<start_date>[\w-]+)/(?P<end_date>[\w-]+)/$', views.kit.kit_requests_send_mail, name='web.views.kit_requests_send_mail'), + url(r'^equipment_and_rooms/flying_teams$', views.flying_teams.flying_teams, name='web.views.equipment_and_rooms.flying_teams'), + url(r'^equipment_and_rooms/flying_teams/add$', views.flying_teams.flying_teams_add, name='web.views.equipment_and_rooms.flying_teams_add'), + url(r'^equipment_and_rooms/flying_teams/edit/(?P<flying_team_id>\d+)$', views.flying_teams.flying_teams_edit, name='web.views.equipment_and_rooms.flying_teams_edit'), #################### # MAIL # diff --git a/smash/web/views/__init__.py b/smash/web/views/__init__.py index 296d4e9fdd25fb4324344099abd639f0621246a0..fedbe5fd8b6300d36166e6e9ba058174553a0352 100644 --- a/smash/web/views/__init__.py +++ b/smash/web/views/__init__.py @@ -70,6 +70,7 @@ import visit import doctor import subject import equipment +import flying_teams import kit import mails import statistics diff --git a/smash/web/views/equipment.py b/smash/web/views/equipment.py index 0a8299071a793695c39d007a65dfe22043b496d2..579f8b98ee33fa02de552d22c4c96fd3a05f3dba 100644 --- a/smash/web/views/equipment.py +++ b/smash/web/views/equipment.py @@ -1,4 +1,6 @@ # coding=utf-8 +from django.shortcuts import redirect + from . import wrap_response from ..models import Item diff --git a/smash/web/views/flying_teams.py b/smash/web/views/flying_teams.py new file mode 100644 index 0000000000000000000000000000000000000000..42d1400b1a8b7c11d074d98dd3a09b062d8b3d60 --- /dev/null +++ b/smash/web/views/flying_teams.py @@ -0,0 +1,42 @@ +# coding=utf-8 +from django.shortcuts import redirect, get_object_or_404 + +from . import wrap_response +from ..models import FlyingTeam +from ..forms.forms import FlyingTeamAddForm, FlyingTeamEditForm + + +def flying_teams(request): + flying_team_list = FlyingTeam.objects.order_by('-place') + context = { + 'flying_team_list': flying_team_list + } + + return wrap_response(request, + "equipment_and_rooms/flying_teams/index.html", + context) + + +def flying_teams_add(request): + if request.method == 'POST': + form = FlyingTeamAddForm(request.POST) + if form.is_valid(): + form.save() + return redirect('web.views.equipment_and_rooms.flying_teams') + else: + form = FlyingTeamAddForm() + + return wrap_response(request, 'equipment_and_rooms/flying_teams/add.html', {'form': form}) + + +def flying_teams_edit(request, flying_team_id): + the_flying_team = get_object_or_404(FlyingTeam, id=flying_team_id) + if request.method == 'POST': + form = FlyingTeamEditForm(request.POST, instance=the_flying_team) + if form.is_valid(): + form.save() + return redirect('web.views.equipment_and_rooms.flying_teams') + else: + form = FlyingTeamEditForm(instance=the_flying_team) + + return wrap_response(request, 'equipment_and_rooms/flying_teams/edit.html', {'form': form}) diff --git a/smash/web/views/kit.py b/smash/web/views/kit.py index fc4cbf376296ac9b8a5746101d3c3fc2589c86a0..f9c51a31aba12340f05fecff8e442a74028654aa 100644 --- a/smash/web/views/kit.py +++ b/smash/web/views/kit.py @@ -75,7 +75,7 @@ def get_kit_requests_data(request, start_date=None, end_date=None): def kit_requests(request): - return wrap_response(request, 'equipment_and_rooms/kit_requests.html', get_kit_requests_data(request)) + return wrap_response(request, 'equipment_and_rooms/kit_requests/kit_requests.html', get_kit_requests_data(request)) def send_mail(data): @@ -125,7 +125,7 @@ def kit_requests_send_mail(request, start_date, end_date=None): messages.add_message(request, messages.SUCCESS, 'Mail sent') except: messages.add_message(request, messages.ERROR, 'There was problem with sending email') - return wrap_response(request, 'equipment_and_rooms/kit_requests.html', get_kit_requests_data(request)) + return wrap_response(request, 'equipment_and_rooms/kit_requests/kit_requests.html', get_kit_requests_data(request)) class KitRequestEmailSendJob(CronJobBase):