mirror of
https://expo.survex.com/repositories/troggle/.git
synced 2025-12-17 14:07:07 +00:00
whack a mole
This commit is contained in:
@@ -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.
|
||||
|
||||
@@ -50,6 +51,7 @@ def notablepersons(request):
|
||||
|
||||
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 = []
|
||||
|
||||
@@ -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()]
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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 %}
|
||||
|
||||
Reference in New Issue
Block a user