2
0
mirror of https://expo.survex.com/repositories/troggle/.git synced 2026-03-30 07:49:51 +01:00

Pre-load form with saved data

This commit is contained in:
2025-01-25 20:36:35 +00:00
parent 0d105d40da
commit 95ea87233f
2 changed files with 45 additions and 17 deletions

View File

@@ -32,10 +32,15 @@ SIGNUP_DATES = "30th June - 3rd August"
def signupok(request):
signup_user = request.user
signedup_people = []
signups_clear = read_signups()
for su in signups_clear:
signedup_people.append(su)
return render(
request, "login/signupok.html",
{"year": SIGNUP_YEAR, "dates": SIGNUP_DATES, "signup_user": signup_user },
{"year": SIGNUP_YEAR, "dates": SIGNUP_DATES, "signup_user": signup_user, "signedup_people": signedup_people},
)
def signup(request):
@@ -58,7 +63,7 @@ def signup(request):
# someone like "fluffy-bunny" not associated with a Person
return HttpResponseRedirect("/accounts/login/?next=/signup")
signup_person = people[0]
editor = f"{signup_person.fullname} <{signup_user.email}>"
editor = f"{signup_person.fullname} <{signup_user.email}>"
if request.method == "POST": # If the form has been submitted...
pageform = ExpoSignupForm(request.POST) # A form bound to the POST data
@@ -77,17 +82,25 @@ def signup(request):
}
)
else:
initial_context = {"allergies":"None",
"medication":"None",
"medic_info":"None",
"veggie": "mostly",
"student": "no",
"top_tent_cap": 2,
"base_tent_cap": 3,
}
signups_clear = read_signups()
if signup_user.username in signups_clear:
# pre-load form with previously saved data
initial_context = signups_clear[signup_user.username]
else:
initial_context = {"allergies":"None",
"medication":"None",
"medic_info":"None",
"veggie": "mostly",
"student": "no",
"top_tent_cap": 2,
"base_tent_cap": 3,
}
if personal_login:
initial_context["name"] = signup_person.fullname
initial_context["email"] = signup_user.email
pageform = ExpoSignupForm(initial=initial_context)
return render(
request, "login/signup.html",
@@ -127,7 +140,7 @@ def read_signups():
for su, content in signups_dict.items():
clear_text = f.decrypt(content).decode()
print(f"\n - C signups_dict {su} - {clear_text}")
signups_clear[su] = clear_text
signups_clear[su] = json.loads(clear_text)
return signups_clear