Skip to content
Snippets Groups Projects
Commit d1999e2f authored by Piotr Gawron's avatar Piotr Gawron
Browse files

pep warnings removed

parent ea464ed4
No related branches found
No related tags found
1 merge request!275Resolve "update automatic visit/subject importer"
......@@ -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)
......
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