summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPhilip Sargent <philip.sargent@gmail.com>2025-02-09 22:06:19 +0000
committerPhilip Sargent <philip.sargent@gmail.com>2025-02-09 22:06:19 +0000
commit10352f2ccb194e9fca562b19cecbe294e93d2d8c (patch)
treef6c639098a7e5259cbcb65e782b414896c3b5c45
parent0e2ccee6788f41cc9113925575502a4a44182978 (diff)
downloadtroggle-10352f2ccb194e9fca562b19cecbe294e93d2d8c.tar.gz
troggle-10352f2ccb194e9fca562b19cecbe294e93d2d8c.tar.bz2
troggle-10352f2ccb194e9fca562b19cecbe294e93d2d8c.zip
Signup adds person to current expedition
-rw-r--r--core/views/signup.py23
-rw-r--r--parsers/logbooks.py9
-rw-r--r--parsers/people.py19
3 files changed, 38 insertions, 13 deletions
diff --git a/core/views/signup.py b/core/views/signup.py
index 04e7539..7536556 100644
--- a/core/views/signup.py
+++ b/core/views/signup.py
@@ -8,7 +8,8 @@ from django.shortcuts import redirect, render
from django.urls import reverse
import troggle.settings as settings
-from troggle.core.models.troggle import DataIssue, Person
+from troggle.core.models.troggle import DataIssue, Person, PersonExpedition
+from troggle.core.models.logbooks import Expedition
from troggle.core.views.editor_helpers import HTMLarea
from troggle.core.utils import (
COOKIE_MAX_AGE,
@@ -51,7 +52,7 @@ def signupok(request):
def signup(request):
- """Display and processes the applicant signup form for the forthcoming expo
+ """Displays and processes the applicant signup form for the forthcoming expo
The user must be logged-on as a personal login and that is
who is being signed up. You can't signup someone else.
"""
@@ -85,6 +86,7 @@ def signup(request):
if pageform.is_valid():
clean = pageform.cleaned_data
print(f" # Signup form OK {clean['name']}")
+ register_on_expo(signup_person)
save_signups(editor, signup_person.slug, clean)
return HttpResponseRedirect("/signupok")
@@ -123,8 +125,14 @@ def signup(request):
},
)
+def register_on_expo(signup_person):
+ signup = PersonExpedition(person=signup_person, expedition=Expedition.objects.get(year=SIGNUP_YEAR))
+ signup.save()
+
def read_signups():
# print(f" + READ signups")
+ # This has a big BUG. when it works, it returns a dict with keys such as "philip-sargent"
+ # but the error conditions are returning a dict of dicts
f = get_encryptor()
signups_dir = settings.EXPOWEB / ENCRYPTED_DIR / current_expo()
if not signups_dir.is_dir():
@@ -132,7 +140,7 @@ def read_signups():
signupsfile = signups_dir / SIGNUPS_FILE
if not signupsfile.is_file():
- return { SIGNEDUP: {} } # dict where e.g. {"philip-sargent": encrypted_form_data, more users etc.}
+ return { "SIGNEDUP": {} } # dict where e.g. {"philip-sargent": encrypted_form_data, more users etc.}
with open(signupsfile, 'r', encoding='utf-8') as json_f:
message = ""
@@ -147,7 +155,7 @@ def read_signups():
if message:
print(message)
DataIssue.objects.update_or_create(parser="_signups", message=message, url="") ###########################
- return { SIGNEDUP: {} }
+ return { "SIGNEDUP": {} }
signups_dict = signups_single_dict[SIGNEDUP]
# print("ALL:",signups_dict)
signups_clear ={}
@@ -158,6 +166,13 @@ def read_signups():
return signups_clear
+# def is_signedup(person):
+ # signups_clear = read_signups()
+ # print(signups_clear)
+ # if person.slug in signups_clear:
+ # return True
+ # return False
+
def save_signups(editor, person_slug, clean):
# print(f" + SAVE: Saving all signups")
diff --git a/parsers/logbooks.py b/parsers/logbooks.py
index 08e2710..a411848 100644
--- a/parsers/logbooks.py
+++ b/parsers/logbooks.py
@@ -58,11 +58,6 @@ LOGBOOK_PARSER_SETTINGS = {
LOGBOOKS_DIR = "years" # subfolder of settings.EXPOWEB
ENTRIES = {
- "2029": 0,
- "2028": 0,
- "2027": 0,
- "2026": 0,
- "2025": 0,
"2024": 125,
"2023": 131,
"2022": 94,
@@ -106,6 +101,10 @@ ENTRIES = {
"1979": 30,
"1978": 38,
}
+for y in range(2025, 2050):
+ y_str = str(y)
+ if y_str not in ENTRIES:
+ ENTRIES[y_str] = 0
# What about 1970s ! Yes, 80 and 81 are missing, so are 1976 and 1977.
logentries = [] # the entire logbook for one year is a single object: a list of entries
diff --git a/parsers/people.py b/parsers/people.py
index 04b5e2f..b6b8159 100644
--- a/parsers/people.py
+++ b/parsers/people.py
@@ -10,6 +10,7 @@ from django.db import models
from unidecode import unidecode
from troggle.core.models.troggle import DataIssue, Expedition, Person, PersonExpedition
+from troggle.core.views.signup import read_signups
"""These functions do not match how the stand-alone folk script works. So the script produces an HTML file which has
href links to pages in troggle which troggle does not think are right.
@@ -94,8 +95,6 @@ def troggle_slugify(longname):
def load_people_expos():
"""This is where the folk.csv file is parsed to read people's names.
- Which it gets wrong for people like Lydia-Clare Leather and various 'von' and 'de' middle 'names'
- and McLean and Mclean and McAdam - interaction with the url parser in urls.py too
This is ALSO where all the Expedition objects get created. So this is the point at which troggle
gets told what expeditions exist.
@@ -116,6 +115,7 @@ def load_people_expos():
if nexpos <= 0:
print(" - Creating expeditions")
for year in years:
+ year = year.strip()
coUniqueAttribs = {"year": year}
otherAttribs = {"name": f"CUCC expo {year}"}
e = Expedition.objects.create(**otherAttribs, **coUniqueAttribs)
@@ -176,10 +176,22 @@ def load_people_expos():
pe = PersonExpedition.objects.create(**coUniqueAttribs)
print("", flush=True)
ensure_users_are_persons()
+ most_recent = Expedition.objects.all().first()
+ check_new_signups(most_recent)
+
+def check_new_signups(expedition):
+ signups_clear = read_signups()
+ # print(signups_clear)
+ for slug in signups_clear:
+ print(slug)
+ p = Person.objects.get(slug=slug)
+ pe = PersonExpedition.objects.update_or_create(person=p, expedition=expedition)
+ # print("ADDING ",pe, expedition)
+
def ensure_users_are_persons():
# Just ensure this is up to date.
- print(f"# ensure_users_are_persons()")
+ print(f"# ensure_users_are_persons() - except for expo and expoadmin of course")
users = User.objects.all()
for u in users:
ps = Person.objects.filter(slug=u.username)
@@ -197,7 +209,6 @@ def who_is_this(year, possibleid):
else:
return None
-
def when_on_expo(name):
"""Returns a list of PersonExpedition objects for the string, if recognised as a name
"""