From d1999e2fbbb61bb9a7f5d16e15e7866a7f75eb16 Mon Sep 17 00:00:00 2001
From: Piotr Gawron <piotr.gawron@uni.lu>
Date: Thu, 19 Nov 2020 10:26:42 +0100
Subject: [PATCH] pep warnings removed

---
 smash/web/importer/importer.py | 27 ++++++++++++++++-----------
 1 file changed, 16 insertions(+), 11 deletions(-)

diff --git a/smash/web/importer/importer.py b/smash/web/importer/importer.py
index 1f2511ab..fc1ed9a2 100644
--- a/smash/web/importer/importer.py
+++ b/smash/web/importer/importer.py
@@ -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)
-- 
GitLab