forked from expo/troggle
drawing file upload form working
This commit is contained in:
@@ -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,})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user