From fedcc6d201df8a474105ee1032430e9fbd401b11 Mon Sep 17 00:00:00 2001 From: Philip Sargent Date: Fri, 24 Jan 2025 02:33:42 +0000 Subject: [PATCH] whack a mole --- core/views/logbooks.py | 6 ++++-- parsers/people.py | 10 ++++++++++ parsers/users.py | 10 +++++++--- templates/{errors => login}/frontpage.html | 0 templates/people_ids.html | 12 ++++++++++-- 5 files changed, 31 insertions(+), 7 deletions(-) rename templates/{errors => login}/frontpage.html (100%) diff --git a/core/views/logbooks.py b/core/views/logbooks.py index 2466fec..8bec554 100644 --- a/core/views/logbooks.py +++ b/core/views/logbooks.py @@ -4,6 +4,7 @@ from django.core.exceptions import ValidationError from django.db.models import Q from django.shortcuts import redirect, render from django.views.generic.list import ListView +from django.contrib.auth.models import User import troggle.settings as settings from troggle.core.models.logbooks import QM, LogbookEntry, PersonLogEntry, writelogbook @@ -12,7 +13,7 @@ from troggle.core.models.troggle import Expedition, Person from troggle.core.models.wallets import Wallet from troggle.core.utils import TROG, current_expo from troggle.parsers.imports import import_logbook - +from troggle.parsers.people import ensure_users_are_persons """These views are for logbook items when they appear in an 'expedition' page and for persons: their individual pages and their perseonexpedition pages. @@ -47,9 +48,10 @@ def notablepersons(request): return render( request, "notablepersons.html", {"persons": persons, "pcols": pcols, "notablepersons": notablepersons} ) - + def people_ids(request): + ensure_users_are_persons() persons = Person.objects.order_by('fullname') # From what I can tell, "persons" seems to be the table rows, while "pcols" is the table columns. - AC 16 Feb 09 pcols = [] diff --git a/parsers/people.py b/parsers/people.py index 4a4512c..18b73f9 100644 --- a/parsers/people.py +++ b/parsers/people.py @@ -175,8 +175,18 @@ def load_people_expos(): # otherAttribs = {"is_guest": (personline[header["Guest"]] == "1")} pe = PersonExpedition.objects.create(**coUniqueAttribs) print("", flush=True) + ensure_users_are_persons() +def ensure_users_are_persons(): + # Just ensure this is up to date. + users = User.objects.all() + for u in users: + ps = Person.objects.filter(slug=u.username) + if len(ps) >= 1: + p = ps[0] + p.user = u + def who_is_this(year, possibleid): expo = Expedition.objects.filter(year=year) personexpedition = GetPersonExpeditionNameLookup(expo)[possibleid.lower()] diff --git a/parsers/users.py b/parsers/users.py index cf721ba..0501525 100644 --- a/parsers/users.py +++ b/parsers/users.py @@ -25,11 +25,12 @@ todo = """ USERS_FILE = "users.json" ENCRYPTED_DIR = "encrypted" -def register_user(u, email, password=None, pwhash=None, fullname=None): +def register_user(u, email, password=None, pwhash=None, fullname=""): """Create User and we may not have a Person to tie it to if it is a future caver. Do not use the lastname field, put the whole free text identification into firstname as this saves hassle and works with Wookey too """ + print(f" - {u} {fullname=}") try: if existing_user := User.objects.filter(username=u): # WALRUS print(f" - deleting existing user '{existing_user[0]}' before importing") @@ -49,7 +50,8 @@ def register_user(u, email, password=None, pwhash=None, fullname=None): user.save() print(f" - receated and reset user '{user}'") except Exception as e: - print(f"Exception <{e}>\n{len(User.objects.all())} users now in db:\n{User.objects.all()}") + print(f"Exception <{e}>") + print(f"{len(User.objects.all())} users now in db:\n{User.objects.all()}") raise expoers = Person.objects.filter(slug=u) @@ -98,6 +100,7 @@ def load_users(): users_list = registered_users_dict["registered_users"] print(f" - {len(users_list)} users read from JSON") + print(f"-- Registering users in database") for userdata in users_list: if not userdata["username"]: message = f"! user: BAD username for {userdata} in {jsonfile}" @@ -105,6 +108,7 @@ def load_users(): DataIssue.objects.update_or_create(parser=PARSER_USERS, message=message, url=jsonurl) continue else: + print(f" - {userdata["username"]=}") if userdata["username"] in [ "expo", "expoadmin" ]: continue if "encrypted" not in userdata: @@ -114,7 +118,7 @@ def load_users(): email = userdata["email"] if userdata["encrypted"]: email = f.decrypt(email).decode() - print(f" - user: '{u} <{email}>' ") + print(f" - user: '{u} <{email}>' (decrypted)") except Exception as e: print(f"Exception <{e}>\n") formatted_json = json.dumps(userdata, indent=4) diff --git a/templates/errors/frontpage.html b/templates/login/frontpage.html similarity index 100% rename from templates/errors/frontpage.html rename to templates/login/frontpage.html diff --git a/templates/people_ids.html b/templates/people_ids.html index ae89337..7a9b727 100644 --- a/templates/people_ids.html +++ b/templates/people_ids.html @@ -15,7 +15,15 @@ Persontroggle ID {% for person in persons %} - {{person.fullname|safe}} + + {% if person.user %} + + {% else %} + + {% endif %} + {{person.fullname|safe}} + + {{person|safe}} @@ -26,5 +34,5 @@ {% endfor %} - +

People with their names in red have a registered login and email address. {% endblock %}