From 9c5d293aef57a2170cf733f31f39db6aa065a31e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=AD=C3=B0ir=20Valberg=20Gu=C3=B0mundsson?= Date: Tue, 5 Apr 2022 09:26:16 +0200 Subject: [PATCH] Add documentation for swappable forms. --- docs/configuration.rst | 39 +++++++++++++++++++++++++++++++++++++ invitations/app_settings.py | 11 +++++++++-- invitations/utils.py | 9 +++++++++ 3 files changed, 57 insertions(+), 2 deletions(-) diff --git a/docs/configuration.rst b/docs/configuration.rst index 221c639..8f610ca 100644 --- a/docs/configuration.rst +++ b/docs/configuration.rst @@ -157,6 +157,45 @@ App registry path of the invitation model used in the current project, for custo ---- +INVITE_FORM +*********** + +Setting name: ``INVITATIONS_INVITE_FORM`` + +Type: String + +Default: ``invitations.forms.InviteForm`` + +Form class used for sending invites outside admin. + +---- + +ADMIN_ADD_FORM +************** + +Setting name: ``INVITATIONS_ADMIN_ADD_FORM`` + +Type: String + +Default: ``invitations.forms.InvitationAdminAddForm`` + +Form class used for sending invites in admin. + +---- + +ADMIN_CHANGE_FORM +***************** + +Setting name: ``INVITATIONS_ADMIN_CHANGE_FORM`` + +Type: String + +Default: ``invitations.forms.InvitationAdminChangeForm`` + +Form class used for updating invites in admin. + +---- + CONFIRMATION_URL_NAME ********************* Setting name: ``INVITATIONS_CONFIRMATION_URL_NAME`` diff --git a/invitations/app_settings.py b/invitations/app_settings.py index c3737f0..4dd495a 100644 --- a/invitations/app_settings.py +++ b/invitations/app_settings.py @@ -6,8 +6,6 @@ def __init__(self, prefix): self.prefix = prefix def _setting(self, name, dflt): - from django.conf import settings - return getattr(settings, self.prefix + name, dflt) @property @@ -81,10 +79,16 @@ def INVITATION_MODEL(self): @property def INVITE_FORM(self): + """ + Form class used for sending invites outside admin. + """ return self._setting("INVITE_FORM", "invitations.forms.InviteForm") @property def ADMIN_ADD_FORM(self): + """ + Form class used for sending invites in admin. + """ return self._setting( "ADMIN_ADD_FORM", "invitations.forms.InvitationAdminAddForm", @@ -92,6 +96,9 @@ def ADMIN_ADD_FORM(self): @property def ADMIN_CHANGE_FORM(self): + """ + Form class used for updating invitations in admin. + """ return self._setting( "ADMIN_CHANGE_FORM", "invitations.forms.InvitationAdminChangeForm", diff --git a/invitations/utils.py b/invitations/utils.py index 3f58d50..0ae251b 100644 --- a/invitations/utils.py +++ b/invitations/utils.py @@ -17,14 +17,23 @@ def import_attribute(path): def get_invite_form(): + """ + Returns the form for sending an invite. + """ return import_attribute(app_settings.INVITE_FORM) def get_invitation_admin_add_form(): + """ + Returns the form for creating a new invitation in admin. + """ return import_attribute(app_settings.ADMIN_ADD_FORM) def get_invitation_admin_change_form(): + """ + Returns the form for changing invitations in admin. + """ return import_attribute(app_settings.ADMIN_CHANGE_FORM)