2
0
mirror of https://expo.survex.com/repositories/troggle/.git synced 2025-12-16 08:47:12 +00:00

refactoring duplicate code

This commit is contained in:
2023-10-23 22:54:46 +03:00
parent b522899216
commit 33477f2b40
4 changed files with 65 additions and 39 deletions

View File

@@ -13,15 +13,14 @@ contentsjson = "contents.json"
git = settings.GIT
# to do: Actually read all the JSON files and set the survex file field appropriately!
def set_walletyear(wallet):
_ = wallet.year() # don't need return value. Just calling this saves it as w.walletyear Syntactic.
def set_JSONwalletdate(wallet):
"""At this point in the import process, the survex files have not been imported so
we cannot get dates from them. There are about 40 JSON files (in 2022) which we read here."""
we cannot get dates from them. There are about 40 JSON files (in 2022) which we read here.
Actually, doing anything that reads the JSON sets .walletdate"""
_ = wallet.date() # don't need return value. Sets .walletdate as side effect
def set_caves(wallet):
@@ -111,11 +110,11 @@ def load_all_scans():
else:
print("", flush=True, end="")
# Create the wallet object. But we don't have a date for it yet.
wallet = Wallet(fpath=fpath, walletname=walletname)
wallet = Wallet.objects.create(walletname=walletname, fpath=fpath)
wallets[walletname] = wallet
set_walletyear(wallet)
wallet.save()
set_caves(wallet)
wallet.save()
singlescan = SingleScan(ffile=fpath, name=p.name, wallet=wallet)
singlescan.save()
@@ -156,15 +155,13 @@ def load_all_scans():
# The wallets found from JSON should all have dates already
wallet, created = Wallet.objects.update_or_create(walletname=walletname, fpath=fpath)
wallets[walletname] = wallet
# Now also load the json
set_JSONwalletdate(wallet)
set_walletyear(wallet)
set_caves(wallet)
wallet.save()
if not created:
print(
f"\n - {walletname} was not created, but was not in directory walk of /surveyscans/. Who created it?"
)
wallet.save()
print(f"\n - found another {wjson:,} JSON files, making a total of {len(wallets):,} wallets")
# Only the 1999 wallets have filenames which mean that the walletyear will be unset: