Skip to content
Snippets Groups Projects
Commit ac7d76f3 authored by Harsha Kethineni's avatar Harsha Kethineni
Browse files

move file count check to finalize()

parent b6e48be5
No related branches found
No related tags found
No related merge requests found
......@@ -142,6 +142,7 @@ class UIDPlacer(Placer):
super(UIDPlacer, self).__init__(container_type, container, id_, metadata, timestamp, origin, context)
self.metadata_for_file = {}
self.session_id = None
self.count = 0
def check(self):
self.requireMetadata()
......@@ -150,22 +151,25 @@ class UIDPlacer(Placer):
metadata_validator = validators.from_schema_path(payload_schema_uri)
metadata_validator(self.metadata, 'POST')
# If not a superuser request, pass uid of user making the upload request
targets = self.create_hierarchy(self.metadata, type_=self.match_type, user=self.context.get('uid'))
self.metadata_for_file = {}
for target in targets:
if target[0].level is 'session':
self.session_id = target[0].id_
for name in target[1]:
self.metadata_for_file[name] = {
'container': target[0],
'metadata': target[1][name]
}
def process_file_field(self, field, file_attrs):
# Only create the hierarchy once
if self.count == 0:
# If not a superuser request, pass uid of user making the upload request
targets = self.create_hierarchy(self.metadata, type_=self.match_type, user=self.context.get('uid'))
self.metadata_for_file = {}
for target in targets:
if target[0].level is 'session':
self.session_id = target[0].id_
for name in target[1]:
self.metadata_for_file[name] = {
'container': target[0],
'metadata': target[1][name]
}
self.count += 1
# For the file, given self.targets, choose a target
name = field.filename
......@@ -195,6 +199,9 @@ class UIDPlacer(Placer):
self.saved.append(file_attrs)
def finalize(self):
# Check that there is at least one file being uploaded
if self.count < 1:
raise FileFormException("No files selected for upload")
if self.session_id:
self.container_type = 'session'
self.id_ = self.session_id
......
......@@ -94,8 +94,6 @@ def process_upload(request, strategy, container_type=None, id_=None, origin=None
# Ref docs from placer.TargetedPlacer for details.
if strategy == Strategy.targeted and len(file_fields) > 1:
raise FileFormException("Targeted uploads can only send one file")
elif strategy in [Strategy.reaper, Strategy.uidupload, Strategy.labelupload, Strategy.uidmatch] and len(file_fields) < 1:
raise FileFormException("No files selected for uploading")
placer.check()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment