Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
Sage Validation
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
geant-swd
Sage Validation
Commits
b6700474
Commit
b6700474
authored
2 months ago
by
Neda Moeini
Browse files
Options
Downloads
Patches
Plain Diff
Validate Source and TraderType values.
parent
17e2f68a
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
sage_validation/file_validator/forms.py
+19
-1
19 additions, 1 deletion
sage_validation/file_validator/forms.py
with
19 additions
and
1 deletion
sage_validation/file_validator/forms.py
+
19
−
1
View file @
b6700474
"""
Forms for the file_validator app.
"""
import
csv
from
collections.abc
import
Sequence
from
collections.abc
import
Iterable
,
Sequence
from
typing
import
ClassVar
from
django
import
forms
...
...
@@ -69,6 +69,9 @@ class CSVUploadForm(forms.Form):
fieldnames
=
reader
.
fieldnames
if
reader
.
fieldnames
is
not
None
else
[]
self
.
_validate_headers
(
fieldnames
)
# Step 3: Validate 'Source' and 'SYSTraderTranType' values
self
.
_validate_source_and_trader_type
(
reader
)
return
file
@staticmethod
...
...
@@ -108,3 +111,18 @@ class CSVUploadForm(forms.Form):
if
missing_columns
:
msg
=
f
"
Missing required columns:
{
'
,
'
.
join
(
missing_columns
)
}
"
raise
forms
.
ValidationError
(
msg
)
@staticmethod
def
_validate_source_and_trader_type
(
data
:
Iterable
[
dict
])
->
None
:
"""
Validate that
'
Source
'
is always 80 and
'
SYSTraderTranType
'
is always 4.
"""
errors
=
[]
for
index
,
row
in
enumerate
(
data
,
start
=
1
):
if
row
.
get
(
"
Source
"
)
!=
"
80
"
:
errors
.
append
(
f
"
Row
{
index
}
:
'
Source
'
must be 80, but found
{
row
.
get
(
'
Source
'
)
}
.
"
)
if
row
.
get
(
"
SYSTraderTranType
"
)
!=
"
4
"
:
errors
.
append
(
f
"
Row
{
index
}
:
'
SYSTraderTranType
'
must be 4, but found
{
row
.
get
(
'
SYSTraderTranType
'
)
}
.
"
)
if
errors
:
raise
forms
.
ValidationError
(
errors
)
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