diff --git a/core/forms.py b/core/forms.py index 977e664..1f0d3e0 100644 --- a/core/forms.py +++ b/core/forms.py @@ -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',) + + + + diff --git a/core/models/troggle.py b/core/models/troggle.py index 927ee44..10c982c 100644 --- a/core/models/troggle.py +++ b/core/models/troggle.py @@ -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}" diff --git a/core/views/other.py b/core/views/other.py index 4f27d98..639ea5f 100644 --- a/core/views/other.py +++ b/core/views/other.py @@ -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,}) diff --git a/templates/cavemillenial.html b/templates/cavemillenial.html deleted file mode 100644 index 6c96ed8..0000000 --- a/templates/cavemillenial.html +++ /dev/null @@ -1,32 +0,0 @@ -{% extends "cavebase.html" %} - - -{% block title %}Cave Index{% endblock %} - -{% block content %} - -

Cave Index

- -

1623

- - -{% for cave in caves1623 %} - - - -{% endfor %} -
{% if cave.kataster_number %}{{ cave.kataster_number }}{% else %}{{cave.unofficial_number }}{%endif %} {{cave.official_name|safe}}
- -

1626

- - - -New Cave - -{% endblock %} diff --git a/templates/simpleupload.html b/templates/simpleupload.html new file mode 100644 index 0000000..d97234c --- /dev/null +++ b/templates/simpleupload.html @@ -0,0 +1,50 @@ +{% extends "base.html" %} + +{% block title %}Simple Fileupload{% endblock %} + +{% block content %} + +

Survey Scan upload into Wallet

+ +
+ + +{% if filesaved %} +

+The file was saved as '{{actual_saved}}'

Upload another?
+

+
+{% endif %} + + +
+ {% csrf_token %} + + +
+ + + + +

+ + + + +
+ +
+
+ + + +
+
+ + + {% endblock %} diff --git a/urls.py b/urls.py index 23e21e6..db9894e 100644 --- a/urls.py +++ b/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[A-Z]*[a-z\-\'&;]*)[^a-zA-Z]*(?P[a-z\-\']*[^a-zA-Z]*[\-]*[A-Z]*[a-zA-Z\-&;]*)/?', person, name="person"), re_path(r'^personexpedition/(?P[A-Z]*[a-z&;]*)[^a-zA-Z]*(?P[A-Z]*[a-zA-Z&;]*)/(?P\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[^.]+).png$', prospecting_image, name="prospecting_image"), +# re_path(r'^prospecting/(?P[^.]+).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.*)$', mediapage, {'doc_root': settings.PHOTOS_ROOT}, name="mediapage"), # photo galleries