forked from expo/troggle
Setting wallet dates earlier in the import process
This commit is contained in:
@@ -99,7 +99,7 @@ class Wallet(models.Model):
|
||||
|
||||
# Yes this is horribly, horribly inefficient, esp. for a page that have date, people and cave in it
|
||||
def date(self):
|
||||
"""Reads all the JSON data just to get the JSNON date."""
|
||||
"""Reads all the JSON data just to get the JSON date."""
|
||||
if self.walletdate:
|
||||
return self.walletdate
|
||||
if not self.get_json():
|
||||
|
||||
@@ -11,9 +11,9 @@ from troggle.core.models.survex import SingleScan, SurvexBlock
|
||||
from troggle.core.models.wallets import Wallet
|
||||
from troggle.core.models.troggle import DataIssue, Expedition, Person
|
||||
from troggle.core.views.expo import getmimetype
|
||||
from troggle.parsers.survex import set_walletdate
|
||||
|
||||
# from troggle.parsers.people import GetPersonExpeditionNameLookup
|
||||
|
||||
# import parsers.surveys
|
||||
|
||||
"""one of these views serves files as binary blobs, and simply set the mime type based on the file extension,
|
||||
@@ -23,7 +23,7 @@ by looking inside the file before being served.
|
||||
need to check if inavlid query string is invalid, or produces multiple replies
|
||||
and render a user-friendly error page.
|
||||
|
||||
Note that datewallet(), caveifywallet() etc do NOT save the object to the db. They are ephemeral, just for the page rendering of the
|
||||
Note that caveifywallet() etc do NOT save the object to the db. They are ephemeral, just for the page rendering of the
|
||||
manywallets dict.
|
||||
|
||||
TODO
|
||||
@@ -47,24 +47,7 @@ def populatewallet(w):
|
||||
w.persons = list(set(survexpeople))
|
||||
|
||||
|
||||
def datewallet(w, earliest):
|
||||
"""Gets the date of the youngest survexblock associated with the wallet
|
||||
REFACTOR this to do the whole date-getting task
|
||||
"""
|
||||
first = earliest
|
||||
blocks = SurvexBlock.objects.filter(scanswallet=w)
|
||||
for b in blocks:
|
||||
if b.date:
|
||||
if b.date < first:
|
||||
first = b.date
|
||||
if first == earliest:
|
||||
# no date found
|
||||
w.date = None
|
||||
else:
|
||||
w.date = first.isoformat()
|
||||
return w.date
|
||||
|
||||
|
||||
|
||||
def caveifywallet(w):
|
||||
"""Gets the cave from the list of survex files,
|
||||
only selects one of them though. Only used for display.
|
||||
@@ -105,11 +88,7 @@ def fillblankpeople(w):
|
||||
|
||||
def fillblankothers(w):
|
||||
if not w.walletdate:
|
||||
earliest = datetime.datetime.now().date()
|
||||
if not w.date(): # sets .walletdate as a side-effect, gets it from JSON
|
||||
d = datewallet(w, earliest) # if nothing in JASON, it looks at the survex blocks
|
||||
w.walletdate = d
|
||||
w.save()
|
||||
set_walletdate(w)
|
||||
|
||||
Gcavelookup = GetCaveLookup()
|
||||
|
||||
@@ -180,6 +159,8 @@ def walletslistperson(request, first_name, last_name):
|
||||
|
||||
|
||||
def setwalletsdates():
|
||||
"""This sets all the undated wallets, but they should already all be dated on
|
||||
import or on edit"""
|
||||
wallets = Wallet.objects.filter(walletdate=None)
|
||||
print(f"undated wallets: {len(wallets)}")
|
||||
for w in wallets:
|
||||
|
||||
@@ -842,6 +842,7 @@ def walletedit(request, path=None):
|
||||
},
|
||||
)
|
||||
else: # no wallet data: should never happen as there should be default data in all cases
|
||||
print(f"! - Should never get here ! Problem in wallet editing...")
|
||||
context = {
|
||||
"year": year,
|
||||
"prev": prev,
|
||||
|
||||
Reference in New Issue
Block a user