From e59f8308ce5972cba74cfb5f821826fc5da1e19b Mon Sep 17 00:00:00 2001 From: Sam Wenham Date: Sun, 24 Feb 2019 18:55:30 +0000 Subject: [PATCH] Deal better with the wallet letter number combo of 2019#X01 --- core/models.py | 8 +++++--- parsers/surveys.py | 9 +++++---- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/core/models.py b/core/models.py index f87792e..32d4c68 100644 --- a/core/models.py +++ b/core/models.py @@ -800,9 +800,11 @@ class DPhoto(TroggleImageModel): scansFileStorage = FileSystemStorage(location=settings.SURVEY_SCANS, base_url=settings.SURVEYS_URL) def get_scan_path(instance, filename): year=instance.survey.expedition.year - #print "WN: ", type(instance.survey.wallet_number), instance.survey.wallet_number - number=str(instance.survey.wallet_number) + str(instance.survey.wallet_letter) #two strings formatting because convention is 2009#01 or 2009#X01 - return os.path.join('./',year,year+r'#'+number,instance.contents+str(instance.number_in_wallet)+r'.jpg') + #print("WN: ", type(instance.survey.wallet_number), instance.survey.wallet_number, instance.survey.wallet_letter) + number=str(instance.survey.wallet_number) + if str(instance.survey.wallet_letter) != "None": + number=str(instance.survey.wallet_letter) + number #two strings formatting because convention is 2009#01 or 2009#X01 + return os.path.join('./',year,year+r'#'+number,str(instance.contents)+str(instance.number_in_wallet)+r'.jpg') class ScannedImage(TroggleImageModel): file = models.ImageField(storage=scansFileStorage, upload_to=get_scan_path) diff --git a/parsers/surveys.py b/parsers/surveys.py index 29de15c..777e04f 100644 --- a/parsers/surveys.py +++ b/parsers/surveys.py @@ -95,7 +95,7 @@ def parseSurveyScans(expedition, logfile=None): print(yearFileList) for surveyFolder in yearFileList: try: - surveyNumber=re.match(r'\d\d\d\d#0*(\d+)',surveyFolder).groups() + surveyNumber=re.match(r'\d\d\d\d#(X?)0*(\d+)',surveyFolder).groups() #scanList = listdir(expedition.year, surveyFolder) scanList=os.listdir(os.path.join(yearPath,surveyFolder)) except AttributeError: @@ -116,12 +116,13 @@ def parseSurveyScans(expedition, logfile=None): scanNumber=1 if type(surveyNumber)==types.TupleType: - surveyNumber=surveyNumber[0] + surveyLetter=surveyNumber[0] + surveyNumber=surveyNumber[1] try: placeholder=get_or_create_placeholder(year=int(expedition.year)) - survey=Survey.objects.get_or_create(wallet_number=surveyNumber, expedition=expedition, defaults={'logbook_entry':placeholder})[0] + survey=Survey.objects.get_or_create(wallet_number=surveyNumber, wallet_letter=surveyLetter, expedition=expedition, defaults={'logbook_entry':placeholder})[0] except Survey.MultipleObjectsReturned: - survey=Survey.objects.filter(wallet_number=surveyNumber, expedition=expedition)[0] + survey=Survey.objects.filter(wallet_number=surveyNumber, wallet_letter=surveyLetter, expedition=expedition)[0] file_=os.path.join(yearPath, surveyFolder, scan) scanObj = ScannedImage( file=file_,