diff --git a/oim_cms/test_api.py b/oim_cms/test_api.py index 9d8f729..5a9b2ad 100644 --- a/oim_cms/test_api.py +++ b/oim_cms/test_api.py @@ -33,13 +33,13 @@ def setUp(self): self.loc2 = mixer.blend(Location, manager=None) # Generate a basic org structure. # NOTE: don't use mixer to create OrgUnit objects (it breaks MPTT). - self.dept = OrgUnit.objects.create(name='Department 1', unit_type=0) + self.dept = OrgUnit.objects.create(name='Department 1', unit_type=0, acronym='DEPT') self.div1 = OrgUnit.objects.create( - name='Divison 1', unit_type=1, parent=self.dept, location=self.loc1) + name='Divison 1', unit_type=1, parent=self.dept, location=self.loc1, acronym='D1') self.cc1 = CostCentre.objects.create( name='Cost centre 1', code='001', division=self.div1, org_position=self.div1) self.div2 = OrgUnit.objects.create( - name='Divison 2', unit_type=1, parent=self.dept, location=self.loc2) + name='Divison 2', unit_type=1, parent=self.dept, location=self.loc2, acronym='D2') self.cc2 = CostCentre.objects.create( name='Cost centre 2', code='002', division=self.div2, org_position=self.div2) # Give each of the divisions some members. @@ -274,9 +274,16 @@ def test_list_filtering(self): self.assertNotContains(response, self.user2.email) def test_detail(self): + """Test the DepartmentUserResource detail response + """ + # Test detail URL using ad_guid. url = '/api/users/{}/'.format(self.user1.ad_guid) response = self.client.get(url) self.assertEqual(response.status_code, 200) + # Test URL using email also. + url = '/api/users/{}/'.format(self.user1.email.lower()) + response = self.client.get(url) + self.assertEqual(response.status_code, 200) def test_org_structure(self): """Test the DepartmentUserResource org_structure response diff --git a/organisation/admin.py b/organisation/admin.py index 8312c99..4cfcbbd 100644 --- a/organisation/admin.py +++ b/organisation/admin.py @@ -10,6 +10,7 @@ from django.utils.html import format_html from django_mptt_admin.admin import DjangoMpttAdmin from leaflet.admin import LeafletGeoAdmin +from reversion.admin import VersionAdmin from threading import Thread import time @@ -41,7 +42,9 @@ def clean_employee_id(self): @register(DepartmentUser) -class DepartmentUserAdmin(ModelAdmin): +class DepartmentUserAdmin(VersionAdmin): + # Override the default reversion/change_list.html template: + change_list_template = 'admin/organisation/departmentuser/change_list.html' form = DepartmentUserForm list_display = [ 'email', 'title', 'employee_id', 'username', 'active', 'vip', 'executive', @@ -243,7 +246,7 @@ class CostCentreAdmin(ModelAdmin): search_fields = ( 'name', 'code', 'chart_acct_name', 'org_position__name', 'division__name', 'org_position__acronym', 'division__acronym') - list_filter = ('active',) + list_filter = ('active', 'chart_acct_name') raw_id_fields = ( 'org_position', 'manager', 'business_manager', 'admin', 'tech_contact') diff --git a/organisation/api.py b/organisation/api.py index 39f374e..7ecd2c2 100644 --- a/organisation/api.py +++ b/organisation/api.py @@ -161,7 +161,7 @@ def list(self): # No other filtering: # Return 'active' DU objects, excluding predefined account types and contractors. FILTERS = DepartmentUser.ACTIVE_FILTER.copy() - users = DepartmentUser.objects.filter(**FILTERS).exclude(account_type__in=[4, 5, 9, 10, 11, 12, 14, 15, 16]) + users = DepartmentUser.objects.filter(**FILTERS).exclude(account_type__in=[4, 5, 9, 10, 11, 12, 14, 16]) users = users.exclude(expiry_date__lte=timezone.now()) # Non-mutually-exclusive filters: if 'o365_licence' in self.request.GET: @@ -292,7 +292,7 @@ def org_structure(self, sync_o365=False, exclude_populate_groups=False): """ qs = DepartmentUser.objects.filter(**DepartmentUser.ACTIVE_FILTER) # Exclude predefined account types: - qs = qs.exclude(account_type__in=[4, 5, 9, 10, 11, 12, 14, 15, 16]) + qs = qs.exclude(account_type__in=[4, 5, 9, 10, 11, 12, 14, 16]) if exclude_populate_groups: # Exclude objects where populate_primary_group == False qs = qs.exclude(populate_primary_group=False) structure = [] diff --git a/organisation/models.py b/organisation/models.py index c179d99..ed16084 100644 --- a/organisation/models.py +++ b/organisation/models.py @@ -479,7 +479,7 @@ def __str__(self): if self.acronym: name = '{} - {}'.format(self.acronym, name) if self.cc(): - return '{} - CC{}'.format(name, self.cc()) + return '{} - CC {}'.format(name, self.cc()) return name def members(self): diff --git a/organisation/templates/admin/organisation/departmentuser/change_list.html b/organisation/templates/admin/organisation/departmentuser/change_list.html index 92bd89c..515297e 100644 --- a/organisation/templates/admin/organisation/departmentuser/change_list.html +++ b/organisation/templates/admin/organisation/departmentuser/change_list.html @@ -1,4 +1,4 @@ -{% extends "admin/change_list.html" %} +{% extends "reversion/change_list.html" %} {% block object-tools-items %}
  • diff --git a/requirements.txt b/requirements.txt index 8623134..a3a9b26 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,14 +1,14 @@ Django==1.10.7 -django-extensions==1.7.9 +django-extensions==1.8.1 django-uwsgi==0.1.6 git+https://github.com/parksandwildlife/dpaw-utils.git@0.3a16#egg=dpaw-utils -wagtail==1.10.1 +wagtail==1.11.1 wagtailtinymce==4.2.1.5 django-queryset-csv==1.0.0 django-mptt==0.8.7 -django-mptt-admin==0.4.4 +django-mptt-admin==0.4.6 django-leaflet==0.21.0 -django-reversion==2.0.8 +django-reversion==2.0.9 python-dateutil==2.4.2 django-model-utils==2.5 django-debug-toolbar==1.7