use new upload page for most wallets

This commit is contained in:
Philip Sargent
2022-03-18 11:28:35 +00:00
parent e4ee4abce8
commit af7fc8f243
5 changed files with 145 additions and 121 deletions

View File

@@ -20,11 +20,14 @@ need to check if inavlid query string is invalid, or produces multiple replies
and render a user-friendly error page.
'''
def singlewallet(request, path):
#print [ s.walletname for s in Wallet.objects.all() ]
def oldwallet(request, path):
'''Now called only for non-standard wallet structures for pre-2000 wallets
'''
# print([ s.walletname for s in Wallet.objects.all() ])
print(f'! - oldwallet path:{path}')
try:
wallet = Wallet.objects.get(walletname=urlunquote(path))
return render(request, 'wallet.html', { 'wallet':wallet, 'settings': settings })
return render(request, 'wallet_old.html', { 'wallet':wallet, 'settings': settings })
except:
message = f'Scan folder error or not found \'{path}\' .'
return render(request, 'errors/generic.html', {'message': message})

View File

@@ -2,6 +2,7 @@ import re, os
import subprocess
import json
import settings
import urllib
from pathlib import Path
@@ -15,6 +16,7 @@ from django.shortcuts import render
from django.template import Context, loader
from django.core.files.storage import FileSystemStorage, default_storage
#from troggle import settings
from troggle.parsers.imports import import_caves, import_people, import_surveyscans
from troggle.parsers.imports import import_logbooks, import_QMs, import_drawingsfiles, import_survex
@@ -24,6 +26,8 @@ from troggle.core.models.troggle import DataIssue
from troggle.core.models.troggle import Expedition, Person, PersonExpedition
from troggle.core.models.caves import LogbookEntry, QM, Cave, PersonTrip
from troggle.core.models.survex import DrawingFile
from troggle.core.views.scans import oldwallet
from .auth import login_required_if_public
#from django.views.decorators.csrf import ensure_csrf_cookie, csrf_exempt
@@ -88,7 +92,7 @@ xlate = {"url": "description url",
}
@login_required_if_public
def scanupload(request, wallet=None):
def scanupload(request, path=None):
'''Upload scanned image files into a wallet on /expofiles
Also display and edit the contents.json data in the wallet.
@@ -100,14 +104,22 @@ def scanupload(request, wallet=None):
checkboxes = ["description written", "survex not required", "qms written", "website updated",
"plan not required", "plan drawn", "elev not required", "elev drawn", "electronic survey" ]
# print(f'! - FORM scanupload - start {wallet}')
if wallet is None:
wallet = "2021#01" # improve this later
if not re.match('(19|20)\d\d:\d\d', wallet):
wallet = "2021:01" # improve this later
if path:
wallet = urllib.parse.unquote(path)
else:
wallet = "2022#01" # improve this later
year = wallet[:4]
if int(year) <= 1999:
print(f'! - FORM scanupload - start {wallet} REDIRECT TO OLDWALLET')
return(oldwallet(request, path))
if not re.match('(19|20)\d\d[:#]\d\d', wallet):
wallet = "2022:01" # improve this later
print(f'! - FORM scanupload - start {wallet}')
if path:
print(f'! - FORM scanupload - start wallet:{wallet}: path:{path}:')
if int(year) < 1977:
year = "1977"
if int(year) > 2050:
@@ -115,6 +127,7 @@ def scanupload(request, wallet=None):
nexty = f'{int(year)+1}'
prevy = f'{int(year)-1}'
wnumber = wallet[5:]
next = f'{int(wnumber)+1:02d}'
prev = f'{int(wnumber)-1:02d}'

View File

