From a95dd34bea8fbdec764425aa033519456d72d37b Mon Sep 17 00:00:00 2001 From: Tom Price Date: Thu, 21 May 2015 16:04:12 +0100 Subject: [PATCH 1/2] Working saving of registration data, need this doesn't create the required registration profile though. Might need to find a way to invoke automatically then just append the new user data to the end. --- PyRIGS/urls.py | 3 +-- RIGS/forms.py | 6 +++++- RIGS/views.py | 12 ++++++++++++ 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/PyRIGS/urls.py b/PyRIGS/urls.py index 82d0c209..a4c8e2a3 100644 --- a/PyRIGS/urls.py +++ b/PyRIGS/urls.py @@ -11,8 +11,7 @@ urlpatterns = patterns('', # url(r'^blog/', include('blog.urls')), url(r'^', include('RIGS.urls')), - url('^user/register/$', RegistrationView.as_view(form_class=RIGS.forms.ProfileRegistrationFormUniqueEmail), - name="registration_register"), + url('^user/register/$', RIGS.views.ProfileRegistrationView.as_view()), url('^user/', include('django.contrib.auth.urls')), url('^user/', include('registration.backends.default.urls')), diff --git a/RIGS/forms.py b/RIGS/forms.py index 8a019409..5b4941ec 100644 --- a/RIGS/forms.py +++ b/RIGS/forms.py @@ -16,7 +16,11 @@ class ProfileRegistrationFormUniqueEmail(RegistrationFormUniqueEmail): last_name = forms.CharField(required=False, max_length=50) initials = forms.CharField(required=True, max_length=5) phone = forms.CharField(required=False, max_length=13) - captcha = ReCaptchaField() + # captcha = ReCaptchaField() + + class Meta: + model = models.Profile + fields = ('first_name','last_name','initials','phone') def clean_initials(self): """ diff --git a/RIGS/views.py b/RIGS/views.py index 472f20ec..0d00680e 100644 --- a/RIGS/views.py +++ b/RIGS/views.py @@ -9,6 +9,7 @@ from django.core import serializers import simplejson from django.contrib import messages import datetime +from registration.views import RegistrationView from RIGS import models, forms @@ -33,6 +34,17 @@ def login(request, **kwargs): return login(request, authentication_form=forms.LoginForm) +class ProfileRegistrationView(RegistrationView): + form_class = forms.ProfileRegistrationFormUniqueEmail + + def register(self, request, **form): + model = models.Profile() + for (key,value) in form.items(): + setattr(model, key, value) + model.set_password(form['password1']) + model.is_active = False + return model.save() + """ Called from a modal window (e.g. when an item is submitted to an event/invoice). May optionally also include some javascript in a success message to cause a load of From e685fa2f7c849abcee97d8a7fb9e2da45e38b60a Mon Sep 17 00:00:00 2001 From: Tom Price Date: Thu, 21 May 2015 21:45:01 +0100 Subject: [PATCH 2/2] Change adding extra user data to on a signal instead. Not sure if this data is clean or not. --- PyRIGS/urls.py | 4 +++- RIGS/regbackend.py | 13 +++++++++++++ RIGS/views.py | 12 ------------ 3 files changed, 16 insertions(+), 13 deletions(-) create mode 100644 RIGS/regbackend.py diff --git a/PyRIGS/urls.py b/PyRIGS/urls.py index a4c8e2a3..9821ae20 100644 --- a/PyRIGS/urls.py +++ b/PyRIGS/urls.py @@ -4,6 +4,7 @@ from django.contrib.staticfiles.urls import staticfiles_urlpatterns from django.conf import settings from registration.backends.default.views import RegistrationView import RIGS +from RIGS import regbackend urlpatterns = patterns('', # Examples: @@ -11,7 +12,8 @@ urlpatterns = patterns('', # url(r'^blog/', include('blog.urls')), url(r'^', include('RIGS.urls')), - url('^user/register/$', RIGS.views.ProfileRegistrationView.as_view()), + url('^user/register/$', RegistrationView.as_view(form_class=RIGS.forms.ProfileRegistrationFormUniqueEmail), + name="registration_register"), url('^user/', include('django.contrib.auth.urls')), url('^user/', include('registration.backends.default.urls')), diff --git a/RIGS/regbackend.py b/RIGS/regbackend.py new file mode 100644 index 00000000..90828a39 --- /dev/null +++ b/RIGS/regbackend.py @@ -0,0 +1,13 @@ +from RIGS.models import Profile +from RIGS.forms import ProfileRegistrationFormUniqueEmail + +def user_created(sender, user, request, **kwargs): + form = ProfileRegistrationFormUniqueEmail(request.POST) + user.first_name = form.data['first_name'] + user.last_name = form.data['last_name'] + user.initials = form.data['initials'] + user.phone = form.data['phone'] + user.save() + +from registration.signals import user_registered +user_registered.connect(user_created) \ No newline at end of file diff --git a/RIGS/views.py b/RIGS/views.py index 0d00680e..265e2dd5 100644 --- a/RIGS/views.py +++ b/RIGS/views.py @@ -33,18 +33,6 @@ def login(request, **kwargs): return login(request, authentication_form=forms.LoginForm) - -class ProfileRegistrationView(RegistrationView): - form_class = forms.ProfileRegistrationFormUniqueEmail - - def register(self, request, **form): - model = models.Profile() - for (key,value) in form.items(): - setattr(model, key, value) - model.set_password(form['password1']) - model.is_active = False - return model.save() - """ Called from a modal window (e.g. when an item is submitted to an event/invoice). May optionally also include some javascript in a success message to cause a load of