Skip to content
Snippets Groups Projects
Commit 2ad9a41a authored by Piotr Gawron's avatar Piotr Gawron
Browse files

Merge branch '150-possibility-to-remove-appointment' into 'master'

appointment can be removed, but only when not atached to visit and with SCHEDULED status

Closes #150

See merge request NCER-PD/scheduling-system!95
parents 1d923642 84678a1b
No related branches found
No related tags found
1 merge request!95appointment can be removed, but only when not atached to visit and with SCHEDULED status
Pipeline #
......@@ -89,18 +89,26 @@
</fieldset>
{% endif %}
<div class="box-footer">
<div class="col-sm-4">
<div class="col-sm-3">
<button type="submit" class="btn btn-block btn-success">Save</button>
</div>
<div class="col-sm-4">
<div class="col-sm-3">
<button id="save-and-continue" type="button" class="btn btn-block btn-success">Save and
Continue
</button>
</div>
<div class="col-sm-4">
<div class="col-sm-3">
<a href="{% url 'web.views.appointments' %}" class="btn btn-block btn-default"
onclick="history.back()">Cancel</a>
</div>
{% if not appointment.visit %}
{% ifequal appointment.status "SCHEDULED" %}
<div class="col-sm-3">
<a href="{% url 'web.views.appointment_delete' appointment.id %}"
class="btn btn-block btn-danger">Delete</a>
</div>
{% endifequal %}
{% endif %}
</div><!-- /.box-footer -->
</form>
</div>
......@@ -111,8 +119,6 @@
{% endblock %}
{% endblock maincontent %}
{% block scripts %}
......
......@@ -150,3 +150,19 @@ class AppointmentsViewTests(LoggedInTestCase):
updated_subject = Subject.objects.get(id=subject.id)
self.assertIsNotNone(updated_subject.flying_team)
def test_delete_appointment(self):
appointment = create_appointment()
appointment.visit = None
appointment.save()
self.client.post(reverse('web.views.appointment_delete', kwargs={'appointment_id': appointment.id}))
self.assertEqual(0, Appointment.objects.all().count())
def test_delete_invalid_appointment_with_visit(self):
appointment = create_appointment()
self.client.post(reverse('web.views.appointment_delete', kwargs={'appointment_id': appointment.id}))
self.assertEqual(1, Appointment.objects.all().count())
......@@ -45,6 +45,8 @@ urlpatterns = [
url(r'^appointments/add/(?P<visit_id>\d+)$', views.appointment.appointment_add, name='web.views.appointment_add'),
url(r'^appointments/add/general$', views.appointment.appointment_add, name='web.views.appointment_add_general'),
url(r'^appointments/edit/(?P<id>\d+)$', views.appointment.appointment_edit, name='web.views.appointment_edit'),
url(r'^appointments/delete/(?P<appointment_id>\d+)$', views.appointment.appointment_delete,
name='web.views.appointment_delete'),
####################
# VISITS #
......
# coding=utf-8
import logging
import re
from django.contrib import messages
from django.core.exceptions import ValidationError
from django.shortcuts import get_object_or_404, redirect
......@@ -125,3 +126,14 @@ def appointment_edit(request, id):
'contact_attempts': contact_attempts,
'mail_templates': MailTemplate.get_appointment_mail_templates(languages)
})
def appointment_delete(request, appointment_id):
appointment = get_object_or_404(Appointment, id=appointment_id)
if appointment.visit is not None or appointment.status != Appointment.APPOINTMENT_STATUS_SCHEDULED:
messages.error(request, "Appointment cannot be deleted")
return redirect('web.views.appointment_edit', id=appointment_id)
else:
appointment.delete()
messages.success(request, "Appointment deleted successfully")
return redirect('web.views.appointments')
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment