From 43394facdf09116e24037b9f769ded987265db82 Mon Sep 17 00:00:00 2001 From: Philip Sargent Date: Sun, 31 May 2020 21:03:40 +0100 Subject: [PATCH] Delete SURVEYS.CSV code --- core/views_other.py | 14 ------- parsers/surveys.py | 82 ++++--------------------------------- templates/controlPanel.html | 51 ++++++++--------------- 3 files changed, 25 insertions(+), 122 deletions(-) diff --git a/core/views_other.py b/core/views_other.py index 6adca9c..c2b8303 100644 --- a/core/views_other.py +++ b/core/views_other.py @@ -71,20 +71,6 @@ def controlPanel(request): return render(request,'controlPanel.html', {'caves':Cave.objects.all(),'expeditions':Expedition.objects.all(),'jobs_completed':jobs_completed}) -def downloadCavetab(request): - from export import tocavetab - response = HttpResponse(content_type='text/csv') - response['Content-Disposition'] = 'attachment; filename=CAVETAB2.CSV' - tocavetab.writeCaveTab(response) - return response - -def downloadSurveys(request): - from export import tosurveys - response = HttpResponse(content_type='text/csv') - response['Content-Disposition'] = 'attachment; filename=Surveys.csv' - tosurveys.writeCaveTab(response) - return response - def downloadLogbook(request,year=None,extension=None,queryset=None): if year: diff --git a/parsers/surveys.py b/parsers/surveys.py index 1e1ac22..8a45bc3 100644 --- a/parsers/surveys.py +++ b/parsers/surveys.py @@ -29,67 +29,14 @@ def get_or_create_placeholder(year): placeholder_logbook_entry, newly_created = save_carefully(LogbookEntry, lookupAttribs, nonLookupAttribs) return placeholder_logbook_entry -# obsolete surveys.csv does not exist. -# def readSurveysFromCSV(): - # try: # could probably combine these two - # surveytab = open(os.path.join(settings.SURVEY_SCANS, "Surveys.csv")) - # except IOError: - # import io, urllib.request, urllib.parse, urllib.error - # surveytab = io.StringIO(urllib.request.urlopen(settings.SURVEY_SCANS + "/Surveys.csv").read()) - # dialect=csv.Sniffer().sniff(surveytab.read()) - # surveytab.seek(0,0) - # surveyreader = csv.reader(surveytab,dialect=dialect) - # headers = next(surveyreader) - # header = dict(list(zip(headers, list(range(len(headers)))))) #set up a dictionary where the indexes are header names and the values are column numbers - - # # test if the expeditions have been added yet - # if Expedition.objects.count()==0: - # print("There are no expeditions in the database. Please run the logbook parser.") - # sys.exit() - - - # logging.info("Deleting all scanned images") - # ScannedImage.objects.all().delete() - - - # logging.info("Deleting all survey objects") - # Survey.objects.all().delete() - - - # logging.info("Beginning to import surveys from "+str(os.path.join(settings.SURVEYS, "Surveys.csv"))+"\n"+"-"*60+"\n") - - # for survey in surveyreader: - # #I hate this, but some surveys have a letter eg 2000#34a. The next line deals with that. - # walletNumberLetter = re.match(r'(?P\d*)(?P[a-zA-Z]*)',survey[header['Survey Number']]) - # # print(walletNumberLetter.groups()) - # year=survey[header['Year']] - - - # surveyobj = Survey( - # expedition = Expedition.objects.filter(year=year)[0], - # wallet_number = walletNumberLetter.group('number'), - # logbook_entry = get_or_create_placeholder(year), - # comments = survey[header['Comments']], - # location = survey[header['Location']] - # ) - # surveyobj.wallet_letter = walletNumberLetter.group('letter') - # if survey[header['Finished']]=='Yes': - # #try and find the sketch_scan - # pass - # surveyobj.save() - - - # logging.info("added survey " + survey[header['Year']] + "#" + surveyobj.wallet_number + "\r") - -# dead -# def listdir(*directories): - # try: - # return os.listdir(os.path.join(settings.SURVEYS, *directories)) - # except: - # import urllib.request, urllib.parse, urllib.error - # url = settings.SURVEYS + reduce(lambda x, y: x + "/" + y, ["listdir"] + list(directories)) - # folders = urllib.request.urlopen(url.replace("#", "%23")).readlines() - # return [folder.rstrip(r"/") for folder in folders] +def listdir(*directories): + try: + return os.listdir(os.path.join(settings.SURVEYS, *directories)) + except: + import urllib.request, urllib.parse, urllib.error + url = settings.SURVEYS + reduce(lambda x, y: x + "/" + y, ["listdir"] + list(directories)) + folders = urllib.request.urlopen(url.replace("#", "%23")).readlines() + return [folder.rstrip(r"/") for folder in folders] # add survey scans # def parseSurveyScans(expedition, logfile=None): @@ -157,19 +104,6 @@ def get_or_create_placeholder(year): # yearPath=os.path.join(settings.SURVEY_SCANS, "surveyscans", expedition.year) # print((" ! No folder found for " + expedition.year + " at:- " + yearPath)) -# dead -# def parseSurveys(logfile=None): - # try: - # readSurveysFromCSV() - # except (IOError, OSError): - # print(" ! Survey CSV not found..") - # pass - - # print(" - Loading scans by expedition year") - # for expedition in Expedition.objects.filter(year__gte=2000): #expos since 2000, because paths and filenames were nonstandard before then - # print("%s" % expedition, end=' ') - # parseSurveyScans(expedition) - # dead # def isInterlacedPNG(filePath): #We need to check for interlaced PNGs because the thumbnail engine can't handle them (uses PIL) # file=Image.open(filePath) diff --git a/templates/controlPanel.html b/templates/controlPanel.html index 41c9409..a01f3e5 100644 --- a/templates/controlPanel.html +++ b/templates/controlPanel.html @@ -16,7 +16,7 @@ {% if error %}
- {{ error }} + {{ error }} dismiss this message
{% endif %} @@ -96,61 +96,44 @@ - - surveys to Surveys.csv + + surveys to Surveys.csv - +
-

Download a logbook file which is dynamically generated by Troggle.

- +

Download a logbook file which is dynamically generated by Troggle.

+

Expedition year:

Output style: - + +

- + - - - surveys to Surveys.csv - - -
-

Overwrite the existing Surveys.csv file with one generated by Troggle.

- -
- - -
-

Download a Surveys.csv file which is dynamically generated by Troggle.

- -
- - - + qms to qms.csv -
- + + - Choose a cave. + Choose a cave. @@ -174,4 +157,4 @@
-{% endblock %} \ No newline at end of file +{% endblock %} \ No newline at end of file