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

possibility to disable account added

parent 56745e77
No related branches found
No related tags found
1 merge request!84Resolve "possibility to remove worker"
# coding=utf-8
import datetime
import logging
from django.contrib.auth.models import User, AnonymousUser
from django.db import models
logger = logging.getLogger(__name__)
class Worker(models.Model):
class Meta:
......@@ -59,6 +62,22 @@ class Worker(models.Model):
return True
return False
def disable(self):
if self.user is not None:
self.user.is_active = False
self.user.save()
logger.info("'" + self.user.username + "' account has been disabled")
return True
else:
logger.warn("Cannot disable account for user '" + self.first_name + " " + self.last_name + "'")
return False
def is_active(self):
if self.user is not None:
return self.user.is_active
else:
return False
@staticmethod
def get_by_user(the_user):
if isinstance(the_user, User):
......
......@@ -35,6 +35,7 @@
<th>Unit</th>
<th>Details</th>
<th>On leave</th>
<th>Disabled</th>
</tr>
</thead>
<tbody>
......@@ -60,6 +61,13 @@
<button type="button" class="btn btn-block btn-success">NO</button>
{% endif %}
</td>
<td>
{% if worker.is_active %}
<a href="{% url 'web.views.doctor_disable' worker.id %}" class="btn btn-block btn-warning">DISABLE</a>
{% else %}
YES
{% endif %}
</td>
</tr>
{% endfor %}
......
from django.contrib.auth.models import User
from django.test import Client
from django.test import TestCase
from functions import create_subject, create_appointment
from functions import create_visit
from web.tests.functions import create_subject, create_appointment, create_worker
from web.tests.functions import create_visit
from web.models import Appointment
from web.models import Visit
......@@ -31,4 +33,4 @@ class SubjectModelTests(TestCase):
self.assertTrue(subject.resigned)
self.assertTrue(visit_finished)
self.assertEquals(Appointment.APPOINTMENT_STATUS_CANCELLED, appointment_status)
self.assertEquals(Appointment.APPOINTMENT_STATUS_CANCELLED, appointment_status)
\ No newline at end of file
from django.contrib.auth.models import User
from django.test import Client
from django.test import TestCase
from web.tests.functions import create_worker
class WorkerModelTests(TestCase):
def test_disable(self):
client = Client()
username = 'piotr'
password = 'top_secret'
user = User.objects.create_user(username=username, email='jacob@bla', password=password)
worker = create_worker(user)
disable_status = worker.disable()
self.assertTrue(disable_status)
success = client.login(username=username, password=password)
self.assertFalse(success)
self.assertFalse(user.is_active)
self.assertFalse(worker.is_active())
def test_disable_invalid(self):
worker = create_worker()
disable_status = worker.disable()
self.assertFalse(disable_status)
def test_is_active_for_invalid(self):
worker = create_worker()
self.assertFalse(worker.is_active())
......@@ -100,6 +100,7 @@ urlpatterns = [
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'),
......
......@@ -49,6 +49,12 @@ 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)
def doctor_availability_delete(request, availability_id):
availability = Availability.objects.filter(id=availability_id)
doctor_id = availability[0].person.id
......
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