Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
scheduling-system
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
External wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
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 GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
SMASCH
scheduling-system
Commits
d1999e2f
Commit
d1999e2f
authored
4 years ago
by
Piotr Gawron
Browse files
Options
Downloads
Patches
Plain Diff
pep warnings removed
parent
ea464ed4
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!275
Resolve "update automatic visit/subject importer"
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
smash/web/importer/importer.py
+16
-11
16 additions, 11 deletions
smash/web/importer/importer.py
with
16 additions
and
11 deletions
smash/web/importer/importer.py
+
16
−
11
View file @
d1999e2f
...
...
@@ -3,10 +3,7 @@ import logging
import
sys
import
traceback
from
django.contrib.auth.models
import
User
from
web.models
import
StudySubject
,
Subject
,
Provenance
,
Worker
,
ConfigurationItem
from
web.models.constants
import
IMPORTER_USER
from
web.models
import
StudySubject
,
Subject
,
Provenance
from
.etl_common
import
EtlCommon
from
.subject_import_reader
import
SubjectImportReader
from
.warning_counter
import
MsgCounterHandler
...
...
@@ -35,6 +32,7 @@ class Importer(EtlCommon):
self
.
study_subjects
=
self
.
reader
.
load_data
()
for
study_subject
in
self
.
study_subjects
:
# noinspection PyBroadException
try
:
if
study_subject
.
study
!=
self
.
reader
.
import_data
.
study
or
study_subject
.
study
.
id
is
None
:
self
.
problematic_count
+=
1
...
...
@@ -42,7 +40,7 @@ class Importer(EtlCommon):
continue
else
:
self
.
import_study_subject
(
study_subject
)
except
:
except
BaseException
:
self
.
problematic_count
+=
1
traceback
.
print_exc
(
file
=
sys
.
stdout
)
logger
.
error
(
"
Problem with importing study subject:
"
+
str
(
study_subject
.
screening_number
)
+
"
,
"
+
...
...
@@ -51,13 +49,14 @@ class Importer(EtlCommon):
self
.
warning_count
=
warning_counter
.
level2count
[
"
WARNING
"
]
logging
.
getLogger
(
''
).
removeHandler
(
warning_counter
)
def
import_study_subject
(
self
,
study_subject
):
# type: (StudySubject) -> None
def
import_study_subject
(
self
,
study_subject
:
StudySubject
):
db_study_subjects
=
StudySubject
.
objects
.
filter
(
nd_number
=
study_subject
.
nd_number
)
if
db_study_subjects
.
count
()
>
0
:
db_study_subject
=
db_study_subjects
.
first
()
for
field
in
Subject
.
_meta
.
get_fields
():
if
field
.
get_internal_type
()
==
"
CharField
"
or
field
.
get_internal_type
()
==
"
DateField
"
or
field
.
get_internal_type
()
is
"
BooleanField
"
:
if
field
.
get_internal_type
()
==
"
CharField
"
or
\
field
.
get_internal_type
()
==
"
DateField
"
or
\
field
.
get_internal_type
()
is
"
BooleanField
"
:
new_value
=
getattr
(
study_subject
.
subject
,
field
.
name
)
if
new_value
is
not
None
and
new_value
!=
""
:
old_value
=
getattr
(
db_study_subject
.
subject
,
field
.
name
)
...
...
@@ -76,7 +75,9 @@ class Importer(EtlCommon):
db_study_subject
.
subject
.
save
()
for
field
in
StudySubject
.
_meta
.
get_fields
():
if
field
.
get_internal_type
()
==
"
CharField
"
or
field
.
get_internal_type
()
==
"
DateField
"
or
field
.
get_internal_type
()
is
"
BooleanField
"
:
if
field
.
get_internal_type
()
==
"
CharField
"
or
\
field
.
get_internal_type
()
==
"
DateField
"
or
\
field
.
get_internal_type
()
is
"
BooleanField
"
:
new_value
=
getattr
(
study_subject
,
field
.
name
)
if
new_value
is
not
None
and
new_value
!=
""
:
old_value
=
getattr
(
db_study_subject
,
field
.
name
)
...
...
@@ -99,7 +100,9 @@ class Importer(EtlCommon):
study_subject
.
save
()
for
field
in
Subject
.
_meta
.
get_fields
():
if
field
.
get_internal_type
()
==
"
CharField
"
or
field
.
get_internal_type
()
==
"
DateField
"
or
field
.
get_internal_type
()
is
"
BooleanField
"
:
if
field
.
get_internal_type
()
==
"
CharField
"
or
\
field
.
get_internal_type
()
==
"
DateField
"
or
\
field
.
get_internal_type
()
is
"
BooleanField
"
:
new_value
=
getattr
(
study_subject
.
subject
,
field
.
name
)
if
new_value
is
not
None
and
new_value
!=
""
:
description
=
'
{} changed from
"
{}
"
to
"
{}
"'
.
format
(
field
,
''
,
new_value
)
...
...
@@ -114,7 +117,9 @@ class Importer(EtlCommon):
p
.
save
()
for
field
in
StudySubject
.
_meta
.
get_fields
():
if
field
.
get_internal_type
()
==
"
CharField
"
or
field
.
get_internal_type
()
==
"
DateField
"
or
field
.
get_internal_type
()
is
"
BooleanField
"
:
if
field
.
get_internal_type
()
==
"
CharField
"
or
\
field
.
get_internal_type
()
==
"
DateField
"
or
\
field
.
get_internal_type
()
is
"
BooleanField
"
:
new_value
=
getattr
(
study_subject
,
field
.
name
)
if
new_value
is
not
None
and
new_value
!=
""
:
description
=
'
{} changed from
"
{}
"
to
"
{}
"'
.
format
(
field
,
''
,
new_value
)
...
...
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