mirror of
https://expo.survex.com/repositories/troggle/.git
synced 2025-12-17 13:57:06 +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.db.models import Q
|
||||||
from django.shortcuts import redirect, render
|
from django.shortcuts import redirect, render
|
||||||
from django.views.generic.list import ListView
|
from django.views.generic.list import ListView
|
||||||
|
from django.contrib.auth.models import User
|
||||||
|
|
||||||
import troggle.settings as settings
|
import troggle.settings as settings
|
||||||
from troggle.core.models.logbooks import QM, LogbookEntry, PersonLogEntry, writelogbook
|
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.models.wallets import Wallet
|
||||||
from troggle.core.utils import TROG, current_expo
|
from troggle.core.utils import TROG, current_expo
|
||||||
from troggle.parsers.imports import import_logbook
|
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
|
"""These views are for logbook items when they appear in an 'expedition' page
|
||||||
and for persons: their individual pages and their perseonexpedition pages.
|
and for persons: their individual pages and their perseonexpedition pages.
|
||||||
|
|
||||||
@@ -47,9 +48,10 @@ def notablepersons(request):
|
|||||||
return render(
|
return render(
|
||||||
request, "notablepersons.html", {"persons": persons, "pcols": pcols, "notablepersons": notablepersons}
|
request, "notablepersons.html", {"persons": persons, "pcols": pcols, "notablepersons": notablepersons}
|
||||||
)
|
)
|
||||||
|
|
||||||
def people_ids(request):
|
def people_ids(request):
|
||||||
|
|
||||||
|
ensure_users_are_persons()
|
||||||
persons = Person.objects.order_by('fullname')
|
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
|
# From what I can tell, "persons" seems to be the table rows, while "pcols" is the table columns. - AC 16 Feb 09
|
||||||
pcols = []
|
pcols = []
|
||||||
|
|||||||
@@ -175,8 +175,18 @@ def load_people_expos():
|
|||||||
# otherAttribs = {"is_guest": (personline[header["Guest"]] == "1")}
|
# otherAttribs = {"is_guest": (personline[header["Guest"]] == "1")}
|
||||||
pe = PersonExpedition.objects.create(**coUniqueAttribs)
|
pe = PersonExpedition.objects.create(**coUniqueAttribs)
|
||||||
print("", flush=True)
|
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):
|
def who_is_this(year, possibleid):
|
||||||
expo = Expedition.objects.filter(year=year)
|
expo = Expedition.objects.filter(year=year)
|
||||||
personexpedition = GetPersonExpeditionNameLookup(expo)[possibleid.lower()]
|
personexpedition = GetPersonExpeditionNameLookup(expo)[possibleid.lower()]
|
||||||
|
|||||||
@@ -25,11 +25,12 @@ todo = """
|
|||||||
USERS_FILE = "users.json"
|
USERS_FILE = "users.json"
|
||||||
ENCRYPTED_DIR = "encrypted"
|
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.
|
"""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
|
Do not use the lastname field, put the whole free text identification into firstname
|
||||||
as this saves hassle and works with Wookey too
|
as this saves hassle and works with Wookey too
|
||||||
"""
|
"""
|
||||||
|
print(f" - {u} {fullname=}")
|
||||||
try:
|
try:
|
||||||
if existing_user := User.objects.filter(username=u): # WALRUS
|
if existing_user := User.objects.filter(username=u): # WALRUS
|
||||||
print(f" - deleting existing user '{existing_user[0]}' before importing")
|
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()
|
user.save()
|
||||||
print(f" - receated and reset user '{user}'")
|
print(f" - receated and reset user '{user}'")
|
||||||
except Exception as e:
|
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
|
raise
|
||||||
|
|
||||||
expoers = Person.objects.filter(slug=u)
|
expoers = Person.objects.filter(slug=u)
|
||||||
@@ -98,6 +100,7 @@ def load_users():
|
|||||||
users_list = registered_users_dict["registered_users"]
|
users_list = registered_users_dict["registered_users"]
|
||||||
|
|
||||||
print(f" - {len(users_list)} users read from JSON")
|
print(f" - {len(users_list)} users read from JSON")
|
||||||
|
print(f"-- Registering users in database")
|
||||||
for userdata in users_list:
|
for userdata in users_list:
|
||||||
if not userdata["username"]:
|
if not userdata["username"]:
|
||||||
message = f"! user: BAD username for {userdata} in {jsonfile}"
|
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)
|
DataIssue.objects.update_or_create(parser=PARSER_USERS, message=message, url=jsonurl)
|
||||||
continue
|
continue
|
||||||
else:
|
else:
|
||||||
|
print(f" - {userdata["username"]=}")
|
||||||
if userdata["username"] in [ "expo", "expoadmin" ]:
|
if userdata["username"] in [ "expo", "expoadmin" ]:
|
||||||
continue
|
continue
|
||||||
if "encrypted" not in userdata:
|
if "encrypted" not in userdata:
|
||||||
@@ -114,7 +118,7 @@ def load_users():
|
|||||||
email = userdata["email"]
|
email = userdata["email"]
|
||||||
if userdata["encrypted"]:
|
if userdata["encrypted"]:
|
||||||
email = f.decrypt(email).decode()
|
email = f.decrypt(email).decode()
|
||||||
print(f" - user: '{u} <{email}>' ")
|
print(f" - user: '{u} <{email}>' (decrypted)")
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(f"Exception <{e}>\n")
|
print(f"Exception <{e}>\n")
|
||||||
formatted_json = json.dumps(userdata, indent=4)
|
formatted_json = json.dumps(userdata, indent=4)
|
||||||
|
|||||||
@@ -15,7 +15,15 @@
|
|||||||
<tr><th>Person</th><th>troggle ID</th></tr>
|
<tr><th>Person</th><th>troggle ID</th></tr>
|
||||||
{% for person in persons %}
|
{% for person in persons %}
|
||||||
<tr>
|
<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>
|
<td style="padding: 3px"><a href="{{ person.get_absolute_url }}">{{person|safe}}</a></td>
|
||||||
|
|
||||||
|
|
||||||
@@ -26,5 +34,5 @@
|
|||||||
{% endfor %}
|
{% endfor %}
|
||||||
</tr>
|
</tr>
|
||||||
</table>
|
</table>
|
||||||
|
<p>People with their <span style="color:red">names in red </span> have a registered login and email address.
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|||||||
Reference in New Issue
Block a user