2
0
mirror of https://expo.survex.com/repositories/troggle/.git synced 2025-12-19 01:17:13 +00:00

generated to-do lists updated

This commit is contained in:
2025-01-20 15:30:15 +00:00
parent 960958c922
commit 1fcb2c5203
3 changed files with 29 additions and 16 deletions

View File

@@ -59,6 +59,8 @@ def todos(request, module):
from troggle.parsers.drawings import todo as parsersdrawings from troggle.parsers.drawings import todo as parsersdrawings
from troggle.parsers.locations import todo as parserslocations from troggle.parsers.locations import todo as parserslocations
from troggle.parsers.logbooks import todo as parserslogbooks from troggle.parsers.logbooks import todo as parserslogbooks
from troggle.parsers.people import todo as parserspeople
from troggle.parsers.users import todo as parsersusers
from troggle.parsers.survex import todo as parserssurvex from troggle.parsers.survex import todo as parserssurvex
from troggle.urls import todo as todourls from troggle.urls import todo as todourls
@@ -81,6 +83,8 @@ def todos(request, module):
"parsers/drawings": parsersdrawings, "parsers/drawings": parsersdrawings,
"parsers/locations": parserslocations, "parsers/locations": parserslocations,
"parsers/logbooks": parserslogbooks, "parsers/logbooks": parserslogbooks,
"parsers/people": parserspeople,
"parsers/users": parsersusers,
"parsers/survex": parserssurvex, "parsers/survex": parserssurvex,
"urls": todourls, "urls": todourls,
} }

View File

@@ -17,6 +17,10 @@ The standalone script needs to be renedred defucnt, and all the parsing needs to
or they should use the same code by importing a module. or they should use the same code by importing a module.
""" """
todo = """
- [copy these from paper notes]
"""
def parse_blurb(personline, header, person): def parse_blurb(personline, header, person):
"""create mugshot Photo instance """create mugshot Photo instance
Would be better if all this was done before the Person object was created in the db, then it would not Would be better if all this was done before the Person object was created in the db, then it would not

View File

@@ -10,12 +10,17 @@ from django.db import models
from troggle.core.models.troggle import DataIssue, Expedition, Person, PersonExpedition from troggle.core.models.troggle import DataIssue, Expedition, Person, PersonExpedition
"""These functions do not match how the stand-alone folk script works. So the script produces an HTML file which has """This imports the registered troggle users, who are nearly-all, but not quite, Persons.
href links to pages in troggle which troggle does not think are right. exceptions are "expo" and "expoadmin" which are created by the databaseReset.py import program.
The standalone script needs to be renedred defucnt, and all the parsing needs to be in troggle. Either that,
or they should use the same code by importing a module. This imports unencrypted email addresses but never exports them.
Passwords are only ever stored as hashes using the standard Django functions.
""" """
todo = """
- [copy these from paper notes]
"""
USERS_FILE = "users_e.json" USERS_FILE = "users_e.json"
ENCRYPTED_DIR = "encrypted" ENCRYPTED_DIR = "encrypted"
@@ -28,8 +33,6 @@ def load_users():
key = settings.LONGTERM_SECRET_KEY # Django generated key = settings.LONGTERM_SECRET_KEY # Django generated
k = base64.urlsafe_b64encode(key.encode("utf8")[:32]) # make Fernet compatible k = base64.urlsafe_b64encode(key.encode("utf8")[:32]) # make Fernet compatible
f = Fernet(k) f = Fernet(k)
print(f)
jsonfile = settings.EXPOWEB / ENCRYPTED_DIR / USERS_FILE jsonfile = settings.EXPOWEB / ENCRYPTED_DIR / USERS_FILE
jsonurl = "/" + str(Path(ENCRYPTED_DIR) / USERS_FILE) jsonurl = "/" + str(Path(ENCRYPTED_DIR) / USERS_FILE)
@@ -57,27 +60,29 @@ def load_users():
print(f" - {len(users_list)} users read from JSON") print(f" - {len(users_list)} users read from JSON")
for userdata in users_list: for userdata in users_list:
if userdata["username"]: if userdata["username"]:
if userdata["username"] == "expo": if userdata["username"] in [ "expo", "expoadmin" ]:
continue
if userdata["username"] == "expoadmin":
continue continue
if "encrypted" not in userdata:
userdata["encrypted"] = True
try: try:
u = userdata["username"] u = userdata["username"]
e_email = userdata["email"] email = userdata["email"]
email = f.decrypt(e_email).decode() if userdata["encrypted"]:
email = f.decrypt(email).decode()
print(f" - user: '{u} <{email}>' ") print(f" - user: '{u} <{email}>' ")
if existing_user := User.objects.filter(username=userdata["username"]): # WALRUS if existing_user := User.objects.filter(username=userdata["username"]): # WALRUS
# print(f" - deleting existing user '{existing_user[0]}' before importing") # print(f" - deleting existing user '{existing_user[0]}' before importing")
existing_user[0].delete() existing_user[0].delete()
user = User.objects.create_user(userdata["username"], email, "secret") user = User.objects.create_user(userdata["username"], email, "secret")
user.set_password = "secret" # stores hash not password user.set_password = "secret" # special attribute stores hash not password
user.is_staff = False user.is_staff = False
user.is_superuser = False user.is_superuser = False
user.save() user.save()
except Exception as e: except Exception as e:
print(f"Exception <{e}>\nusers in db: {len(User.objects.all())}\n{User.objects.all()}") print(f"Exception <{e}>\n{len(User.objects.all())} users now in db:\n{User.objects.all()}")
formatted_json = json.dumps(userdata, indent=4) formatted_json = json.dumps(userdata, indent=4)
print(formatted_json) print(formatted_json)
raise
return None return None
else: else:
print(f" - user: BAD username for {userdata} ") print(f" - user: BAD username for {userdata} ")
@@ -94,8 +99,8 @@ def load_users():
if u.username == "expoadmin": if u.username == "expoadmin":
continue continue
e_email = f.encrypt(u.email.encode("utf8")).decode() e_email = f.encrypt(u.email.encode("utf8")).decode()
ru.append({"username":u.username, "email": e_email, "password": u.password}) ru.append({"username":u.username, "email": e_email, "password": u.password, "encrypted": True})
print(u.username, e_email) # print(u.username, e_email)
original = f.decrypt(e_email).decode() original = f.decrypt(e_email).decode()
print(u.username, original) print(u.username, original)
@@ -103,5 +108,5 @@ def load_users():
encryptedfile = settings.EXPOWEB / ENCRYPTED_DIR / "encrypt.json" encryptedfile = settings.EXPOWEB / ENCRYPTED_DIR / "encrypt.json"
# with open(encryptedfile, 'w', encoding='utf-8') as json_f: # with open(encryptedfile, 'w', encoding='utf-8') as json_f:
# json.dump(jsondict, json_f, indent=1) # json.dump(jsondict, json_f, indent=1)
# return True return True