mirror of
https://expo.survex.com/repositories/troggle/.git
synced 2024-11-25 08:41:51 +00:00
Drawing files upload form
This commit is contained in:
parent
9ae2e18fe6
commit
90bb0759a0
@ -51,7 +51,7 @@ def dwgfilesingle(request, path):
|
||||
|
||||
|
||||
def dwgfileupload(request, path):
|
||||
'''uploads a drawing file, but where is the Form? This just processes POST info. Apparently unfinished?
|
||||
'''Use bits of this to REGISTEr a recently uploaded dwg file which used dwgupload
|
||||
'''
|
||||
try:
|
||||
dwgfile = DrawingFile.objects.get(dwgpath=urlunquote(path)) # need to check if inavlid query string and produce friendly error
|
||||
|
@ -194,19 +194,12 @@ def exportlogbook(request,year=None,extension=None):
|
||||
return render(request,'controlPanel.html', {'expeditions':Expedition.objects.all(),'jobs_completed':[completed]})
|
||||
|
||||
|
||||
# def ajax_test(request):
|
||||
# post_text = request.POST['post_data']
|
||||
# return HttpResponse("{'response_text': '"+post_text+" recieved.'}",
|
||||
# content_type="application/json")
|
||||
|
||||
|
||||
|
||||
class FilesForm(forms.Form): # not a model-form, just a form-form
|
||||
scanfiles = forms.FileField()
|
||||
|
||||
@login_required_if_public
|
||||
def scanupload(request, wallet=None):
|
||||
'''Upload one scanned image file into a wallet on /expofiles
|
||||
'''Upload scanned image files into a wallet on /expofiles
|
||||
This does NOT use a Django model linked to a Django form. Just a simple Django form.
|
||||
'''
|
||||
filesaved = False
|
||||
@ -275,3 +268,70 @@ def scanupload(request, wallet=None):
|
||||
|
||||
return render(request, 'scanuploadform.html',
|
||||
{'form': form, 'wallet': wallet, **context, 'files': files, 'dirs': dirs, 'filesaved': filesaved, 'actual_saved': actual_saved})
|
||||
|
||||
@login_required_if_public
|
||||
def dwgupload(request, folder=None):
|
||||
'''Upload DRAWING files (tunnel or therion) into the upload folder in :drawings:
|
||||
This does NOT use a Django model linked to a Django form. Just a simple Django form.
|
||||
'''
|
||||
def dwgvalid(name):
|
||||
if name in [ '.gitignore', '.hgignore', ]:
|
||||
return False
|
||||
if Path(name).suffix in ['.xml', '.th', '.th2', '', '.svg', '.jpg']:
|
||||
return True
|
||||
return False
|
||||
|
||||
filesaved = False
|
||||
actual_saved = []
|
||||
doesnotexist = ''
|
||||
#print(f'! - FORM dwgupload - start "{folder}"')
|
||||
if folder is None:
|
||||
folder = "" # improve this later
|
||||
dirpath = Path(settings.DRAWINGS_DATA)
|
||||
urlfile = '/dwgdataraw'
|
||||
urldir = '/dwgupload'
|
||||
else:
|
||||
dirpath = Path(settings.DRAWINGS_DATA, folder)
|
||||
urlfile = Path('/dwgdataraw/') / folder
|
||||
urldir = Path('/dwgupload/') / folder
|
||||
|
||||
form = FilesForm()
|
||||
|
||||
if request.method == 'POST':
|
||||
form = FilesForm(request.POST,request.FILES)
|
||||
if form.is_valid():
|
||||
f = request.FILES["scanfiles"]
|
||||
multiple = request.FILES.getlist('scanfiles')
|
||||
fs = FileSystemStorage(os.path.join(settings.DRAWINGS_DATA, folder))
|
||||
|
||||
actual_saved = []
|
||||
if multiple:
|
||||
for f in multiple:
|
||||
if dwgvalid(f.name):
|
||||
actual_saved.append( fs.save(f.name, content=f) )
|
||||
# print(f'! - FORM dwgupload multiple {actual_saved}')
|
||||
filesaved = True
|
||||
|
||||
files = []
|
||||
dirs = []
|
||||
#print(f'! - FORM dwgupload - start {folder} \n"{dirpath}" \n"{dirpath.parent}" \n"{dirpath.exists()}"')
|
||||
try:
|
||||
for f in dirpath.iterdir():
|
||||
if f.is_dir():
|
||||
if f.name not in ['.git' ]:
|
||||
dirs.append(f.name)
|
||||
continue
|
||||
if f.is_file():
|
||||
if dwgvalid(f.name):
|
||||
files.append(f.name)
|
||||
continue
|
||||
except FileNotFoundError:
|
||||
doesnotexist = True
|
||||
if files:
|
||||
files = sorted(files)
|
||||
|
||||
if dirs:
|
||||
dirs = sorted(dirs)
|
||||
|
||||
return render(request, 'dwguploadform.html',
|
||||
{'form': form, 'doesnotexist': doesnotexist, 'urlfile': urlfile, 'urldir': urldir,'folder': folder, 'files': files, 'dirs': dirs, 'filesaved': filesaved, 'actual_saved': actual_saved})
|
||||
|
@ -5,6 +5,7 @@ import stat
|
||||
import csv
|
||||
import re
|
||||
import datetime
|
||||
from pathlib import Path
|
||||
|
||||
from PIL import Image
|
||||
from functools import reduce
|
||||
@ -261,6 +262,11 @@ def setdwgfileinfo(dwgfile):
|
||||
|
||||
def load_drawings_files():
|
||||
'''Breadth first search of drawings directory looking for sub-directories and *.xml filesize
|
||||
|
||||
Why do we have all this detection of file types/! Why not use get_mime_types ?
|
||||
What is it all for ??
|
||||
|
||||
ALL THIS NEEDS TO DETCT UPPER CASE suffices
|
||||
'''
|
||||
all_xml = []
|
||||
drawdatadir = settings.DRAWINGS_DATA
|
||||
@ -294,6 +300,26 @@ def load_drawings_files():
|
||||
dwgfile = DrawingFile(dwgpath=lf, dwgname=os.path.split(f[:-4])[1])
|
||||
dwgfile.save()
|
||||
all_xml.append(('th2',dwgfile))
|
||||
elif f[-4:] == ".pdf":
|
||||
# Always creates new
|
||||
dwgfile = DrawingFile(dwgpath=lf, dwgname=os.path.split(f[:-4])[1])
|
||||
dwgfile.save()
|
||||
all_xml.append(('pdf',dwgfile))
|
||||
elif f[-4:] == ".svg":
|
||||
# Always creates new
|
||||
dwgfile = DrawingFile(dwgpath=lf, dwgname=os.path.split(f[:-4])[1])
|
||||
dwgfile.save()
|
||||
all_xml.append(('svg',dwgfile))
|
||||
elif f[-4:] == ".jpg":
|
||||
# Always creates new
|
||||
dwgfile = DrawingFile(dwgpath=lf, dwgname=os.path.split(f[:-4])[1])
|
||||
dwgfile.save()
|
||||
all_xml.append(('jpg',dwgfile))
|
||||
elif Path(f).suffix == '':
|
||||
# therion file
|
||||
dwgfile = DrawingFile(dwgpath=lf, dwgname=os.path.split(f)[1])
|
||||
dwgfile.save()
|
||||
all_xml.append(('',dwgfile))
|
||||
|
||||
print(f' - {len(all_xml)} Drawings files found')
|
||||
|
||||
|
@ -23,6 +23,6 @@
|
||||
{% endblock content %}
|
||||
|
||||
{% block margins %}
|
||||
<img src="{{ settings.MEDIA_URL }}eieshole.jpg">
|
||||
<img src="{{ settings.MEDIA_URL }}goesser.jpg">
|
||||
<img src="{{ settings.MEDIA_URL }}/eieshole.jpg">
|
||||
<img src="{{ settings.MEDIA_URL }}/goesser.jpg">
|
||||
{% endblock margins %}
|
63
templates/dwguploadform.html
Normal file
63
templates/dwguploadform.html
Normal file
@ -0,0 +1,63 @@
|
||||
{% extends "base.html" %}
|
||||
|
||||
{% block title %}Simple Fileupload{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
|
||||
<h2>Upload drawing file into folder '{{folder}}'</h2>
|
||||
<p style="font-family: monospace; font-weight: bold; font-size: 130%; text-align: center">
|
||||
<div style = "max-width:35%; margin-left:20%; text-align: center; " >
|
||||
<form method ='post' enctype ="multipart/form-data">
|
||||
{% csrf_token %}
|
||||
<br>
|
||||
<input class="fancybutton" type = "file" multiple="multiple"
|
||||
placeholder = "Scanfiles" name = "scanfiles" id="scanfiles" />
|
||||
|
||||
<br><br><br>
|
||||
<button class="fancybutton" style="padding: 0.5em 25px; margin-left: 155px" type = "submit" value = "Upload" >
|
||||
Upload
|
||||
</button>
|
||||
</form>
|
||||
</div>
|
||||
<div style = "max-width:70%; margin-left:20%; text-align: left" >
|
||||
<p>Only drawings and drawing config files can be uploaded.
|
||||
</div>
|
||||
<div style = "max-width:70%; margin-left:20%; text-align: left" >
|
||||
{% if filesaved %}
|
||||
<p>
|
||||
<b>Drawing(s) saved as <br>
|
||||
{% for f in actual_saved %}
|
||||
<em>{{f}}</em> <br>
|
||||
{% endfor %}
|
||||
<br><br>Upload more?</b>
|
||||
</p>
|
||||
<br>
|
||||
{% endif %}
|
||||
|
||||
{% if doesnotexist %}
|
||||
<p>No folder of this name.<br>
|
||||
It would be created if you upload a file.
|
||||
{% else %}
|
||||
<strong style="font-size: 110%;">Files:</strong><br>
|
||||
{% for f in files %}
|
||||
<a href="{{urlfile|urlencode}}/{{f|urlencode}}">{{f}}</a><br />
|
||||
{% empty %}
|
||||
<p><No files here>
|
||||
{% endfor %}
|
||||
|
||||
|
||||
<p><strong style="font-size: 110%;">Directories:</strong><br>
|
||||
{% if folder %}
|
||||
<a href="{{urldir}}/..">[up]</a><br />
|
||||
{% endif %}
|
||||
{% for f in dirs %}
|
||||
<a href="{{urldir}}/{{f}}">/{{f}}/</a><br />
|
||||
{% empty %}
|
||||
<p><No subdirectories>
|
||||
{% endfor %}
|
||||
<p>Clicking on a filename only works if the drawing file has been imported into the system as part of a bulk-import
|
||||
as we are matching it against a file recorded in the database.
|
||||
{% endif %}
|
||||
</div>
|
||||
|
||||
{% endblock %}
|
@ -43,7 +43,7 @@ div#editLinks a{
|
||||
<li>You can log on or log off using the gray menu bar above.
|
||||
</ul>
|
||||
|
||||
<p>Did you get lost ?
|
||||
<p>Did you get lost ?</p>
|
||||
|
||||
<img align=center src="/handbook/i/204-area.png">
|
||||
{% include "menu.html" %}
|
||||
|
8
urls.py
8
urls.py
@ -10,7 +10,9 @@ from django.urls import reverse, resolve
|
||||
|
||||
from troggle.core.views import caves, statistics, survex
|
||||
from troggle.core.views.scans import scansingle, singlewallet, allwallets
|
||||
from troggle.core.views.drawings import dwgdata, dwgfilesingle, dwgfileupload
|
||||
from troggle.core.views.drawings import dwgdata, dwgfilesingle
|
||||
from troggle.core.views.drawings import dwgfileupload
|
||||
from troggle.core.views.other import dwgupload
|
||||
from troggle.core.views.other import troggle404, frontpage, todos, controlpanel, frontpage, scanupload
|
||||
from troggle.core.views.other import exportlogbook
|
||||
from troggle.core.views.caves import ent, cavepage
|
||||
@ -80,6 +82,8 @@ trogglepatterns = [
|
||||
re_path(r'^admin/', admin.site.urls), # includes admin login & logout urls
|
||||
|
||||
path('scanupload/<wallet>', scanupload, name='scanupload'),
|
||||
path('dwgupload/<path:folder>', dwgupload, name='dwgupload'),
|
||||
path('dwgupload/', dwgupload, name='dwgupload'),
|
||||
|
||||
# setting LOGIN_URL = '/accounts/login/' is default
|
||||
# url ENDS WITH this string
|
||||
@ -158,7 +162,7 @@ trogglepatterns = [
|
||||
re_path(r'^dwgdataraw/(?P<path>.+?\.th)$', dwgfilesingle, name="dwgfilesingle"),
|
||||
re_path(r'^dwgdataraw/(?P<path>.+?\.th2)$', dwgfilesingle, name="dwgfilesingle"),
|
||||
# re_path(r'^dwgdatainfo/(?P<path>.+?\.xml)$', dwgfileinfo, name="dwgfileinfo"), # parses tunnel for info & ref to wallet
|
||||
re_path(r'^dwgdataraw/(?P<path>.+?\.xml)/upload$', dwgfileupload, name="dwgfileupload"), # Not working
|
||||
# re_path(r'^dwgdataraw/(?P<path>.+?\.xml)/upload$', dwgfileupload, name="dwgfileupload"), # Not working
|
||||
|
||||
|
||||
# QMs pages - must precede other /caves pages?
|
||||
|
Loading…
Reference in New Issue
Block a user