mirror of
https://expo.survex.com/repositories/troggle/.git
synced 2024-11-28 18:11:52 +00:00
drawing file upload form working
This commit is contained in:
parent
74403d28e9
commit
8f89b022c7
@ -8,7 +8,7 @@ from django.contrib.admin.widgets import AdminDateWidget
|
||||
|
||||
#from tinymce.widgets import TinyMCE
|
||||
|
||||
from troggle.core.models.troggle import Person, PersonExpedition, Expedition
|
||||
from troggle.core.models.troggle import Person, PersonExpedition, Expedition, SimpleFileModel
|
||||
from troggle.core.models.caves import Cave, LogbookEntry, QM, Entrance, CaveAndEntrance
|
||||
|
||||
'''These are all the Forms used by troggle
|
||||
@ -180,3 +180,14 @@ class UploadFileForm(forms.Form):
|
||||
person = forms.ChoiceField([("-----", "Please select an expedition"), ], required=False)
|
||||
|
||||
|
||||
|
||||
class SimpleUploadFileForm(forms.ModelForm):
|
||||
"""New in April 2021
|
||||
"""
|
||||
class Meta:
|
||||
model = SimpleFileModel
|
||||
fields = ('title', 'simplefile',)
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -19,6 +19,7 @@ from django.conf import settings
|
||||
|
||||
from django.urls import reverse
|
||||
from django.template import Context, loader
|
||||
from django.core.files.storage import FileSystemStorage
|
||||
|
||||
import troggle.core.models.survex
|
||||
from troggle.core.utils import get_process_memory
|
||||
@ -222,4 +223,11 @@ class PersonExpedition(TroggleModel):
|
||||
res = self.persontrip_set.all().aggregate(day_max=models.Max("expeditionday__date"))
|
||||
return res["day_max"]
|
||||
|
||||
class SimpleFileModel(models.Model):
|
||||
simplefile = models.FileField(upload_to='fileuploads/') # in MEDIA_FILES
|
||||
title = models.CharField(max_length = 80)
|
||||
class Meta:
|
||||
ordering = ['title']
|
||||
|
||||
def __str__(self):
|
||||
return f"{self.title}"
|
||||
|
@ -1,4 +1,4 @@
|
||||
import re
|
||||
import re, os
|
||||
|
||||
from django import forms
|
||||
from django.conf import settings
|
||||
@ -7,12 +7,13 @@ from django.db.models import Q
|
||||
from django.http import HttpResponse, HttpResponseRedirect
|
||||
from django.shortcuts import render
|
||||
from django.template import Context, loader
|
||||
from django.core.files.storage import FileSystemStorage, default_storage
|
||||
|
||||
import troggle.parsers.imports
|
||||
from troggle.core.models.troggle import Expedition, Person, PersonExpedition
|
||||
from troggle.core.models.caves import LogbookEntry, QM, Cave, PersonTrip
|
||||
from .login import login_required_if_public
|
||||
from troggle.core.forms import UploadFileForm
|
||||
from troggle.core.forms import UploadFileForm, SimpleUploadFileForm
|
||||
|
||||
'''Utility functions and code to serve the control panel and individual user's
|
||||
progress and task list (deprecated as we do not have individual user login).
|
||||
@ -213,4 +214,26 @@ def newfile(request, pslug = None):
|
||||
|
||||
return render(request, 'editfile.html', {'fileForm': fileform, })
|
||||
|
||||
@login_required_if_public
|
||||
def simpleupload(request):
|
||||
print(f'! - FORM simpleupload - start')
|
||||
if request.method == 'POST':
|
||||
form = SimpleUploadFileForm(request.POST,request.FILES)
|
||||
if form.is_valid():
|
||||
#form.save() # comment out so nothing saved in MEDIA_ROOT/fileuploads
|
||||
f = request.FILES["simplefile"]
|
||||
w = request.POST["title"]
|
||||
print(f'! - FORM simpleupload uploaded {f.name}')
|
||||
fs = FileSystemStorage(os.path.join(settings.SURVEY_SCANS, '2021', w))
|
||||
|
||||
actual_saved = fs.save(f.name, content=f) # name may chnage to avoid clash
|
||||
# INSERT check if name is chnaged, to allow user to abort and rename - or lets do a chaecjk anyway.
|
||||
|
||||
print(f'! - FORM simpleupload {actual_saved}')
|
||||
|
||||
form = SimpleUploadFileForm()
|
||||
return render(request, 'simpleupload.html', {'form': form,'filesaved': True, 'actual_saved': actual_saved})
|
||||
else:
|
||||
form = SimpleUploadFileForm()
|
||||
return render(request, 'simpleupload.html', {'form':form,})
|
||||
|
||||
|
@ -1,32 +0,0 @@
|
||||
{% extends "cavebase.html" %}
|
||||
|
||||
|
||||
{% block title %}Cave Index{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
|
||||
<h1>Cave Index</h1>
|
||||
|
||||
<h3>1623</h3>
|
||||
|
||||
<table class="searchable">
|
||||
{% for cave in caves1623 %}
|
||||
|
||||
<tr><td> <a href="{{ cave.url }}">{% if cave.kataster_number %}{{ cave.kataster_number }}{% else %}{{cave.unofficial_number }}{%endif %} {{cave.official_name|safe}}</a> </td></tr>
|
||||
|
||||
{% endfor %}
|
||||
</table>
|
||||
|
||||
<h3>1626</h3>
|
||||
|
||||
<ul class="searchable">
|
||||
{% for cave in caves1626 %}
|
||||
|
||||
<li> <a href="{{ cave.url }}">{% if cave.kataster_number %}{{ cave.kataster_number }}{% else %}{{cave.unofficial_number }}{%endif %} {{cave.official_name|safe}}</a> </li>
|
||||
|
||||
{% endfor %}
|
||||
</ul>
|
||||
|
||||
<a href="{% url "newcave" %}">New Cave</a>
|
||||
|
||||
{% endblock %}
|
50
templates/simpleupload.html
Normal file
50
templates/simpleupload.html
Normal file
@ -0,0 +1,50 @@
|
||||
{% extends "base.html" %}
|
||||
|
||||
{% block title %}Simple Fileupload{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
|
||||
<h2>Survey Scan upload into Wallet</h2>
|
||||
|
||||
<div style = "max-width:470px; " >
|
||||
|
||||
|
||||
{% if filesaved %}
|
||||
<p style="margin-left:20%;">
|
||||
<b>The file was saved as <em>'{{actual_saved}}'</em> <br><br>Upload another?</b>
|
||||
</p>
|
||||
<br>
|
||||
{% endif %}
|
||||
|
||||
|
||||
<form method ='post' enctype ="multipart/form-data">
|
||||
{% csrf_token %}
|
||||
|
||||
|
||||
<br>
|
||||
|
||||
|
||||
<input type = "file" style = "margin-left:20%;"
|
||||
placeholder = "Simplefile" name = "simplefile" />
|
||||
|
||||
<br> <br>
|
||||
|
||||
|
||||
<input type = "text" style = "margin-left:20%;"
|
||||
placeholder = "Wallet id e.g. 2021#23" name = "title" value='2021#99' label="Wallet id"/>
|
||||
|
||||
</div>
|
||||
|
||||
<div style = "max-width:470px;">
|
||||
<center>
|
||||
|
||||
<button style = "color: #fff; border:1px; background-color:#999; margin-top:8%;
|
||||
height:35px; width:80%; margin-left:19%;" type = "submit" value = "Upload" >
|
||||
<strong>Upload</strong>
|
||||
</button>
|
||||
|
||||
</center>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
{% endblock %}
|
10
urls.py
10
urls.py
@ -1,4 +1,5 @@
|
||||
from django.conf import settings
|
||||
from django.urls import path
|
||||
from django.conf.urls import url, include, re_path
|
||||
from django.views.generic.base import RedirectView
|
||||
from django.views.generic.edit import UpdateView
|
||||
@ -9,7 +10,8 @@ from django.urls import reverse, resolve
|
||||
|
||||
from troggle.core.views import caves, statistics, survex
|
||||
from troggle.core.views.surveys import surveyscansingle, surveyscansfolder, surveyscansfolders, dwgdata, dwgfilesingle, dwgfileupload
|
||||
from troggle.core.views.other import troggle404, frontpage, todos, controlpanel, frontpage, newfile, downloadlogbook, ajax_QM_number, downloadQMs
|
||||
from troggle.core.views.other import troggle404, frontpage, todos, controlpanel, frontpage, newfile, simpleupload
|
||||
from troggle.core.views.other import downloadlogbook, ajax_QM_number, downloadQMs
|
||||
from troggle.core.views.caves import ent, cavepage
|
||||
from troggle.core.views.logbooks import get_logbook_entries, logbookentry, logbookSearch
|
||||
from troggle.core.views.logbooks import personindex, person, get_people
|
||||
@ -73,6 +75,8 @@ trogglepatterns = [
|
||||
re_path(r'^admin/doc/', include('django.contrib.admindocs.urls')), # needs docutils Python module (http://docutils.sf.net/).
|
||||
re_path(r'^admin/', admin.site.urls), # includes admin login & logout urls
|
||||
|
||||
path('upload', simpleupload, name='simpleupload'), # includes admin login & logout urls
|
||||
|
||||
# setting LOGIN_URL = '/accounts/login/' is default
|
||||
# url ENDS WITH this string
|
||||
re_path(r'logout/$', expologout, name='expologout'), # higher precedence than /accounts/logout
|
||||
@ -83,7 +87,7 @@ trogglepatterns = [
|
||||
re_path(r'^person/(?P<first_name>[A-Z]*[a-z\-\'&;]*)[^a-zA-Z]*(?P<last_name>[a-z\-\']*[^a-zA-Z]*[\-]*[A-Z]*[a-zA-Z\-&;]*)/?', person, name="person"),
|
||||
re_path(r'^personexpedition/(?P<first_name>[A-Z]*[a-z&;]*)[^a-zA-Z]*(?P<last_name>[A-Z]*[a-zA-Z&;]*)/(?P<year>\d+)/?$', personexpedition, name="personexpedition"),
|
||||
|
||||
# Expedition master page
|
||||
# Expedition master page & API exports
|
||||
re_path(r'^expedition/(\d+)$', expedition, name="expedition"),
|
||||
re_path(r'^api/expeditions_tsv$', Expeditions_tsvListView.as_view()),
|
||||
re_path(r'^api/expeditions_json$', Expeditions_jsonListView.as_view()),
|
||||
@ -161,7 +165,7 @@ trogglepatterns = [
|
||||
|
||||
# Prospecting Guide document
|
||||
re_path(r'^prospecting_guide/$', prospecting),
|
||||
re_path(r'^prospecting/(?P<name>[^.]+).png$', prospecting_image, name="prospecting_image"),
|
||||
# re_path(r'^prospecting/(?P<name>[^.]+).png$', prospecting_image, name="prospecting_image"), broken, won't repair.
|
||||
|
||||
# This next set are all intercepted by Apache, if it is running.
|
||||
re_path(r'^photos/(?P<subpath>.*)$', mediapage, {'doc_root': settings.PHOTOS_ROOT}, name="mediapage"), # photo galleries
|
||||
|
Loading…
Reference in New Issue
Block a user