summaryrefslogtreecommitdiffstats
path: root/core/views/uploads.py
diff options
context:
space:
mode:
authorPhilip Sargent <philip.sargent@klebos.com>2022-08-11 21:19:52 +0300
committerPhilip Sargent <philip.sargent@klebos.com>2022-08-11 21:19:52 +0300
commit3607b9f1409c4e4d176f457f63739670c88b4951 (patch)
treef9ce6718a12a6984bf9b52b579ab3c13c463e98e /core/views/uploads.py
parent25c425cff8890f28a7c8038f78c3c0bbc9cbe97f (diff)
downloadtroggle-3607b9f1409c4e4d176f457f63739670c88b4951.tar.gz
troggle-3607b9f1409c4e4d176f457f63739670c88b4951.tar.bz2
troggle-3607b9f1409c4e4d176f457f63739670c88b4951.zip
enable photo file rename
Diffstat (limited to 'core/views/uploads.py')
-rw-r--r--core/views/uploads.py36
1 files changed, 30 insertions, 6 deletions
diff --git a/core/views/uploads.py b/core/views/uploads.py
index 9bb37cd..619ea90 100644
--- a/core/views/uploads.py
+++ b/core/views/uploads.py
@@ -59,7 +59,11 @@ todo = '''
class FilesForm(forms.Form): # not a model-form, just a form-form
uploadfiles = forms.FileField()
-
+
+class FilesRenameForm(forms.Form): # not a model-form, just a form-form
+ uploadfiles = forms.FileField()
+ renameto = forms.CharField(strip=True)
+
class TextForm(forms.Form): # not a model-form, just a form-form
photographer = forms.CharField(strip=True)
@@ -443,6 +447,13 @@ def photoupload(request, folder=None):
'''Upload photo image files into /expofiles/photos/<year>/<photographer>/
This does NOT use a Django model linked to a Django form. Just a simple Django form.
You will find the Django documentation on forms very confusing, This is simpler.
+
+
+ When uploading from a phone, it is useful to be able to rename the file to something
+ meaningful as this is difficult to do on a phone. Previously we had assumed files would
+ be renamed to something useful before starting the upload.
+ Unfortunately this only works when uploading one file at at time ,
+ inevitable once you think about it.
'''
year = settings.PHOTOS_YEAR
filesaved = False
@@ -472,7 +483,7 @@ def photoupload(request, folder=None):
urldir = f'/photoupload/{year}'
- form = FilesForm()
+ form = FilesRenameForm()
formd = TextForm()
if request.method == 'POST':
@@ -482,24 +493,37 @@ def photoupload(request, folder=None):
newphotographer = request.POST["photographer"]
(yearpath / newphotographer).mkdir(exist_ok=True)
else:
- form = FilesForm(request.POST,request.FILES)
+ form = FilesRenameForm(request.POST,request.FILES)
if form.is_valid():
f = request.FILES["uploadfiles"]
multiple = request.FILES.getlist('uploadfiles')
# NO CHECK that the files being uploaded are image files
fs = FileSystemStorage(dirpath)
+
+ renameto = request.POST["renameto"]
actual_saved = []
if multiple:
- for f in multiple:
+ if len(multiple) == 1:
try: # crashes in Django os.chmod call if on WSL, but does save file!
- saved_filename = fs.save(f.name, content=f)
+ saved_filename = fs.save(renameto, content=f)
except:
print(f'\n !! Permissions failure ?! on attempting to save file {f.name}')
if 'saved_filename' in locals():
if saved_filename.is_file():
actual_saved.append(saved_filename)
filesaved = True
+
+ else:
+ for f in multiple:
+ try: # crashes in Django os.chmod call if on WSL, but does save file!
+ saved_filename = fs.save(f.name, content=f)
+ except:
+ print(f'\n !! Permissions failure ?! on attempting to save file {f.name}')
+ if 'saved_filename' in locals():
+ if saved_filename.is_file():
+ actual_saved.append(saved_filename)
+ filesaved = True
files = []
dirs = []
try:
@@ -527,7 +551,7 @@ def dwgupload(request, folder=None, gitdisable='no'):
This does NOT use a Django model linked to a Django form. Just a simple Django form.
You will find the Django documentation on forms very confusing, This is simpler.
- Need to validate it as being a valid GPX file using an XML parser, not a dubious script or hack
+ We could validate the uploaded files as being a valid files using an XML parser, not a dubious script or hack
We use get_or_create instead of simply creating a new object in case someone uploads the same file