portal-oddajanje-solar/portal/solar.py
2021-05-05 14:26:26 +02:00

42 lines
1.2 KiB
Python

import portal.base
def handle_upload(request, upload_handler):
files = request.files
if len(files) > upload_handler.MAX_FILES_PER_UPLOAD:
return 'Naložite lahko do {} datotek hkrati.'.format(upload_handler.MAX_FILES_PER_UPLOAD), 400
elif len(files) < 1:
return 'Priložena ni bila nobena datoteka.', 400
err = portal.base.check_suffixes(files)
if err:
return err, 400
err = check_form(request.form)
if err:
return err, 400
# Parse request.
upload_metadata = upload_handler.extract_upload_metadata(corpus_name, request)
logging.info('Upload from user "{}" with upload id "{}" supplied form data: {}'.format(
request.user,
upload_metadata['upload_id'],
str(upload_metadata['form_data']
)))
# Store uploaded files to disk.
upload_handler.store_datafiles(files, upload_metadata)
# Store metadata to database.
upload_handler.store_metadata_solar(upload_metadata)
# Send confirmation mail along with the contract to the submitted email address.
upload_handler.send_confirm_mail(upload_metadata)
return 'Uspešno ste oddali datotek(e). Št. datotek: {}'.format(len(files))
def check_form(form):
pass