diff --git a/profiles/admin.py b/profiles/admin.py index b69742b87d7e6174d4a7611e4b068605d1eda9be..7927dd270867e964778dfbcc3fce11557d8c2e90 100644 --- a/profiles/admin.py +++ b/profiles/admin.py @@ -7,6 +7,6 @@ from . import models admin.site.register(models.User, UserAdmin) -@admin.register(models.Institution) -class InstitutionAdmin(admin.ModelAdmin): +@admin.register(models.OrganisationalUnit) +class OrganisationalUnitAdmin(admin.ModelAdmin): pass diff --git a/profiles/migrations/0003_rename_institution.py b/profiles/migrations/0003_rename_institution.py new file mode 100644 index 0000000000000000000000000000000000000000..553b09479ec8dacb2169a67cd8ea88d0418705f6 --- /dev/null +++ b/profiles/migrations/0003_rename_institution.py @@ -0,0 +1,22 @@ +# Generated by Django 2.0.8 on 2018-11-15 09:45 + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('profiles', '0002_add_institution'), + ] + + operations = [ + migrations.RenameModel( + old_name='Institution', + new_name='OrganisationalUnit', + ), + migrations.RenameField( + model_name='user', + old_name='institution', + new_name='organisational_unit', + ), + ] diff --git a/profiles/models.py b/profiles/models.py index aced23b56d2a7ec7ccbf02b72adab593fab25cca..ae98a7aa7f5701ff8aa8709df368020e8b97dafa 100644 --- a/profiles/models.py +++ b/profiles/models.py @@ -7,12 +7,12 @@ from django.urls import reverse from core.models import MAX_LENGTH_NAME -class Institution(models.Model): +class OrganisationalUnit(models.Model): """ - Model representing the institution with which a user is associated. + Model representing the organisational unit with which a user is associated. """ @enum.unique - class InstitutionType(enum.Enum): + class OrganisationalUnitType(enum.Enum): ACADEMIC = 'aca' BUSINESS = 'bus' CHARITY = 'cha' @@ -23,18 +23,24 @@ class Institution(models.Model): def choices(cls): return tuple((i.value, i.name.title()) for i in cls) - #: Name of the institution + #: Name of the organisational unit name = models.CharField(max_length=MAX_LENGTH_NAME, blank=False, null=False) - #: Type of institution - e.g. academic, business, etc. + #: Type of organisational_unit - e.g. academic, business, etc. type = models.CharField(max_length=3, - choices=InstitutionType.choices(), + choices=OrganisationalUnitType.choices(), blank=False, null=False) + @property + def all_auditors(self): + return self.auditors.union( + User.objects.filter(is_superauditor=True) + ) + @property def auditors(self): - return self.users.filter(is_auditor=True) + User.objects.filter(is_superauditor=True) + return self.users.filter(is_auditor=True) def __str__(self): return self.name @@ -44,12 +50,12 @@ class User(AbstractUser): """ Model representing a user of PEDASI. """ - #: Institution to which this user belongs - institution = models.ForeignKey(Institution, related_name='users', - on_delete=models.SET_NULL, - blank=True, null=True) + #: Organisational unit to which this user belongs + organisational_unit = models.ForeignKey(OrganisationalUnit, related_name='users', + on_delete=models.SET_NULL, + blank=True, null=True) - #: Is this user an auditor of their institution? + #: Is this user an auditor of their organisational unit? is_auditor = models.BooleanField(default=False, blank=False, null=False) diff --git a/profiles/templates/profiles/institution/detail.html b/profiles/templates/profiles/institution/detail.html deleted file mode 100644 index ebcb60c45b9ab8032d09fcefda53ff7b38b0b7f1..0000000000000000000000000000000000000000 --- a/profiles/templates/profiles/institution/detail.html +++ /dev/null @@ -1,21 +0,0 @@ -{% extends "base.html" %} -{% load bootstrap4 %} - -{% block content %} - <nav aria-label="breadcrumb"> - <ol class="breadcrumb"> - <li class="breadcrumb-item" aria-current="page"> - <a href="{% url 'index' %}">Home</a> - </li> - <li class="breadcrumb-item" aria-current="page"> - Institutions - </li> - <li class="breadcrumb-item active" aria-current="page"> - {{ institution.name }} - </li> - </ol> - </nav> - - <h2>{{ institution.name }}</h2> - -{% endblock %} \ No newline at end of file diff --git a/profiles/templates/profiles/organisational_unit/detail.html b/profiles/templates/profiles/organisational_unit/detail.html new file mode 100644 index 0000000000000000000000000000000000000000..be5c251c5cdaafd31bf80bcfbd1027338a4b39a1 --- /dev/null +++ b/profiles/templates/profiles/organisational_unit/detail.html @@ -0,0 +1,39 @@ +{% extends "base.html" %} +{% load bootstrap4 %} + +{% block content %} + <nav aria-label="breadcrumb"> + <ol class="breadcrumb"> + <li class="breadcrumb-item" aria-current="page"> + <a href="{% url 'index' %}">Home</a> + </li> + <li class="breadcrumb-item" aria-current="page"> + Organisational Units + </li> + <li class="breadcrumb-item active" aria-current="page"> + {{ organisational_unit.name }} + </li> + </ol> + </nav> + + <h2>{{ organisational_unit.name }}</h2> + + <h4 class="pt-3">Auditors</h4> + + <table class="table"> + <thead> + <tr> + <th scope="col">Name</th> + </tr> + </thead> + + <tbody> + {% for auditor in organisational_unit.auditors.all %} + <tr> + <td>{{ auditor.get_full_name }}</td> + </tr> + {% endfor %} + </tbody> + </table> + +{% endblock %} \ No newline at end of file diff --git a/profiles/templates/profiles/user/profile.html b/profiles/templates/profiles/user/profile.html index f4e6e83c0f1380f7a47c74b2a2300ebee4b5ad86..7ff10e83ef7168d58f4f7ac386d2de62bab3f6c2 100644 --- a/profiles/templates/profiles/user/profile.html +++ b/profiles/templates/profiles/user/profile.html @@ -22,12 +22,12 @@ </thead> <tbody> - {% if request.user.institution %} + {% if request.user.organisational_unit %} <tr> - <td>Institution</td> + <td>Organisational Unit</td> <td> - {{ request.user.institution.name }} - <a href="{% url 'profiles:institution.detail' pk=request.user.institution_id %}" + {{ request.user.organisational_unit.name }} + <a href="{% url 'profiles:organisational_unit.detail' pk=request.user.organisational_unit_id %}" class="btn btn-info">Detail</a> </td> </tr> diff --git a/profiles/urls.py b/profiles/urls.py index d5bf9e9ed9863f6faf3ac06fe20ff27bdb751df1..c55df55822158162948e4172b874fa355c83fb1a 100644 --- a/profiles/urls.py +++ b/profiles/urls.py @@ -19,7 +19,7 @@ urlpatterns = [ views.user.UserUriView.as_view(), name='uri'), - path('institutions/<int:pk>', - views.institution.InstitutionDetailView.as_view(), - name='institution.detail'), + path('orgunit/<int:pk>', + views.organisational_unit.OrganisationalUnitDetailView.as_view(), + name='organisational_unit.detail'), ] diff --git a/profiles/views/__init__.py b/profiles/views/__init__.py index cd9a456e619dfd6d41664d8f44c6deb2f59f148b..e18dfd73f41426fb127ba7dfdbf888c762dd99e2 100644 --- a/profiles/views/__init__.py +++ b/profiles/views/__init__.py @@ -3,9 +3,9 @@ from django.views.generic import TemplateView from applications.models import Application from datasources.models import DataSource -from . import institution, user +from . import organisational_unit, user -__all__ = ['IndexView', 'institution', 'user'] +__all__ = ['IndexView', 'organisational_unit', 'user'] class IndexView(TemplateView): diff --git a/profiles/views/institution.py b/profiles/views/institution.py deleted file mode 100644 index c13b543416adde90f745881f1da81e6ed12453bf..0000000000000000000000000000000000000000 --- a/profiles/views/institution.py +++ /dev/null @@ -1,9 +0,0 @@ -from django.views.generic.detail import DetailView - -from profiles import models - - -class InstitutionDetailView(DetailView): - model = models.Institution - template_name = 'profiles/institution/detail.html' - context_object_name = 'institution' diff --git a/profiles/views/organisational_unit.py b/profiles/views/organisational_unit.py new file mode 100644 index 0000000000000000000000000000000000000000..fa42b513f99cf4fce3b4d202f9fa225aef36facc --- /dev/null +++ b/profiles/views/organisational_unit.py @@ -0,0 +1,9 @@ +from django.views.generic.detail import DetailView + +from profiles import models + + +class OrganisationalUnitDetailView(DetailView): + model = models.OrganisationalUnit + template_name = 'profiles/organisational_unit/detail.html' + context_object_name = 'organisational_unit'