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 %} - -
{% if cave.kataster_number %}{{ cave.kataster_number }}{% else %}{{cave.unofficial_number }}{%endif %} {{cave.official_name|safe}} |
+The file was saved as '{{actual_saved}}'
Upload another?
+