From 423bff39c665f3844b634b19ce95c004bf4bbce3 Mon Sep 17 00:00:00 2001 From: frekk <frekk@ucc.asn.au> Date: Mon, 31 Dec 2018 00:59:39 +0800 Subject: [PATCH] added post-registration thankyou --- gms/memberdb/register.py | 11 ++++++----- gms/memberdb/templates/thanks.html | 11 +++++++++++ gms/memberdb/urls.py | 3 +++ gms/memberdb/views.py | 6 ++++++ 4 files changed, 26 insertions(+), 5 deletions(-) create mode 100644 gms/memberdb/templates/thanks.html diff --git a/gms/memberdb/register.py b/gms/memberdb/register.py index 369fefd..045250d 100644 --- a/gms/memberdb/register.py +++ b/gms/memberdb/register.py @@ -51,8 +51,8 @@ class RegisterForm(MyModelForm): m = super().save(commit=False) if (m.display_name == ""): m.display_name = "%s %s" % (m.first_name, m.last_name); - if (commit): - m.save() + # must save otherwise membership creation will fail + m.save() # now create a corresponding Membership (marked as pending / not accepted, mostly default values) ms = make_pending_membership(m) @@ -90,7 +90,8 @@ class RegisterView(MyUpdateView): def form_valid(self, form): # save the member data and get the Member instance m, ms = form.save() - return HttpResponseRedirect(reverse("memberdb:home")) + #messages.success(self.request, 'Your registration has been submitted.') + return HttpResponseRedirect(reverse("memberdb:thanks")) class RenewView(LoginRequiredMixin, MyUpdateView): template_name = 'renew.html' @@ -112,11 +113,11 @@ class RenewView(LoginRequiredMixin, MyUpdateView): def get_context_data(self, **kwargs): context = super().get_context_data(**kwargs) context.update({ - 'is_new': self.object == None, + 'is_new': Member.objects.filter(username__exact=self.request.user.username).count() == 0, }) return context def form_valid(self, form): m, ms = form.save() - + messages.success(self.request, 'Your membership renewal has been submitted.') return HttpResponseRedirect(reverse("memberdb:home")) diff --git a/gms/memberdb/templates/thanks.html b/gms/memberdb/templates/thanks.html new file mode 100644 index 0000000..ddaf5a0 --- /dev/null +++ b/gms/memberdb/templates/thanks.html @@ -0,0 +1,11 @@ +{% extends "register.html" %} + +{% block content-title %} +<h1>Thanks!</h1> +{% endblock %} + +{% block tips %} +<b>Your membership registration has been submitted.</b><br><br> +Once it has been approved, you will receive an email with instructions to activate your account. +{% endblock %} +{% block form %}{% endblock %} \ No newline at end of file diff --git a/gms/memberdb/urls.py b/gms/memberdb/urls.py index 2b04749..82bcc9e 100644 --- a/gms/memberdb/urls.py +++ b/gms/memberdb/urls.py @@ -1,5 +1,6 @@ from django.urls import path from django.contrib.auth import views as auth_views +from django.views.generic.base import TemplateView from . import views from .views import MemberHomeView @@ -8,6 +9,7 @@ from .register import RegisterView, RenewView app_name = 'memberdb' urlpatterns = [ path('', MemberHomeView.as_view(), name='home'), + path('', MemberHomeView.as_view(), name='index'), path('login/', auth_views.LoginView.as_view(template_name='login.html'), name='login'), path('logout/', auth_views.LogoutView.as_view(template_name='logout.html'), name='logout'), @@ -18,5 +20,6 @@ urlpatterns = [ path('register/', RegisterView.as_view(), name='register'), path('renew/', RenewView.as_view(), name='renew'), path('active/', views.getactive, name='actives'), + path('thanks/', TemplateView.as_view(template_name='thanks.html'), name='thanks'), #path('<str:username>/', views.info, name='info'), ] \ No newline at end of file diff --git a/gms/memberdb/views.py b/gms/memberdb/views.py index 552c73c..fca7b77 100644 --- a/gms/memberdb/views.py +++ b/gms/memberdb/views.py @@ -3,6 +3,7 @@ from django.http import HttpResponse, HttpResponseRedirect from django.shortcuts import render from django.urls import reverse from django.forms import ModelForm +from django.contrib import messages from django.views.generic.edit import UpdateView from django.contrib.auth.mixins import LoginRequiredMixin @@ -63,3 +64,8 @@ class MemberHomeView(LoginRequiredMixin, MyUpdateView): 'memberships': m.memberships.all() if m is not None else None, }) return d + + def form_valid(self, form): + messages.success(self.request, 'Member details updated.') + # redirect to ourselves?!! because I can't think of a less hacky way to do this + return HttpResponseRedirect(reverse('memberdb:home')) -- GitLab