diff --git a/core/admin.py b/core/admin.py index 0b5ecad..cc231da 100644 --- a/core/admin.py +++ b/core/admin.py @@ -7,7 +7,7 @@ from django.core import serializers from troggle.core.views.other import downloadlogbook from troggle.core.models.troggle import Person, PersonExpedition, Expedition, DataIssue from troggle.core.models.caves import Cave, Area, Entrance, CaveAndEntrance, LogbookEntry, PersonTrip, QM -from troggle.core.models.survex import SurvexBlock, SurvexPersonRole, SurvexStation, ScansFolder, SingleScan +from troggle.core.models.survex import SurvexBlock, SurvexPersonRole, SurvexStation, Wallet, SingleScan '''This code significantly adds to the capabilities of the Django Management control panel for Troggle data. In particular, it enables JSON export of any data with 'export_as_json' @@ -118,7 +118,7 @@ admin.site.register(PersonExpedition,PersonExpeditionAdmin) admin.site.register(LogbookEntry, LogbookEntryAdmin) admin.site.register(QM, QMAdmin) admin.site.register(SurvexStation) -admin.site.register(ScansFolder) +admin.site.register(Wallet) admin.site.register(SingleScan) admin.site.register(DataIssue) diff --git a/core/models/survex.py b/core/models/survex.py index 7551470..b4dadc9 100644 --- a/core/models/survex.py +++ b/core/models/survex.py @@ -114,7 +114,7 @@ class SurvexBlock(models.Model): survexfile = models.ForeignKey("SurvexFile", blank=True, null=True,on_delete=models.SET_NULL) survexpath = models.CharField(max_length=200) # the path for the survex stations - scansfolder = models.ForeignKey("ScansFolder", null=True,on_delete=models.SET_NULL) + scansfolder = models.ForeignKey("Wallet", null=True,on_delete=models.SET_NULL) legsall = models.IntegerField(null=True) # summary data for this block legslength = models.FloatField(null=True) @@ -172,7 +172,7 @@ class SurvexPersonRole(models.Model): def __str__(self): return str(self.person) + " - " + str(self.survexblock) + " - " + str(self.nrole) -class ScansFolder(models.Model): +class Wallet(models.Model): fpath = models.CharField(max_length=200) walletname = models.CharField(max_length=200) @@ -188,7 +188,7 @@ class ScansFolder(models.Model): class SingleScan(models.Model): ffile = models.CharField(max_length=200) name = models.CharField(max_length=200) - scansfolder = models.ForeignKey("ScansFolder", null=True,on_delete=models.SET_NULL) + scansfolder = models.ForeignKey("Wallet", null=True,on_delete=models.SET_NULL) class Meta: ordering = ('name',) @@ -203,7 +203,7 @@ class DrawingFile(models.Model): dwgpath = models.CharField(max_length=200) tunnelname = models.CharField(max_length=200) bfontcolours = models.BooleanField(default=False) # UNUSED now, can be deleted - manyscansfolders = models.ManyToManyField("ScansFolder") # implicitly links via folders to scans to SVX files + manyscansfolders = models.ManyToManyField("Wallet") # implicitly links via folders to scans to SVX files scans = models.ManyToManyField("SingleScan") # implicitly links via scans to SVX files tunnelcontains = models.ManyToManyField("DrawingFile") # case when its a frame type filesize = models.IntegerField(default=0) diff --git a/core/views/surveys.py b/core/views/surveys.py index cf18fdd..d2d2fac 100644 --- a/core/views/surveys.py +++ b/core/views/surveys.py @@ -8,7 +8,7 @@ from django.conf import settings from django.shortcuts import render from django.http import HttpResponse, Http404 -from troggle.core.models.survex import ScansFolder, SingleScan, SurvexBlock, DrawingFile +from troggle.core.models.survex import Wallet, SingleScan, SurvexBlock, DrawingFile from troggle.core.views.expo import getmimetype import parsers.surveys @@ -21,9 +21,9 @@ and render a user-friendly error page. ''' def scanswallet(request, path): - #print [ s.walletname for s in ScansFolder.objects.all() ] + #print [ s.walletname for s in Wallet.objects.all() ] try: - scansfolder = ScansFolder.objects.get(walletname=urlunquote(path)) + scansfolder = Wallet.objects.get(walletname=urlunquote(path)) return render(request, 'scansfolder.html', { 'scansfolder':scansfolder, 'settings': settings }) except: message = f'Scan folder error or not found \'{path}\' .' @@ -33,7 +33,7 @@ def scansingle(request, path, file): '''sends a single binary file to the user for display - browser decides how using mimetype ''' try: - scansfolder = ScansFolder.objects.get(walletname=urlunquote(path)) + scansfolder = Wallet.objects.get(walletname=urlunquote(path)) singlescan = SingleScan.objects.get(scansfolder=scansfolder, name=file) # print(" - scansingle {}:{}:{}:".format(path, file, getmimetype(file))) return HttpResponse(content=open(singlescan.ffile,"rb"), content_type=getmimetype(file)) # any type of image @@ -43,7 +43,7 @@ def scansingle(request, path, file): def scanswallets(request): - manyscansfolders = ScansFolder.objects.all() + manyscansfolders = Wallet.objects.all() return render(request, 'manyscansfolders.html', { 'manyscansfolders':manyscansfolders, 'settings': settings }) diff --git a/parsers/survex.py b/parsers/survex.py index 1f0f036..c1d5a17 100644 --- a/parsers/survex.py +++ b/parsers/survex.py @@ -17,7 +17,7 @@ from troggle.core.utils import get_process_memory, chaosmonkey from troggle.parsers.people import GetPersonExpeditionNameLookup from troggle.parsers.logbooks import GetCaveLookup from troggle.core.models.troggle import DataIssue, Expedition -from troggle.core.models.survex import SurvexPersonRole, ScansFolder, SurvexDirectory, SurvexFile, SurvexBlock, SurvexStation +from troggle.core.models.survex import SurvexPersonRole, Wallet, SurvexDirectory, SurvexFile, SurvexBlock, SurvexStation '''Imports the tree of survex files following form a defined root .svx file It does also NOT scan the Loser repo for all the svx files - though it should ! @@ -473,7 +473,7 @@ class LoadingSurvex(): message = " ! Wallet *REF {} - not numeric in '{}'".format(refscan, survexblock.survexfile.path) print((self.insp+message)) DataIssue.objects.create(parser='survex', message=message) - manyscansfolders = ScansFolder.objects.filter(walletname=refscan) + manyscansfolders = Wallet.objects.filter(walletname=refscan) if manyscansfolders: survexblock.scansfolder = manyscansfolders[0] # this is a ForeignKey field print(manyscansfolders[0]) diff --git a/parsers/surveys.py b/parsers/surveys.py index e0ecf27..73161f2 100644 --- a/parsers/surveys.py +++ b/parsers/surveys.py @@ -10,7 +10,7 @@ from PIL import Image from functools import reduce import settings -from troggle.core.models.survex import SingleScan, ScansFolder, DrawingFile +from troggle.core.models.survex import SingleScan, Wallet, DrawingFile from troggle.core.models.troggle import DataIssue from troggle.core.utils import save_carefully @@ -85,11 +85,11 @@ def LoadListScans(): print(' - Loading Survey Scans') SingleScan.objects.all().delete() - ScansFolder.objects.all().delete() + Wallet.objects.all().delete() print(' - deleting all scansFolder and scansSingle objects') # first do the smkhs (large kh survey scans) directory - manyscansfoldersmkhs = ScansFolder(fpath=os.path.join(settings.SURVEY_SCANS, "../surveys/smkhs"), walletname="smkhs") + manyscansfoldersmkhs = Wallet(fpath=os.path.join(settings.SURVEY_SCANS, "../surveys/smkhs"), walletname="smkhs") print("smkhs", end=' ') if os.path.isdir(manyscansfoldersmkhs.fpath): manyscansfoldersmkhs.save() @@ -107,13 +107,13 @@ def LoadListScans(): print("%s" % f, end=' ') for fy, ffy, fisdiry in GetListDir(ff): if fisdiry: - scansfolder = ScansFolder(fpath=ffy, walletname=fy) + scansfolder = Wallet(fpath=ffy, walletname=fy) scansfolder.save() LoadListScansFile(scansfolder) # do the elif f != "thumbs": - scansfolder = ScansFolder(fpath=ff, walletname=f) + scansfolder = Wallet(fpath=ff, walletname=f) scansfolder.save() LoadListScansFile(scansfolder) @@ -125,7 +125,7 @@ def find_tunnel_scan(dwgfile, path): scansfolder, scansfile = None, None mscansdir = re.search(r"(\d\d\d\d#X?\d+\w?|1995-96kh|92-94Surveybookkh|1991surveybook|smkhs)/(.*?(?:png|jpg|pdf|jpeg))$", path) if mscansdir: - scansfolderl = ScansFolder.objects.filter(walletname=mscansdir.group(1)) + scansfolderl = Wallet.objects.filter(walletname=mscansdir.group(1)) # This should properly detect if a list of folders is returned and do something sensible, not just pick the first. if len(scansfolderl): scansfolder = scansfolderl[0]