Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add docs to swappable forms #105

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,18 @@ Bulk invites are supported via JSON. Post a list of comma separated emails to t

App registry path of the invitation model used in the current project, for customization purposes.

* `INVITE_FORM` (default=`invitations.forms.InviteForm`)

Form class used for sending invites outside admin.

* `ADMIN_ADD_FORM` (default=`invitations.forms.InvitationAdminAddForm`)

Form class used for sending invites in admin.

* `ADMIN_CHANGE_FORM` (default=`invitations.forms.InvitationAdminChangeForm`)

Form class used for updating invitations in admin.

### Signals

The following signals are emitted:
Expand Down
14 changes: 11 additions & 3 deletions invitations/app_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@ class AppSettings(object):
def __init__(self, prefix):
self.prefix = prefix

def _setting(self, name, dflt):
from django.conf import settings
return getattr(settings, self.prefix + name, dflt)
def _setting(self, name, default):
return getattr(settings, self.prefix + name, default)

@property
def INVITATION_EXPIRY(self):
Expand Down Expand Up @@ -82,17 +81,26 @@ 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"
)

@property
def ADMIN_CHANGE_FORM(self):
"""
Form class used for updating invitations in admin.
"""
return self._setting(
"ADMIN_CHANGE_FORM",
"invitations.forms.InvitationAdminChangeForm"
Expand Down
9 changes: 9 additions & 0 deletions invitations/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,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)


Expand Down