@@ -57,6 +57,7 @@
</div>
<hr />
{% if not create %}
<br>
<span style="font-family: monospace; font-size: 150%; ">
{% if cave %}<u>Cave ID</u>: <b>{{cave}}</b><br> {% endif %}
@@ -160,4 +161,5 @@ input {font-family: monospace; font-weight: bold; font-size: 100%; padding: 0.5e
</button>
</form>
</div>
{% endif %} <!-- not create -->
{% endblock %}

View File

@@ -2,7 +2,9 @@
{% block title %}Survey Scans Wallet {% endblock %}
{% block content %}
<h3>Survey Scans in: {{wallet.walletname}}</h3>
<h3>Survey Scans in old wallet: {{wallet.walletname}}</h3>
<p>Wallets of 1999 and earlier are in a different structure and have not yet been edited to conform to the current
name format and folder structure.
<table>
{% for singlescan in wallet.singlescan_set.all %}
<tr>
@@ -17,7 +19,9 @@
</table>
<h3>Survex surveys referring to this wallet</h3>
<p><b>*ref</b> references have not been configured in most old survex files,
so it is unlikley that you will see anything here. To find survex files for this year look in the
survex column of the <a href="/expedition/1999">expedition page</a>.
<table>
{% for survexblock in wallet.survexblock_set.all %}
<tr>

18
urls.py
View File

@@ -8,7 +8,7 @@ from django.contrib import auth
from django.urls import path, reverse, resolve
from troggle.core.views import caves, statistics, survex
from troggle.core.views.scans import scansingle, singlewallet, allwallets
from troggle.core.views.scans import scansingle, allwallets
from troggle.core.views.drawings import dwgallfiles, dwgfilesingle
from troggle.core.views.uploads import dwgupload, scanupload, photoupload
from troggle.core.views.other import troggle404, frontpage, todos, controlpanel, frontpage
@@ -86,7 +86,8 @@ trogglepatterns = [
re_path(r'^admin/', admin.site.urls), # includes admin login & logout urls
# Uploads - uploading a file
path('scanupload/<wallet>', scanupload, name='scanupload'), # wallet=2020#01, not a path
path('scanupload/', scanupload, name='scanupload'), # path=2020#01
path('scanupload/<path:path>', scanupload, name='scanupload'), # path=2020#01
path('photoupload/', photoupload, name='photoupload'), # restricted to current year
path('photoupload/<path:folder>', photoupload, name='photoupload'), # restricted to current year
path('dwgupload/<path:folder>', dwgupload, name='dwgupload'),
@@ -94,7 +95,8 @@ trogglepatterns = [
path('dwguploadnogit/', dwgupload, {'gitdisable': 'yes'}, name='dwguploadnogit'), # used in testing
path('dwguploadnogit/<path:folder>', dwgupload, {'gitdisable': 'yes'}, name='dwguploadnogit'), # used in testing
# setting LOGIN_URL = '/accounts/login/' is default
# setting LOGIN_URL = '/accounts/login/' is default.
# NB setting url pattern name to 'login' instea dof 'expologin' with override Django, see https://docs.djangoproject.com/en/4.0/topics/http/urls/#naming-url-patterns
path('accounts/logout/', expologout, name='expologout'), # same as in django.contrib.auth.urls
path('accounts/login/', expologin, name='expologin'), # same as in django.contrib.auth.urls
#re_path(r'^accounts/', include('django.contrib.auth.urls')), # see site-packages\registration\auth_urls_classes.py
@@ -124,13 +126,13 @@ trogglepatterns = [
re_path(r'^newcave/$', caves.edit_cave, name="newcave"),
re_path(r'^cave/3d/(?P<cave_id>[^/]+)$', caves.cave3d, name="cave3d"),
re_path(r'^cave/description/([^/]+)/?$', caves.caveDescription),
re_path(r'^cave/description/([^/]+)/?$', caves.caveDescription), #!!!BAD, local links fail..
re_path(r'^cave/(?P<cave_id>[^/]+)/?$', caves.cave, name="cave"), #!!!BAD, local links fail.. to be checked..
re_path(r'^cave/(?P<cave_id>[^/]+)/?(?P<ent_letter>[^/])$', ent), # view_caves.ent
re_path(r'^cave/(?P<cave_id>[^/]+)/?(?P<ent_letter>[^/])$', ent), #!!!BAD, local links fail..# view_caves.ent
re_path(r'^cave/(?P<slug>[^/]+)/edit/$', caves.edit_cave, name="edit_cave"),
re_path(r'^(?P<karea>\d\d\d\d)(?P<subpath>.*)$', cavepage, name="cavepage"), # shorthand /1623/264 BUT url links break! Stop this..
# Note that urls eg '1623/161/l/rl89a.htm' are handled by cavepage which redirects them to 'expopage'
# Note that _edit$ for a cave description page in a subfolder e.g. /1623/via204.html_edit gets caught here and breaks with 404
# Note that urls eg '/1623/161/l/rl89a.htm' are handled by cavepage which redirects them to 'expopage'
# Note that _edit$ for a cave description page in a subfolder e.g. /1623/204/204.html_edit gets caught here and breaks with 404
# Entrances
re_path(r'^cave/entrance/([^/]+)/?$', caves.caveEntrance), # lists all entrances !!!BAD, local links fail
@@ -163,7 +165,7 @@ trogglepatterns = [
# The survey scans in the wallets
path('survey_scans/', allwallets, name="allwallets"),
path('survey_scans/<path:path>/', singlewallet, name="singlewallet"),
path('survey_scans/<path:path>/', scanupload, name="singlewallet"), # replaced singlewallet()
path('survey_scans/<path:path>/<file>', scansingle, name="scansingle"),
# The tunnel and therion drawings files pages