forked from expo/troggle
enable photo file rename
This commit is contained in:
parent
25c425cff8
commit
3607b9f140
@ -60,6 +60,10 @@ 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,15 +493,28 @@ 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:
|
||||
if len(multiple) == 1:
|
||||
try: # crashes in Django os.chmod call if on WSL, but does save file!
|
||||
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)
|
||||
@ -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
|
||||
|
@ -19,6 +19,13 @@
|
||||
<input class="fancybutton2" type = "file" multiple="multiple"
|
||||
name = "uploadfiles" id="uploadfiles" />
|
||||
<br><br><br>
|
||||
<input class="fancybutton2" style="padding: 0.5em 25px; margin-left: 125px"
|
||||
label = "Rename to" name = "renameto" id="renameto"
|
||||
pattern="[A-Za-z][A-Za-z0-9_-\.]*"/>
|
||||
<label
|
||||
style="padding: 0.5em 25px; margin-left: 110px"
|
||||
for="renameto">If uploading a single file, you can rename it<br></label>
|
||||
<br><br><br>
|
||||
<button class="fancybutton2" style="padding: 0.5em 25px; margin-left: 155px" type = "submit" value = "Upload" >
|
||||
Upload
|
||||
</button>
|
||||
|
Loading…
Reference in New Issue
Block a user