diff --git a/smash/web/templates/doctors/add.html b/smash/web/templates/doctors/add.html index eb17a92775c2ae3206b8545d674c9b2614361274..45259a6242701e7754fcf98eea71b6609fa3da19 100644 --- a/smash/web/templates/doctors/add.html +++ b/smash/web/templates/doctors/add.html @@ -22,7 +22,7 @@ {% block content %} <div class="box box-info"> <div class="box-header with-border"> - <a href="{% url 'web.views.doctors' %}" class="btn btn-block btn-default">Go back (without changes)</a> + <a href="{% url 'web.views.workers' %}" class="btn btn-block btn-default">Go back (without changes)</a> </div> <form method="post" action="" class="form-horizontal"> @@ -55,7 +55,7 @@ <button type="submit" class="btn btn-block btn-success">Add</button> </div> <div class="col-sm-6"> - <a href="{% url 'web.views.doctors' %}" class="btn btn-block btn-default">Cancel</a> + <a href="{% url 'web.views.workers' %}" class="btn btn-block btn-default">Cancel</a> </div> </div><!-- /.box-footer --> </form> diff --git a/smash/web/templates/doctors/add_availability.html b/smash/web/templates/doctors/add_availability.html index 3277b6f0db6c2f21bf7216cbaaff85a5cc5089e6..de6dce582dd2ea09ae2faf06b1d29bf4c21d0e03 100644 --- a/smash/web/templates/doctors/add_availability.html +++ b/smash/web/templates/doctors/add_availability.html @@ -22,7 +22,7 @@ {% block content %} <div class="box box-info"> <div class="box-header with-border"> - <a href="{% url 'web.views.doctor_edit' doctor_id %}" class="btn btn-block btn-default">Go back (without + <a href="{% url 'web.views.worker_edit' doctor_id %}" class="btn btn-block btn-default">Go back (without changes)</a> </div> @@ -56,7 +56,7 @@ <button type="submit" class="btn btn-block btn-success">Add</button> </div> <div class="col-sm-6"> - <a href="{% url 'web.views.doctor_edit' doctor_id %}" + <a href="{% url 'web.views.worker_edit' doctor_id %}" class="btn btn-block btn-default">Cancel</a> </div> </div><!-- /.box-footer --> diff --git a/smash/web/templates/doctors/add_holiday.html b/smash/web/templates/doctors/add_holiday.html index 797bab7d47ad70f20606fd0c71805e53f6e2e0b5..59e2975087f29fa7adf00f386bf03623c09966f5 100644 --- a/smash/web/templates/doctors/add_holiday.html +++ b/smash/web/templates/doctors/add_holiday.html @@ -23,7 +23,7 @@ {% block content %} <div class="box box-info"> <div class="box-header with-border"> - <a href="{% url 'web.views.doctor_edit' doctor_id %}" class="btn btn-block btn-default">Go back (without + <a href="{% url 'web.views.worker_edit' doctor_id %}" class="btn btn-block btn-default">Go back (without changes)</a> </div> @@ -57,7 +57,7 @@ <button type="submit" class="btn btn-block btn-success">Add</button> </div> <div class="col-sm-6"> - <a href="{% url 'web.views.doctor_edit' doctor_id %}" + <a href="{% url 'web.views.worker_edit' doctor_id %}" class="btn btn-block btn-default">Cancel</a> </div> </div><!-- /.box-footer --> diff --git a/smash/web/templates/doctors/breadcrumb.html b/smash/web/templates/doctors/breadcrumb.html index 76b5b72095b33b9a7c470f19bb7568d72b7df9b4..6d111dd545adc0d422fe4dfae996671af3c8f657 100644 --- a/smash/web/templates/doctors/breadcrumb.html +++ b/smash/web/templates/doctors/breadcrumb.html @@ -1,2 +1,2 @@ <li><a href="{% url 'web.views.appointments' %}"><i class="fa fa-dashboard"></i> Dashboard</a></li> -<li class="active"><a href="{% url 'web.views.doctors' %}">Workers</a></li> \ No newline at end of file +<li class="active"><a href="{% url 'web.views.workers' %}">Workers</a></li> \ No newline at end of file diff --git a/smash/web/templates/doctors/edit.html b/smash/web/templates/doctors/edit.html index e41beaed77e99201e1f6fcbb5c865c13a0f83812..bd5378b9f54ce7aaa81eb15e894246673ec1750c 100644 --- a/smash/web/templates/doctors/edit.html +++ b/smash/web/templates/doctors/edit.html @@ -23,7 +23,7 @@ {% block content %} <div class="box box-info"> <div class="box-header with-border"> - <a href="{% url 'web.views.doctors' %}" class="btn btn-block btn-default" onclick="history.back()">Go + <a href="{% url 'web.views.workers' %}" class="btn btn-block btn-default" onclick="history.back()">Go back (without changes)</a> </div> @@ -55,7 +55,7 @@ <button type="submit" class="btn btn-block btn-success">Save</button> </div> <div class="col-sm-6"> - <a href="{% url 'web.views.doctors' %}" class="btn btn-block btn-default" + <a href="{% url 'web.views.workers' %}" class="btn btn-block btn-default" onclick="history.back()">Cancel</a> </div> </div><!-- /.box-footer --> @@ -90,11 +90,11 @@ <td>{{ availability.available_from }}</td> <td>{{ availability.available_till }}</td> <td> - <a href="{% url 'web.views.doctor_availability_edit' availability.id %}" type="button" + <a href="{% url 'web.views.worker_availability_edit' availability.id %}" type="button" class="btn btn-block btn-default">Edit</a> </td> <td> - <a href="{% url 'web.views.doctor_availability_delete' availability.id %}" type="button" + <a href="{% url 'web.views.worker_availability_delete' availability.id %}" type="button" class="btn btn-block btn-default">Delete</a> </td> </tr> @@ -105,7 +105,7 @@ <div class="box-footer"> <div class="col-sm-6"> - <a href="{% url 'views.doctor.doctor_availability_add' doctor_id %}" type="button" + <a href="{% url 'web.views.worker_availability_add' doctor_id %}" type="button" class="btn btn-block btn-success">Add availability</a> </div> </div><!-- /.box-footer --> @@ -143,7 +143,7 @@ <div class="box-footer"> <div class="col-sm-6"> - <a href="{% url 'views.doctor.doctor_holiday_add' doctor_id %}" type="button" + <a href="{% url 'web.views.worker_holiday_add' doctor_id %}" type="button" class="btn btn-block btn-success">Add holiday</a> </div> </div><!-- /.box-footer --> diff --git a/smash/web/templates/doctors/edit_availability.html b/smash/web/templates/doctors/edit_availability.html index 37de10ae4cc064b45b0173ef53d7a80e43296227..4daf5fffd8475f40a0908e700dfb717547c36a24 100644 --- a/smash/web/templates/doctors/edit_availability.html +++ b/smash/web/templates/doctors/edit_availability.html @@ -23,7 +23,7 @@ {% block content %} <div class="box box-info"> <div class="box-header with-border"> - <a href="{% url 'web.views.doctor_edit' doctor_id %}" class="btn btn-block btn-default">Go back (without + <a href="{% url 'web.views.worker_edit' doctor_id %}" class="btn btn-block btn-default">Go back (without changes)</a> </div> @@ -57,7 +57,7 @@ <button type="submit" class="btn btn-block btn-success">Save</button> </div> <div class="col-sm-6"> - <a href="{% url 'web.views.doctor_edit' doctor_id %}" + <a href="{% url 'web.views.worker_edit' doctor_id %}" class="btn btn-block btn-default">Cancel</a> </div> </div><!-- /.box-footer --> diff --git a/smash/web/templates/doctors/index.html b/smash/web/templates/doctors/index.html index 4dc34ec01d556867dd728b5f51d553f360eceb0c..695da0bcf94b689e2a483d1c94158841f40fd960 100644 --- a/smash/web/templates/doctors/index.html +++ b/smash/web/templates/doctors/index.html @@ -18,7 +18,7 @@ {% block maincontent %} <div> - <a href="{% url 'web.views.doctor_add' %}" class="btn btn-app"> + <a href="{% url 'web.views.worker_add' %}" class="btn btn-app"> <i class="fa fa-plus"></i> Add new worker</a> </div> @@ -52,7 +52,7 @@ {% endautoescape %} </td> <td>{{ worker.unit }}</td> - <td><a href="{% url 'web.views.doctor_edit' worker.id %}" type="button" + <td><a href="{% url 'web.views.worker_edit' worker.id %}" type="button" class="btn btn-block btn-default">Details</a></td> <td> {% if worker.is_on_leave %} @@ -63,7 +63,7 @@ </td> <td> {% if worker.is_active %} - <a href="{% url 'web.views.doctor_disable' worker.id %}" class="btn btn-block btn-warning">DISABLE</a> + <a href="{% url 'web.views.worker_disable' worker.id %}" class="btn btn-block btn-warning">DISABLE</a> {% else %} YES {% endif %} diff --git a/smash/web/templates/sidebar.html b/smash/web/templates/sidebar.html index 71c325a1cc768df50f5898b59b8e3e1b1aeefa6a..fbd7fdb050e6fef8ca8b8f3019d38a4ce827067e 100644 --- a/smash/web/templates/sidebar.html +++ b/smash/web/templates/sidebar.html @@ -24,7 +24,7 @@ </li> <li data-desc="workers"> - <a href="{% url 'web.views.doctors' %}"> + <a href="{% url 'web.views.workers' %}"> <i class="fa fa-user-md"></i> <span>Workers</span> </a> diff --git a/smash/web/tests/view/test_doctor.py b/smash/web/tests/view/test_doctor.py index 16da568bf22a0fd61f9dd7297ba049b774339057..8c6dccdbdb26beea505462aaba321b0fdda4d754 100644 --- a/smash/web/tests/view/test_doctor.py +++ b/smash/web/tests/view/test_doctor.py @@ -15,13 +15,13 @@ class DoctorViewTests(LoggedInTestCase): def test_render_workers_list_request(self): create_worker() - response = self.client.get(reverse('web.views.doctors')) + response = self.client.get(reverse('web.views.workers')) self.assertEqual(response.status_code, 200) def test_render_add_worker_request(self): create_worker() - response = self.client.get(reverse('web.views.doctor_add')) + response = self.client.get(reverse('web.views.worker_add')) self.assertEqual(response.status_code, 200) def test_render_worker_added_request(self): @@ -44,7 +44,7 @@ class DoctorViewTests(LoggedInTestCase): form_data["languages"] = [language.id] form_data["locations"] = [location.id] - response = self.client.post(reverse('web.views.doctor_add'), data=form_data) + response = self.client.post(reverse('web.views.worker_add'), data=form_data) self.assertEqual(response.status_code, 302) @@ -54,24 +54,24 @@ class DoctorViewTests(LoggedInTestCase): def test_render_edit_worker_request(self): worker = create_worker() - response = self.client.get(reverse('web.views.doctor_edit', args=[worker.id])) + response = self.client.get(reverse('web.views.worker_edit', args=[worker.id])) self.assertEqual(response.status_code, 200) def test_render_add_availability_request(self): worker = create_worker() - response = self.client.get(reverse('views.doctor.doctor_availability_add', args=[worker.id])) + response = self.client.get(reverse('web.views.worker_availability_add', args=[worker.id])) self.assertEqual(response.status_code, 200) def test_render_edit_availability_request(self): worker = create_worker() availability = create_availability(worker) - response = self.client.get(reverse('web.views.doctor_availability_edit', args=[availability.id])) + response = self.client.get(reverse('web.views.worker_availability_edit', args=[availability.id])) self.assertEqual(response.status_code, 200) def test_render_add_holiday_request(self): worker = create_worker() - response = self.client.get(reverse('views.doctor.doctor_holiday_add', args=[worker.id])) + response = self.client.get(reverse('web.views.worker_holiday_add', args=[worker.id])) self.assertEqual(response.status_code, 200) diff --git a/smash/web/urls.py b/smash/web/urls.py index 567ef50b4e736c0d4b80d319f9592ef508be8b66..6fedc075ee9e54ef1ee94438eefb1ae8eba835da 100644 --- a/smash/web/urls.py +++ b/smash/web/urls.py @@ -99,23 +99,23 @@ urlpatterns = [ # DOCTORS # #################### - url(r'^doctors$', views.doctor.doctors, name='web.views.doctors'), - url(r'^doctors/add$', views.doctor.doctor_add, name='web.views.doctor_add'), - url(r'^doctors/edit/(?P<doctor_id>\d+)$', views.doctor.doctor_edit, name='web.views.doctor_edit'), - url(r'^doctors/disable/(?P<doctor_id>\d+)$', views.doctor.doctor_disable, name='web.views.doctor_disable'), - url(r'^doctors/(?P<doctor_id>\d+)/availability/add$', views.doctor.doctor_availability_add, - name='views.doctor.doctor_availability_add'), - - url(r'^doctors/availability/(?P<availability_id>\d+)/delete$', views.doctor.doctor_availability_delete, - name='web.views.doctor_availability_delete'), - url(r'^doctors/availability/(?P<availability_id>\d+)/edit', views.doctor.doctor_availability_edit, - name='web.views.doctor_availability_edit'), - - url(r'^doctors/(?P<doctor_id>\d+)/holiday/add$', views.doctor.doctor_holiday_add, - name='views.doctor.doctor_holiday_add'), - - url(r'^doctors/holiday/(?P<holiday_id>\d+)/delete$', views.doctor.doctor_holiday_delete, - name='web.views.doctor_holiday_delete'), + url(r'^doctors$', views.worker.worker_list, name='web.views.workers'), + url(r'^doctors/add$', views.worker.worker_add, name='web.views.worker_add'), + url(r'^doctors/edit/(?P<doctor_id>\d+)$', views.worker.worker_edit, name='web.views.worker_edit'), + url(r'^doctors/disable/(?P<doctor_id>\d+)$', views.worker.doctor_disable, name='web.views.worker_disable'), + + url(r'^doctors/(?P<doctor_id>\d+)/availability/add$', views.worker.worker_availability_add, + name='web.views.worker_availability_add'), + url(r'^doctors/availability/(?P<availability_id>\d+)/delete$', views.worker.worker_availability_delete, + name='web.views.worker_availability_delete'), + url(r'^doctors/availability/(?P<availability_id>\d+)/edit', views.worker.worker_availability_edit, + name='web.views.worker_availability_edit'), + + url(r'^doctors/(?P<doctor_id>\d+)/holiday/add$', views.worker.worker_holiday_add, + name='web.views.worker_holiday_add'), + + url(r'^doctors/holiday/(?P<holiday_id>\d+)/delete$', views.worker.worker_holiday_delete, + name='web.views.worker_holiday_delete'), #################### # EQUIPMENT # diff --git a/smash/web/views/__init__.py b/smash/web/views/__init__.py index 296d4e9fdd25fb4324344099abd639f0621246a0..9dc10050a57825b5c69c6af3980c0d6cb823515b 100644 --- a/smash/web/views/__init__.py +++ b/smash/web/views/__init__.py @@ -67,7 +67,7 @@ class WrappedView(ContextMixin): import auth import appointment import visit -import doctor +import worker import subject import equipment import kit diff --git a/smash/web/views/doctor.py b/smash/web/views/worker.py similarity index 78% rename from smash/web/views/doctor.py rename to smash/web/views/worker.py index d6738333ac2225cebac3be65db76e3e85448a403..78e50a857d945f33cdb0227106bd014d8ea90e1f 100644 --- a/smash/web/views/doctor.py +++ b/smash/web/views/worker.py @@ -1,4 +1,5 @@ # coding=utf-8 +from django.contrib.auth.decorators import login_required from django.shortcuts import redirect, get_object_or_404 from . import wrap_response @@ -7,7 +8,7 @@ from ..models import Worker, Availability, Holiday from ..models.constants import WEEKDAY_CHOICES -def doctors(request): +def worker_list(request): doctors_list = Worker.objects.order_by('-last_name') context = { 'doctors_list': doctors_list @@ -16,25 +17,25 @@ def doctors(request): return wrap_response(request, "doctors/index.html", context) -def doctor_add(request): +def worker_add(request): if request.method == 'POST': form = WorkerAddForm(request.POST, request.FILES) if form.is_valid(): form.save() - return redirect('web.views.doctors') + return redirect('web.views.workers') else: form = WorkerAddForm() return wrap_response(request, 'doctors/add.html', {'form': form}) -def doctor_edit(request, doctor_id): +def worker_edit(request, doctor_id): the_doctor = get_object_or_404(Worker, id=doctor_id) if request.method == 'POST': form = WorkerEditForm(request.POST, request.FILES, instance=the_doctor) if form.is_valid(): form.save() - return redirect('web.views.doctors') + return redirect('web.views.workers') else: form = WorkerEditForm(instance=the_doctor) availabilities = Availability.objects.filter(person=doctor_id).order_by('day_number', 'available_from') @@ -52,28 +53,26 @@ def doctor_edit(request, doctor_id): def doctor_disable(request, doctor_id): the_doctor = get_object_or_404(Worker, id=doctor_id) the_doctor.disable() - return doctors(request) + return worker_list(request) -def doctor_availability_delete(request, availability_id): +@login_required +def worker_availability_delete(request, availability_id): availability = Availability.objects.filter(id=availability_id) doctor_id = availability[0].person.id availability.delete() - return redirect(doctor_edit, doctor_id=doctor_id) + return redirect(worker_edit, doctor_id=doctor_id) -def doctor_availability_add(request, doctor_id): - doctors = Worker.objects.filter(id=doctor_id) - doctor = None - if len(doctors) > 0: - doctor = doctors[0] +def worker_availability_add(request, doctor_id): + worker = get_object_or_404(Worker, id=doctor_id) if request.method == 'POST': form = AvailabilityAddForm(request.POST, request.FILES) if form.is_valid(): form.save() - return redirect(doctor_edit, doctor_id=doctor_id) + return redirect(worker_edit, doctor_id=doctor_id) else: - form = AvailabilityAddForm(initial={'person': doctor}) + form = AvailabilityAddForm(initial={'person': worker}) return wrap_response(request, 'doctors/add_availability.html', { 'form': form, @@ -81,13 +80,13 @@ def doctor_availability_add(request, doctor_id): }) -def doctor_availability_edit(request, availability_id): +def worker_availability_edit(request, availability_id): availability = get_object_or_404(Availability, id=availability_id) if request.method == 'POST': form = AvailabilityEditForm(request.POST, request.FILES, instance=availability) if form.is_valid(): form.save() - return redirect(doctor_edit, doctor_id=availability.person_id) + return redirect(worker_edit, doctor_id=availability.person_id) else: form = AvailabilityEditForm(instance=availability) return wrap_response(request, 'doctors/edit_availability.html', @@ -98,14 +97,15 @@ def doctor_availability_edit(request, availability_id): }) -def doctor_holiday_delete(request, holiday_id): +@login_required +def worker_holiday_delete(request, holiday_id): holiday = Holiday.objects.filter(id=holiday_id) doctor_id = holiday[0].person.id holiday.delete() - return redirect(doctor_edit, doctor_id=doctor_id) + return redirect(worker_edit, doctor_id=doctor_id) -def doctor_holiday_add(request, doctor_id): +def worker_holiday_add(request, doctor_id): doctors = Worker.objects.filter(id=doctor_id) doctor = None if len(doctors) > 0: @@ -114,7 +114,7 @@ def doctor_holiday_add(request, doctor_id): form = HolidayAddForm(request.POST, request.FILES) if form.is_valid(): form.save() - return redirect(doctor_edit, doctor_id=doctor_id) + return redirect(worker_edit, doctor_id=doctor_id) else: form = HolidayAddForm(initial={'person': doctor}) return wrap_response(request, 'doctors/add_holiday.html',