diff --git a/smash/web/forms/forms.py b/smash/web/forms/forms.py index 1aa33b920dd8735547cc2b8c786b81ef79e369d6..65e60931507fdbb9dd07f6325bd7a4f451bc5b57 100644 --- a/smash/web/forms/forms.py +++ b/smash/web/forms/forms.py @@ -7,7 +7,7 @@ from django.forms import ModelForm, Form from django.utils.dates import MONTHS from web.models import Appointment, AppointmentType, AppointmentTypeLink, \ - Availability, ContactAttempt, FlyingTeam, Holiday, StudySubject, \ + Availability, ContactAttempt, FlyingTeam, Holiday, StudySubject, Room, \ Worker, Visit, VoucherType, VoucherTypePrice from web.models.constants import SUBJECT_TYPE_CHOICES from web.views.notifications import get_filter_locations @@ -400,3 +400,7 @@ class HolidayAddForm(ModelForm): validate_availability_conflict(self, self.cleaned_data, availability) +class RoomForm(ModelForm): + class Meta: + model = Room + fields = '__all__' diff --git a/smash/web/templates/equipment_and_rooms/rooms/add.html b/smash/web/templates/equipment_and_rooms/rooms/add.html new file mode 100644 index 0000000000000000000000000000000000000000..f5cd36e3ed15a93141bf2cd69dbf6d08add05a5e --- /dev/null +++ b/smash/web/templates/equipment_and_rooms/rooms/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 room{% endblock page_header %} +{% block page_description %}{% endblock page_description %} + +{% block title %}{{ block.super }} - Add new room{% endblock %} + +{% block breadcrumb %} + {% include "equipment_and_rooms/rooms/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.rooms' %}" 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.rooms' %}" class="btn btn-block btn-default">Cancel</a> + </div> + </div><!-- /.box-footer --> + </form> + </div> + {% endblock %} diff --git a/smash/web/templates/equipment_and_rooms/rooms/breadcrumb.html b/smash/web/templates/equipment_and_rooms/rooms/breadcrumb.html index 0aeef03762093e789beaf1bf9363ea45669d065d..b2ecb34d76b1b2c14a78762297c46cbf855cf5cd 100644 --- a/smash/web/templates/equipment_and_rooms/rooms/breadcrumb.html +++ b/smash/web/templates/equipment_and_rooms/rooms/breadcrumb.html @@ -1,3 +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="">Rooms</a></li> +<li class="active"><a href="{% url 'web.views.equipment_and_rooms.rooms' %}">Rooms</a></li> diff --git a/smash/web/templates/equipment_and_rooms/rooms/edit.html b/smash/web/templates/equipment_and_rooms/rooms/edit.html new file mode 100644 index 0000000000000000000000000000000000000000..4a7e9b9e69aa9b3693dcf5f21dd4dd05f57cb7cc --- /dev/null +++ b/smash/web/templates/equipment_and_rooms/rooms/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 room{% endblock page_header %} +{% block page_description %}{% endblock page_description %} + +{% block title %}{{ block.super }} - Edit room{% endblock %} + +{% block breadcrumb %} + {% include "equipment_and_rooms/rooms/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.rooms' %}" 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.rooms' %}" class="btn btn-block btn-default">Cancel</a> + </div> + </div><!-- /.box-footer --> + </form> + </div> + {% endblock %} diff --git a/smash/web/templates/equipment_and_rooms/rooms/index.html b/smash/web/templates/equipment_and_rooms/rooms/index.html new file mode 100644 index 0000000000000000000000000000000000000000..454cd79ed545d547da67be8295c9483c27075946 --- /dev/null +++ b/smash/web/templates/equipment_and_rooms/rooms/index.html @@ -0,0 +1,61 @@ +{% 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 %}Rooms{% endblock page_header %} +{% block page_description %}management{% endblock page_description %} + +{% block breadcrumb %} + {% include "equipment_and_rooms/rooms/breadcrumb.html" %} +{% endblock breadcrumb %} + +{% block maincontent %} +<div> + <a href="{% url 'web.views.equipment_and_rooms.rooms_add' %}" class="btn btn-app"> + <i class="fa fa-plus"></i> + Add new room</a> +</div> + +<div class="box-body"> + {% if rooms_list %} + <table id="table" class="table table-bordered table-striped"> + <thead> + <tr> + <th>No.</th> + <th>City</th> + <th>Address</th> + <th>Owner</th> + <th>Details</th> + <th>Remove</th> + </tr> + </thead> + <tbody> + {% for room in rooms_list %} + <tr> + <td>{{ forloop.counter }}</td> + <td>{{ room.city }}</td> + <td>{{ room.address }}</td> + <td>{{ room.owner }}</td> + <td> + <a href="{% url 'web.views.equipment_and_rooms.rooms_edit' room.id %}" type="button" + class="btn btn-block btn-default">Details</a></td> + </td> + <td> + <a href="{% url 'web.views.equipment_and_rooms.rooms_delete' room.id %}" type="button" + class="btn btn-block btn-danger">Remove</a></td> + </td> + </tr> + {% endfor %} + + </tbody> + </table> + {% else %} + <p>No rooms found.</p> + {% endif %} +{% endblock maincontent %} diff --git a/smash/web/templates/sidebar.html b/smash/web/templates/sidebar.html index 05498fc5bf407bdd307a8e554214a598a5105953..c883860fe03c28ce4fd5019b08d88581ee77a5d4 100644 --- a/smash/web/templates/sidebar.html +++ b/smash/web/templates/sidebar.html @@ -38,8 +38,9 @@ </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> + <li><a href="{% url 'web.views.kit_requests' %}">Kit requests</a></li> + <li><a href="{% url 'web.views.equipment_and_rooms.rooms' %}">Rooms</a></li> </ul> </li> diff --git a/smash/web/urls.py b/smash/web/urls.py index c58aa7bb6a3cebcf9310718f5c7042e1ca58e02f..fef4fade6b489b361b01375df39038dc3889fe60 100644 --- a/smash/web/urls.py +++ b/smash/web/urls.py @@ -131,6 +131,10 @@ urlpatterns = [ 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'), + url(r'^equipment_and_rooms/rooms$', views.rooms.rooms, name='web.views.equipment_and_rooms.rooms'), + url(r'^equipment_and_rooms/rooms/add$', views.rooms.rooms_add, name='web.views.equipment_and_rooms.rooms_add'), + url(r'^equipment_and_rooms/rooms/edit/(?P<room_id>\d+)$', views.rooms.rooms_edit, name='web.views.equipment_and_rooms.rooms_edit'), + url(r'^equipment_and_rooms/rooms/delete/(?P<room_id>\d+)$', views.rooms.rooms_delete, name='web.views.equipment_and_rooms.rooms_delete'), #################### # MAIL # diff --git a/smash/web/views/__init__.py b/smash/web/views/__init__.py index fedbe5fd8b6300d36166e6e9ba058174553a0352..7870edac540b9a1ca976b73d5b59ffd7fdec8750 100644 --- a/smash/web/views/__init__.py +++ b/smash/web/views/__init__.py @@ -82,4 +82,5 @@ import voucher import voucher_type import voucher_type_price import redcap +import rooms import uploaded_files diff --git a/smash/web/views/rooms.py b/smash/web/views/rooms.py new file mode 100644 index 0000000000000000000000000000000000000000..0d14fafba044d0c1e4ff7f7bee0c1a12f9319a75 --- /dev/null +++ b/smash/web/views/rooms.py @@ -0,0 +1,49 @@ +# coding=utf-8 +from django.shortcuts import redirect, get_object_or_404 + +from . import wrap_response +from ..models import Room +from ..forms.forms import RoomForm + + +def rooms(request): + rooms_list = Room.objects.order_by('-city') + context = { + 'rooms_list': rooms_list + } + + return wrap_response(request, + "equipment_and_rooms/rooms/index.html", + context) + + +def rooms_add(request): + if request.method == 'POST': + form = RoomForm(request.POST) + if form.is_valid(): + form.save() + return redirect('web.views.equipment_and_rooms.rooms') + else: + form = RoomForm() + + return wrap_response(request, 'equipment_and_rooms/rooms/add.html', {'form': form}) + + +def rooms_edit(request, room_id): + the_room = get_object_or_404(Room, id=room_id) + if request.method == 'POST': + form = RoomForm(request.POST, instance=the_room) + if form.is_valid(): + form.save() + return redirect('web.views.equipment_and_rooms.rooms') + else: + form = RoomForm(instance=the_room) + + return wrap_response(request, 'equipment_and_rooms/rooms/edit.html', {'form': form}) + + +def rooms_delete(request, room_id): + the_room = get_object_or_404(Room, id=room_id) + the_room.delete() + + return redirect('web.views.equipment_and_rooms.rooms')