Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
C
core
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to JiHu GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Chenhao Ma
core
Commits
ac7d76f3
Commit
ac7d76f3
authored
7 years ago
by
Harsha Kethineni
Browse files
Options
Downloads
Patches
Plain Diff
move file count check to finalize()
parent
b6e48be5
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
api/placer.py
+20
-13
20 additions, 13 deletions
api/placer.py
api/upload.py
+0
-2
0 additions, 2 deletions
api/upload.py
with
20 additions
and
15 deletions
api/placer.py
+
20
−
13
View file @
ac7d76f3
...
...
@@ -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
...
...
This diff is collapsed.
Click to expand it.
api/upload.py
+
0
−
2
View file @
ac7d76f3
...
...
@@ -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
()
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment