diff options
author | Philip Sargent <philip.sargent@gmail.com> | 2025-01-15 17:00:01 +0000 |
---|---|---|
committer | Philip Sargent <philip.sargent@gmail.com> | 2025-01-15 17:00:01 +0000 |
commit | 21d69994e7a0efc402b3b11fd0ede04eabb1a474 (patch) | |
tree | e7c27312abcd134236fdd3df6b86f2b4af9c1d93 | |
parent | d603bef64e74dc69db57bbdbe0782cf2fc8f4726 (diff) | |
download | troggle-21d69994e7a0efc402b3b11fd0ede04eabb1a474.tar.gz troggle-21d69994e7a0efc402b3b11fd0ede04eabb1a474.tar.bz2 troggle-21d69994e7a0efc402b3b11fd0ede04eabb1a474.zip |
new signup form now split out
-rw-r--r-- | core/views/expo.py | 72 | ||||
-rw-r--r-- | core/views/signup.py | 97 | ||||
-rw-r--r-- | urls.py | 12 |
3 files changed, 103 insertions, 78 deletions
diff --git a/core/views/expo.py b/core/views/expo.py index 123540a..a25dfee 100644 --- a/core/views/expo.py +++ b/core/views/expo.py @@ -69,33 +69,6 @@ def spider(request, _): return render(request, "pagenotfound.html", {"path": path}, status=404) # return redirect("/?#") # so that suffixes applied by spider are no longer part of the url -@ensure_csrf_cookie -def signup(request): - if request.method == "POST": # If the form has been submitted... - pageform = ExpoSignupForm(request.POST) # A form bound to the POST data - if pageform.is_valid(): - print(f"form OK") - who = pageform.cleaned_data["name"] - who = git_string(editor) - print(f"{who=}") - return render( - request, - "signup.html", - {"form": pageform, - "year": "2025", "dates": "30th June - 3rd August", - "name": f"{who}", - } - ) - else: - pageform = ExpoSignupForm(initial={"allergies":"None", "medication":"None", "medic_info":"None", }) - return render( - request, - "signup.html", - {"form": pageform, - "year": "2025", "dates": "30th June - 3rd August", - "name": "", "kinname": ""}, - ) - def map(request): """Serves unadorned the expoweb/map/slippy/map.html file""" fn = Path(settings.EXPOWEB, "map", "slippy", "map.html") @@ -576,48 +549,3 @@ class ExpoPageForm(forms.Form): ), label = "Editor" ) - -class ExpoSignupForm(forms.Form): - name = forms.CharField(label='Full name', max_length=100, widget=forms.TextInput(attrs={'tabindex': 1, 'placeholder': 'Anathema Device'})) - address = forms.CharField(widget=forms.Textarea(attrs={'rows': 7, 'cols': 20, 'tabindex': 2, 'placeholder': 'The Airfield,\nTadfield'})) - phone = forms.CharField(max_length=15, widget=forms.TextInput(attrs={'tabindex': 3, 'placeholder': '+44.1234567890'})) - email = forms.EmailField(widget=forms.TextInput(attrs={'tabindex': 4, 'placeholder': 'a.device@potatohut.expo'})) - - kinname = forms.CharField(label='Next of Kin name', max_length=100, widget=forms.TextInput(attrs={'tabindex': 5, 'placeholder': 'Newton Pulsifer'})) - kinaddress = forms.CharField(widget=forms.Textarea(attrs={'rows': 7, 'cols': 20, 'tabindex': 6})) - kinphone = forms.CharField(max_length=15, widget=forms.TextInput(attrs={'tabindex': 7})) - kinemail = forms.EmailField(widget=forms.TextInput(attrs={'tabindex': 8})) - relation = forms.CharField(label='Relation to you', max_length=100, widget=forms.TextInput(attrs={'tabindex': 9, 'placeholder': 'Beau'})) - - VEGGIE_CHOICES = [ - ('yes', 'Yes'), - ('mostly', 'Mostly'), - ('no', 'No'), - ] - - STUDENT_CHOICES = [ - ('yes', 'Yes'), - ('no', 'No'), - ] - - veggie = forms.ChoiceField(choices=VEGGIE_CHOICES, widget=forms.RadioSelect(attrs={'tabindex': 10})) - student = forms.ChoiceField(choices=STUDENT_CHOICES, widget=forms.RadioSelect(attrs={'tabindex': 11})) - - transport_ok = forms.ChoiceField(choices=[('yes', 'Yes'), ('no', 'No')], - widget=forms.RadioSelect(attrs={'tabindex': 12}), initial='yes') - transport_info = forms.CharField(widget=forms.Textarea(attrs={'rows': 6, 'cols': 80, 'tabindex': 13}), - required=False) - - bivvy = forms.BooleanField(required=False, widget=forms.CheckboxInput(attrs={'tabindex': 14})) - tent = forms.BooleanField(required=False, widget=forms.CheckboxInput(attrs={'tabindex': 15})) - top_tent_cap = forms.IntegerField(required=False, widget=forms.NumberInput(attrs={'tabindex': 16})) - btent = forms.BooleanField(required=False, widget=forms.CheckboxInput(attrs={'tabindex': 17})) - base_tent_cap = forms.IntegerField(required=False, widget=forms.NumberInput(attrs={'tabindex': 18})) - - allergies = forms.CharField(widget=forms.Textarea(attrs={'rows': 2, 'cols': 80, 'tabindex': 19}), required=False) - medication = forms.CharField(widget=forms.Textarea(attrs={'rows': 2, 'cols': 80, 'tabindex': 20}), required=False) - medic_info = forms.CharField(widget=forms.Textarea(attrs={'rows': 5, 'cols': 80, 'tabindex': 21}), required=False) - - extra_info = forms.CharField(widget=forms.Textarea(attrs={'rows': 15, 'cols': 80, 'tabindex': 22}), required=False) - - aims = forms.CharField(widget=forms.Textarea(attrs={'rows': 15, 'cols': 80, 'tabindex': 23}), required=False) diff --git a/core/views/signup.py b/core/views/signup.py new file mode 100644 index 0000000..d36b095 --- /dev/null +++ b/core/views/signup.py @@ -0,0 +1,97 @@ +import os +import re +from pathlib import Path + +import django.forms as forms +from django.http import HttpResponse, HttpResponseRedirect +from django.shortcuts import redirect, render +from django.urls import reverse +from django.views.decorators.csrf import ensure_csrf_cookie + +import troggle.settings as settings +from troggle.core.utils import ( + COOKIE_MAX_AGE, + WriteAndCommitError, + current_expo, + get_cookie, + git_string, + write_and_commit, +) +from troggle.core.views.editor_helpers import HTMLarea + +from .auth import login_required_if_public + +"""The new user signup form and expo user management system in 2025. +""" + +@ensure_csrf_cookie +def signup(request): + if request.method == "POST": # If the form has been submitted... + pageform = ExpoSignupForm(request.POST) # A form bound to the POST data + if pageform.is_valid(): + print(f"form OK") + who = pageform.cleaned_data["name"] + who = git_string(editor) + print(f"{who=}") + return render( + request, + "signup.html", + {"form": pageform, + "year": "2025", "dates": "30th June - 3rd August", + "name": f"{who}", + } + ) + else: + pageform = ExpoSignupForm(initial={"allergies":"None", "medication":"None", "medic_info":"None", }) + return render( + request, + "signup.html", + {"form": pageform, + "year": "2025", "dates": "30th June - 3rd August", + "name": "", "kinname": ""}, + ) + +class ExpoSignupForm(forms.Form): + name = forms.CharField(label='Full name', max_length=100, widget=forms.TextInput(attrs={'tabindex': 1, 'placeholder': 'Anathema Device'})) + address = forms.CharField(widget=forms.Textarea(attrs={'rows': 7, 'cols': 20, 'tabindex': 2, 'placeholder': 'The Airfield,\nTadfield'})) + phone = forms.CharField(max_length=15, widget=forms.TextInput(attrs={'tabindex': 3, 'placeholder': '+44.1234567890'})) + email = forms.EmailField(widget=forms.TextInput(attrs={'tabindex': 4, 'placeholder': 'a.device@potatohut.expo'})) + + kinname = forms.CharField(label='Next of Kin name', max_length=100, widget=forms.TextInput(attrs={'tabindex': 5, 'placeholder': 'Newton Pulsifer'})) + kinaddress = forms.CharField(widget=forms.Textarea(attrs={'rows': 7, 'cols': 20, 'tabindex': 6})) + kinphone = forms.CharField(max_length=15, widget=forms.TextInput(attrs={'tabindex': 7})) + kinemail = forms.EmailField(widget=forms.TextInput(attrs={'tabindex': 8})) + relation = forms.CharField(label='Relation to you', max_length=100, widget=forms.TextInput(attrs={'tabindex': 9, 'placeholder': 'Beau'})) + + VEGGIE_CHOICES = [ + ('yes', 'Yes'), + ('mostly', 'Mostly'), + ('no', 'No'), + ] + + STUDENT_CHOICES = [ + ('yes', 'Yes'), + ('no', 'No'), + ] + + veggie = forms.ChoiceField(choices=VEGGIE_CHOICES, widget=forms.RadioSelect(attrs={'tabindex': 10})) + student = forms.ChoiceField(choices=STUDENT_CHOICES, widget=forms.RadioSelect(attrs={'tabindex': 11})) + + transport_ok = forms.ChoiceField(choices=[('yes', 'Yes'), ('no', 'No')], + widget=forms.RadioSelect(attrs={'tabindex': 12}), initial='yes') + transport_info = forms.CharField(widget=forms.Textarea(attrs={'rows': 6, 'cols': 80, 'tabindex': 13}), + required=False) + + bivvy = forms.BooleanField(required=False, widget=forms.CheckboxInput(attrs={'tabindex': 14})) + tent = forms.BooleanField(required=False, widget=forms.CheckboxInput(attrs={'tabindex': 15})) + top_tent_cap = forms.IntegerField(required=False, widget=forms.NumberInput(attrs={'tabindex': 16})) + btent = forms.BooleanField(required=False, widget=forms.CheckboxInput(attrs={'tabindex': 17})) + base_tent_cap = forms.IntegerField(required=False, widget=forms.NumberInput(attrs={'tabindex': 18})) + + allergies = forms.CharField(widget=forms.Textarea(attrs={'rows': 2, 'cols': 80, 'tabindex': 19}), required=False) + medication = forms.CharField(widget=forms.Textarea(attrs={'rows': 2, 'cols': 80, 'tabindex': 20}), required=False) + medic_info = forms.CharField(widget=forms.Textarea(attrs={'rows': 5, 'cols': 80, 'tabindex': 21}), required=False) + + extra_info = forms.CharField(widget=forms.Textarea(attrs={'rows': 15, 'cols': 80, 'tabindex': 22}), required=False) + + aims = forms.CharField(widget=forms.Textarea(attrs={'rows': 15, 'cols': 80, 'tabindex': 23}), required=False) @@ -34,7 +34,6 @@ from troggle.core.views.expo import ( mediapage, pubspage, spider, - signup, ) from troggle.core.views.logbook_edit import logbookedit from troggle.core.views.logbooks import ( @@ -54,6 +53,7 @@ from troggle.core.views.logbooks import ( from troggle.core.views.other import controlpanel, exportlogbook, frontpage, todos from troggle.core.views.prospect import prospecting from troggle.core.views.scans import allscans, cavewallets, scansingle, walletslistperson, walletslistyear +from troggle.core.views.signup import signup from troggle.core.views.uploads import dwgupload, expofilerename, gpxupload, photoupload from troggle.core.views.wallets_edit import walletedit @@ -142,19 +142,19 @@ trogglepatterns = [ re_path(r'^admin/', admin.site.urls), # includes admin login & logout urls & /admin/jsi18n/ # Uploads - uploading a file - path('walletedit/', walletedit, name='walletedit'), - path('walletedit/<path:path>', walletedit, name='walletedit'), # path=2020#01 + path('walletedit/', walletedit, name='walletedit'), + path('walletedit/<path:path>', walletedit, name='walletedit'), # path=2020#01 path('photoupload/', photoupload, name='photoupload'), # restricted to current year path('photoupload/<path:folder>', photoupload, name='photoupload'), # restricted to current year - path('gpxupload/', gpxupload, name='gpxupload'), # restricted to current year - path('gpxupload/<path:folder>', gpxupload, name='gpxupload'), # restricted to current year + path('gpxupload/', gpxupload, name='gpxupload'), # restricted to current year + path('gpxupload/<path:folder>', gpxupload, name='gpxupload'), # restricted to current year path('dwgupload/<path:folder>', dwgupload, name='dwgupload'), path('dwgupload/', dwgupload, name='dwgupload'), path('dwguploadnogit/', dwgupload, {'gitdisable': 'yes'}, name='dwguploadnogit'), # used in testing path('dwguploadnogit/<path:folder>', dwgupload, {'gitdisable': 'yes'}, name='dwguploadnogit'), # used in testing path('logbookedit/', logbookedit, name='logbookedit'), path('logbookedit/<slug:slug>', logbookedit, name='logbookedit'), - path('sign_up', signup, name='signup'), + path('signup', signup, name='signup'), # Renaming an uploaded file path('expofilerename/<path:filepath>', expofilerename, name='expofilerename'), |