From 49b9225b6e833b4c08382fc86f9556ff4d0e7fbc Mon Sep 17 00:00:00 2001 From: Philip Sargent Date: Mon, 26 Apr 2021 19:50:03 +0100 Subject: [PATCH] rename scansfolder to wallet --- core/models/survex.py | 14 ++++---- core/views/surveys.py | 12 +++---- parsers/survex.py | 4 +-- parsers/surveys.py | 36 ++++++++++----------- requirements.txt | 4 ++- requirements3.2.txt | 10 ++++++ templates/base.html | 2 +- templates/dwgfiles.html | 4 +-- templates/expowebbase.html | 2 +- templates/manywallets.html | 8 ++--- templates/svxcaveseveral.html | 4 +-- templates/svxcavesingle.html | 4 +-- templates/{scansfolder.html => wallet.html} | 6 ++-- urls.py | 6 ++-- 14 files changed, 64 insertions(+), 52 deletions(-) create mode 100644 requirements3.2.txt rename templates/{scansfolder.html => wallet.html} (78%) diff --git a/core/models/survex.py b/core/models/survex.py index 6d662e9..b30f231 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("Wallet", null=True,on_delete=models.SET_NULL) + scanswallet = 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) @@ -180,24 +180,24 @@ class Wallet(models.Model): ordering = ('walletname',) def get_absolute_url(self): - return urljoin(settings.URL_ROOT, reverse('scanswallet', kwargs={"path":re.sub("#", "%23", self.walletname)})) + return urljoin(settings.URL_ROOT, reverse('singlewallet', kwargs={"path":re.sub("#", "%23", self.walletname)})) def __str__(self): return str(self.walletname) + " (Survey Scans Folder)" class SingleScan(models.Model): - ffile = models.CharField(max_length=200) - name = models.CharField(max_length=200) - scansfolder = models.ForeignKey("Wallet", null=True,on_delete=models.SET_NULL) + ffile = models.CharField(max_length=200) + name = models.CharField(max_length=200) + wallet = models.ForeignKey("Wallet", null=True,on_delete=models.SET_NULL) class Meta: ordering = ('name',) def get_absolute_url(self): - return urljoin(settings.URL_ROOT, reverse('scansingle', kwargs={"path":re.sub("#", "%23", self.scansfolder.walletname), "file":self.name})) + return urljoin(settings.URL_ROOT, reverse('scansingle', kwargs={"path":re.sub("#", "%23", self.wallet.walletname), "file":self.name})) def __str__(self): - return "Survey Scan Image: " + str(self.name) + " in " + str(self.scansfolder) + return "Survey Scan Image: " + str(self.name) + " in " + str(self.wallet) class DrawingFile(models.Model): dwgpath = models.CharField(max_length=200) diff --git a/core/views/surveys.py b/core/views/surveys.py index 952aa77..56168f6 100644 --- a/core/views/surveys.py +++ b/core/views/surveys.py @@ -20,11 +20,11 @@ need to check if inavlid query string is invalid, or produces multiple replies and render a user-friendly error page. ''' -def scanswallet(request, path): +def singlewallet(request, path): #print [ s.walletname for s in Wallet.objects.all() ] try: - scansfolder = Wallet.objects.get(walletname=urlunquote(path)) - return render(request, 'scansfolder.html', { 'scansfolder':scansfolder, 'settings': settings }) + wallet = Wallet.objects.get(walletname=urlunquote(path)) + return render(request, 'wallet.html', { 'wallet':wallet, 'settings': settings }) except: message = f'Scan folder error or not found \'{path}\' .' return render(request, 'errors/generic.html', {'message': message}) @@ -33,8 +33,8 @@ def scansingle(request, path, file): '''sends a single binary file to the user for display - browser decides how using mimetype ''' try: - scansfolder = Wallet.objects.get(walletname=urlunquote(path)) - singlescan = SingleScan.objects.get(scansfolder=scansfolder, name=file) + wallet = Wallet.objects.get(walletname=urlunquote(path)) + singlescan = SingleScan.objects.get(wallet=wallet, name=file) # print(" - scansingle {}:{}:{}:".format(path, file, getmimetype(file))) return HttpResponse(content=open(singlescan.ffile,"rb"), content_type=getmimetype(file)) # any type of image except: @@ -42,7 +42,7 @@ def scansingle(request, path, file): return render(request, 'errors/generic.html', {'message': message}) -def scanswallets(request): +def allwallets(request): manywallets = Wallet.objects.all() return render(request, 'manywallets.html', { 'manywallets':manywallets, 'settings': settings }) diff --git a/parsers/survex.py b/parsers/survex.py index 9686b2e..ea1e061 100644 --- a/parsers/survex.py +++ b/parsers/survex.py @@ -86,7 +86,7 @@ class LoadingSurvex(): """A 'survex block' is a *begin...*end set of cave data. A survex file can contain many begin-end blocks, which can be nested, and which can *include other survex files. - A 'scansfolder' is what we today call a "survey scans folder" or a "wallet". + A 'scanswallet' is what we today call a "survey scans folder" or a "wallet". """ rx_begin = re.compile(r'(?i)begin') rx_end = re.compile(r'(?i)end$') @@ -475,7 +475,7 @@ class LoadingSurvex(): DataIssue.objects.create(parser='survex', message=message) manywallets = Wallet.objects.filter(walletname=refscan) if manywallets: - survexblock.scansfolder = manywallets[0] # this is a ForeignKey field + survexblock.scanswallet = manywallets[0] # this is a ForeignKey field print(manywallets[0]) survexblock.save() if len(manywallets) > 1: diff --git a/parsers/surveys.py b/parsers/surveys.py index cfe8db9..f9ca56a 100644 --- a/parsers/surveys.py +++ b/parsers/surveys.py @@ -58,10 +58,10 @@ def GetListDir(sdir): return res -def LoadListScansFile(scansfolder): +def LoadListScansFile(wallet): gld = [ ] # flatten out any directories in these wallet folders - should not be any - for (fyf, ffyf, fisdiryf) in GetListDir(scansfolder.fpath): + for (fyf, ffyf, fisdiryf) in GetListDir(wallet.fpath): if fisdiryf: gld.extend(GetListDir(ffyf)) else: @@ -70,7 +70,7 @@ def LoadListScansFile(scansfolder): c=0 for (fyf, ffyf, fisdiryf) in gld: if re.search(r"\.(?:png|jpg|jpeg|pdf|svg|gif)(?i)$", fyf): - singlescan = SingleScan(ffile=ffyf, name=fyf, scansfolder=scansfolder) + singlescan = SingleScan(ffile=ffyf, name=fyf, wallet=wallet) singlescan.save() c+=1 if c>=10: @@ -107,35 +107,35 @@ def LoadListScans(): print("%s" % f, end=' ') for fy, ffy, fisdiry in GetListDir(ff): if fisdiry: - scansfolder = Wallet(fpath=ffy, walletname=fy) - scansfolder.save() - LoadListScansFile(scansfolder) + wallet = Wallet(fpath=ffy, walletname=fy) + wallet.save() + LoadListScansFile(wallet) # do the elif f != "thumbs": - scansfolder = Wallet(fpath=ff, walletname=f) - scansfolder.save() - LoadListScansFile(scansfolder) + wallet = Wallet(fpath=ff, walletname=f) + wallet.save() + LoadListScansFile(wallet) def find_tunnel_scan(dwgfile, path): '''Is given a line of text 'path' which may or may not contain a recognisable name of a scanned file which we have already seen when we imported all the files we could find in the surveyscans direstories ''' - scansfolder, scansfile = None, None + wallet, 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 = Wallet.objects.filter(walletname=mscansdir.group(1)) + scanswalletl = 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] - if len(scansfolderl) > 1: + if len(scanswalletl): + wallet = scanswalletl[0] + if len(scanswalletl) > 1: message = "! More than one scan FOLDER matches filter query. [{}]: {} {} {} {}".format(scansfilel[0], mscansdir.group(1), mscansdir.group(2), dwgfile.dwgpath, path) print(message) DataIssue.objects.create(parser='Tunnel', message=message) - if scansfolder: - scansfilel = scansfolder.singlescan_set.filter(name=mscansdir.group(2)) + if wallet: + scansfilel = wallet.singlescan_set.filter(name=mscansdir.group(2)) if len(scansfilel): if len(scansfilel) > 1: message = "! More than one image FILENAME matches filter query. [{}]: {} {} {} {}".format(scansfilel[0], mscansdir.group(1), mscansdir.group(2), dwgfile.dwgpath, path) @@ -143,8 +143,8 @@ def find_tunnel_scan(dwgfile, path): DataIssue.objects.create(parser='Tunnel', message=message) scansfile = scansfilel[0] - if scansfolder: - dwgfile.manywallets.add(scansfolder) + if wallet: + dwgfile.manywallets.add(wallet) if scansfile: dwgfile.scans.add(scansfile) diff --git a/requirements.txt b/requirements.txt index a7a7711..cba36bf 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,8 +1,10 @@ +asgiref==3.3.4 confusable-homoglyphs==3.2.0 -Django==2.2.19 +Django==2.2.20 docutils==0.14 gunicorn==20.1.0 Pillow==5.4.1 pytz==2019.1 sqlparse==0.2.4 +typing-extensions==3.7.4.3 Unidecode==1.0.23 diff --git a/requirements3.2.txt b/requirements3.2.txt new file mode 100644 index 0000000..06995ab --- /dev/null +++ b/requirements3.2.txt @@ -0,0 +1,10 @@ +asgiref==3.3.4 +confusable-homoglyphs==3.2.0 +Django==3.2 +docutils==0.14 +gunicorn==20.1.0 +Pillow==5.4.1 +pytz==2019.1 +sqlparse==0.2.4 +typing-extensions==3.7.4.3 +Unidecode==1.0.23 diff --git a/templates/base.html b/templates/base.html index 0ae254d..c10f2ab 100644 --- a/templates/base.html +++ b/templates/base.html @@ -31,7 +31,7 @@ Survex-204 | Survex | All Survex | - Scans | + Scans | Drawings | 290 (FGH) | 291 (GSH) | diff --git a/templates/dwgfiles.html b/templates/dwgfiles.html index a89bca3..d850976 100644 --- a/templates/dwgfiles.html +++ b/templates/dwgfiles.html @@ -17,8 +17,8 @@ {{dwgfile.npaths}} - {% for scansfolder in dwgfile.manywallets.all %} - {{scansfolder.walletname}} + {% for scanswallet in dwgfile.manywallets.all %} + {{scanswallet.walletname}} {% endfor %} diff --git a/templates/expowebbase.html b/templates/expowebbase.html index 5261e8a..097c4e0 100644 --- a/templates/expowebbase.html +++ b/templates/expowebbase.html @@ -17,7 +17,7 @@ {% if cavepage %}