summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPhilip Sargent <philip.sargent@gmail.com>2025-01-24 02:33:42 +0000
committerPhilip Sargent <philip.sargent@gmail.com>2025-01-24 02:33:42 +0000
commitfedcc6d201df8a474105ee1032430e9fbd401b11 (patch)
tree153e881731cdba88ba1f935a8989adb53212ff3f
parent61722fd6c065f491770568eb0aad57194ce13d61 (diff)
downloadtroggle-fedcc6d201df8a474105ee1032430e9fbd401b11.tar.gz
troggle-fedcc6d201df8a474105ee1032430e9fbd401b11.tar.bz2
troggle-fedcc6d201df8a474105ee1032430e9fbd401b11.zip
whack a mole
-rw-r--r--core/views/logbooks.py6
-rw-r--r--parsers/people.py10
-rw-r--r--parsers/users.py10
-rw-r--r--templates/login/frontpage.html (renamed from templates/errors/frontpage.html)0
-rw-r--r--templates/people_ids.html12
5 files changed, 31 insertions, 7 deletions
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
index 461bce9..461bce9 100644
--- a/templates/errors/frontpage.html
+++ b/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 @@
<tr><th>Person</th><th>troggle ID</th></tr>
{% for person in persons %}
<tr>
- <td style="padding: 3px">{{person.fullname|safe}}</td>
+ <td style="padding: 3px">
+ {% if person.user %}
+ <span style="color:red">
+ {% else %}
+ <span>
+ {% endif %}
+ {{person.fullname|safe}}
+ </span>
+ </td>
<td style="padding: 3px"><a href="{{ person.get_absolute_url }}">{{person|safe}}</a></td>
@@ -26,5 +34,5 @@
{% endfor %}
</tr>
</table>
-
+<p>People with their <span style="color:red">names in red </span> have a registered login and email address.
{% endblock %}