From a3993edf32cfe9330261e345aa7ce253ef21d9a5 Mon Sep 17 00:00:00 2001
From: Calum Mackervoy <c.mackervoy@gmail.com>
Date: Mon, 11 Apr 2022 21:02:42 +0200
Subject: [PATCH] feature: added REGISTRATION_USER_FORM setting

---
 README.md                           | 10 ++++++++--
 djangoldp_account/djangoldp_urls.py |  6 +++++-
 2 files changed, 13 insertions(+), 3 deletions(-)

diff --git a/README.md b/README.md
index 22817e3..266d66f 100644
--- a/README.md
+++ b/README.md
@@ -66,9 +66,15 @@ Optionally you can configure which user fields which you would like to include o
 REGISTRATION_FIELDS = ('username', 'email', 'password1', 'password2')
 ```
 
-The workflow starts at : http://127.0.0.1:8000/accounts/register/
+This will be sufficient to change the user fields on display on the form. If you want to customise the form (for example by [adding a model relationship to the user](https://stackoverflow.com/questions/14726725/python-django-django-registration-add-an-extra-field/14879316#14879316)), then you can override the setting `REGISTRATION_USER_FORM` to replace it altogether. The form you supply should extend `djangoldp_account.forms.LDPUserForm` or at minimum `django_registration.forms.RegistrationForm`
 
-Then, override template by copying the directory `djangoldp_account/templates/django_registration/` to your project and modify them.
+```
+REGISTRATION_USER_FORM: "djangoldp_hiphopcommunity.forms.HipHopUserForm"
+```
+
+In either case, at a minimum the registration form fields must include the fields `('username', 'email', 'password1', 'password2')`
+
+Visit http://127.0.0.1:8000/auth/register/ to access the registration form
 
 ### Enabling account activation without mail
 
diff --git a/djangoldp_account/djangoldp_urls.py b/djangoldp_account/djangoldp_urls.py
index 41b2f8b..8f09a39 100644
--- a/djangoldp_account/djangoldp_urls.py
+++ b/djangoldp_account/djangoldp_urls.py
@@ -1,5 +1,6 @@
 """djangoldp project URL Configuration"""
 
+from pydoc import locate
 from django.conf import settings
 from django.conf.urls import url, include
 from django.contrib.auth.models import Group
@@ -17,6 +18,9 @@ Group._meta.anonymous_perms = getattr(settings, 'GROUP_ANONYMOUS_PERMISSIONS', [
 Group._meta.authenticated_perms = getattr(settings, 'GROUP_AUTHENTICATED_PERMISSIONS', ['inherit'])
 Group._meta.owner_perms = getattr(settings, 'GROUP_OWNER_PERMISSIONS', ['inherit'])
 
+user_form_override = getattr(settings, 'REGISTRATION_USER_FORM', None)
+user_form = LDPUserForm if user_form_override is None else locate(user_form_override)
+
 urlpatterns = [
     url(r'^groups/',
         LDPViewSet.urls(model=Group, fields=['@id', 'name', 'user_set'],
@@ -25,7 +29,7 @@ urlpatterns = [
     ),
     url(r'^auth/register/$',
         LDPAccountRegistrationView.as_view(
-            form_class=LDPUserForm
+            form_class=user_form
         ),
         name='django_registration_register',
     ),
-- 
GitLab