Package: django-authorities
An application for managing your organization’s authorities (departments, directorates etc). This is an app built to mainly cover the needs of the organization I work for (a public sector organization in Greece); however feel free to use it if you like it.RationaleThis more or less is abetterauth.Groupto help you building the hierarchy of an organization. Why not just useauth.Group? Well, unfortunately,auth.Groupis missing various needed things like:category: You may have departments, teams, directoratatesactive: Some authorities are de-activated; they should not be deleted thoughparent: You’ll need to have a proper authority hierarchyemail: Some authorities have their own email for contactAlso, for me the djangoauth.Groupentity feels more like an application/system-related concept (vs the HR Authority provided in this add-on). I.e you can have a django auth group of “Administrators” or “Advanced users” or “Moderators” etc; these people may belong to various directorates; not all people in the “IT department” need to be Administrators of the application.Now, there aremorethings that may be useful for an authority/HR system, likemanager: Who manages the authorityuser-job: The users of an authority may have different jobs like manager (this is complementary to the first one), teller, client development etcI haven’t added these fields yet because I don’t need them for my projects. If the need arises I’ll add them.InstallationInstall it withpip installdjango-authorities, or if you want to use the latest version on github, trypip installgit+https://github.com/spapas/django-authorities.After it is installed, putauthoritiesin yourINSTALLED_APPSsetting.Simple usageThis is a very simple app with two models and a couple of views for editing these.After you’ve installed it, you can visit the django admin to editauthorities.Authorityandauthorities.AuthorityKind.AuthorityKindonly has a name (so it can be directorate, department
team etc) whileAuthorityhaskind(AuthorityKind),is_active(boolean),parent(an optional FK to anotherAuthorityto create hierarchies) andusers(an M2M relation withsettings.AUTH_USER_MODEL; each user can belong to multiple authorities and each authority will
have more than one user).Also I’ve included a couple of non-admin views which you can use
as they are or modify them to fit your needs. Either inherit from or and them in your own urls.py as they are orincludethe
wholeauthorities.urls. The templates of these views inherit from abase.htmlwhich needs
to provide acontentand a{% page_title %}block. Thus yourbase.htmltemplate could be like this:<html>
    <body>
        <h1>{% block page_title %}{% endblock %}</h1>
        {% block content %}{% endblock %}
    </body>
</html>These views are:authorities.views.AuthorityListViewauthorities.views.AuthorityCreateViewauthorities.views.AuthorityUpdateViewauthorities.views.AuthorityDetailViewauthorities.views.AuthorityEditUsersViewThe names are self-explanatory; notice that the Create and Update views do not allow you to edit the users of that authority; you must use theAuthorityEditUsersViewfor that.You can either use these views in your urls.py or just add something likepath("authorities/",include("authorities.urls")),in your urls.py.To improve security a bit I’m checking that a user has the proper permission for authority in the app’s urls.py before allowing access to these views, i.eauthorities.view_authorityfor list and view,authorities.add_authorityfor add andauthorities.change_authorityfor edit and edit users.To use the provided template tag, you need to{% load authorities_tags %}and then you can do something
like this in your template:{% if user.is_authenticated %}
    {% user_authorities as my_authorities %}
    {% if my_authorities %}
        My authorities are:
        <ul>
        {% for a in my_authorities  %}
            <li>{{ a.name }}</li>
        {% endfor %}
        </ul>
    {% endif %}
{% endif %}ConfigurationThe follow options are supported:AUTHORITY_STR_FUNCTION: You can use this option to set a function that will be used instead of the default__str__function of theAuthoritymodelAUTHORITY_KIND_STR_FUNCTION: You can use this option to set a function that will be used instead of the default__str__of theAuthorityKindBoth functions will take the object as a parameter. For example define a function namedauthority_strin yourproject.core.utilsmodule like this:def authority_str(au):
    return '{0} {1}'.format(au.name, au.email)And then in your settings.py add:AUTHORITY_STR_FUNCTION = project.core.utils.authority_strChangelogv.0.4.2Make unique per name/kind idv.0.4.1Make it compatible with Django 4.xv.0.4.0Support configurable__str__methods forAuthorityandAuthorityKindv.0.3.3Add a defaultdefault_auto_fieldto apps.pyv.0.3.2Small fix to work with newer Django versionsv.0.3.1Add email to formsv.0.3.0Add optional email field toAuthorityv.0.2.3Improve permissionsv.0.2.2Fix MANIFEST.in to include locale filesv.0.2.1Add a missing migrationv.0.2.0Add greek translationsImprove standard views a bitAdd some security to the builtin viewsv.0.1.2Add template tags to get current user authoritiesImprove READMEv.0.1.0Initial version