From 6da586d3efc3b01041ce61b65214f8cf86d806e7 Mon Sep 17 00:00:00 2001
From: Piotr Gawron <piotr.gawron@uni.lu>
Date: Mon, 4 Sep 2017 18:04:59 +0200
Subject: [PATCH] various coding issues

---
 smash/web/api_views/appointment.py             |  1 -
 smash/web/api_views/subject.py                 | 12 ++++++------
 smash/web/api_views/worker.py                  |  8 ++++----
 smash/web/models/availability.py               |  2 --
 smash/web/models/mail_template.py              |  4 ++--
 smash/web/templates/configuration/index.html   |  2 +-
 smash/web/templates/subjects/add.html          |  2 +-
 smash/web/templates/subjects/edit.html         |  2 +-
 smash/web/tests/functions.py                   |  4 ++--
 smash/web/tests/test_AvailabilityAddForm.py    |  1 -
 smash/web/tests/test_AvailabilityEditForm.py   |  1 -
 smash/web/tests/test_api_appointment_type.py   |  4 ++--
 smash/web/tests/test_api_configuration_item.py |  4 +---
 smash/web/tests/test_api_subject.py            |  6 +++---
 smash/web/tests/test_api_worker.py             |  2 +-
 smash/web/tests/test_process_file.py           |  4 ++--
 smash/web/tests/test_view_appointments.py      |  2 +-
 smash/web/tests/test_view_configuration.py     |  4 ----
 smash/web/tests/test_view_contact_attempt.py   |  2 +-
 smash/web/tests/test_view_functions.py         |  2 +-
 smash/web/tests/test_view_kit_request.py       |  2 +-
 smash/web/tests/test_view_notifications.py     |  2 +-
 smash/web/tests/test_view_subjects.py          |  6 ++++--
 smash/web/views/doctor.py                      |  4 ++--
 smash/web/views/export.py                      |  4 +++-
 smash/web/views/kit.py                         | 12 ++++++------
 smash/web/views/notifications.py               |  2 +-
 27 files changed, 47 insertions(+), 54 deletions(-)

diff --git a/smash/web/api_views/appointment.py b/smash/web/api_views/appointment.py
index 28a521b3..8945d166 100644
--- a/smash/web/api_views/appointment.py
+++ b/smash/web/api_views/appointment.py
@@ -94,7 +94,6 @@ def serialize_appointment(appointment):
     time = ""
     if appointment.datetime_when is not None:
         time = appointment.datetime_when.strftime('%Y-%m-%d %H:%M')
-        # time = appointment.datetime_when.strftime('%Y-%m-%d %H:%M:%S.%f %Z%z')
     until = ""
     if appointment.datetime_when is not None:
         until = appointment.datetime_until().strftime('%Y-%m-%d %H:%M')
diff --git a/smash/web/api_views/subject.py b/smash/web/api_views/subject.py
index abdd81b4..8f0161dd 100644
--- a/smash/web/api_views/subject.py
+++ b/smash/web/api_views/subject.py
@@ -10,25 +10,25 @@ from web.views.subject import SUBJECT_LIST_GENERIC, SUBJECT_LIST_NO_VISIT, SUBJE
 
 @login_required
 def cities(request):
-    X = Subject.objects.filter(city__isnull=False).values_list('city').distinct()
+    subjects = Subject.objects.filter(city__isnull=False).values_list('city').distinct()
     return JsonResponse({
-        "cities": [x[0] for x in X]
+        "cities": [x[0] for x in subjects]
     })
 
 
 @login_required
 def countries(request):
-    X = Subject.objects.filter(country__isnull=False).values_list('country').distinct()
+    subjects = Subject.objects.filter(country__isnull=False).values_list('country').distinct()
     return JsonResponse({
-        "countries": [x[0] for x in X]
+        "countries": [x[0] for x in subjects]
     })
 
 
 @login_required
 def referrals(request):
-    X = Subject.objects.filter(referral__isnull=False).values_list('referral').distinct()
+    subjects = Subject.objects.filter(referral__isnull=False).values_list('referral').distinct()
     return JsonResponse({
-        "referrals": [x[0] for x in X]
+        "referrals": [x[0] for x in subjects]
     })
 
 
diff --git a/smash/web/api_views/worker.py b/smash/web/api_views/worker.py
index 2b4aeaf1..803435cb 100644
--- a/smash/web/api_views/worker.py
+++ b/smash/web/api_views/worker.py
@@ -7,17 +7,17 @@ from ..views.notifications import get_filter_locations
 
 @login_required
 def specializations(request):
-    X = Worker.objects.filter(specialization__isnull=False).values_list('specialization').distinct()
+    workers = Worker.objects.filter(specialization__isnull=False).values_list('specialization').distinct()
     return JsonResponse({
-        "specializations": [x[0] for x in X]
+        "specializations": [x[0] for x in workers]
     })
 
 
 @login_required
 def units(request):
-    X = Worker.objects.filter(unit__isnull=False).values_list('unit').distinct()
+    workers = Worker.objects.filter(unit__isnull=False).values_list('unit').distinct()
     return JsonResponse({
-        "units": [x[0] for x in X]
+        "units": [x[0] for x in workers]
     })
 
 
diff --git a/smash/web/models/availability.py b/smash/web/models/availability.py
index a375ce11..46a98ac1 100644
--- a/smash/web/models/availability.py
+++ b/smash/web/models/availability.py
@@ -1,7 +1,5 @@
 # coding=utf-8
 
-import datetime
-
 from django.db import models
 
 from constants import WEEKDAY_CHOICES
diff --git a/smash/web/models/mail_template.py b/smash/web/models/mail_template.py
index 62d4491d..a5dabfbc 100644
--- a/smash/web/models/mail_template.py
+++ b/smash/web/models/mail_template.py
@@ -6,8 +6,8 @@ from contextlib import contextmanager
 
 from django.db import models
 
-from .constants import MAIL_TEMPLATE_CONTEXT_CHOICES, MAIL_TEMPLATE_CONTEXT_APPOINTMENT, MAIL_TEMPLATE_CONTEXT_SUBJECT, \
-    MAIL_TEMPLATE_CONTEXT_VISIT
+from .constants import MAIL_TEMPLATE_CONTEXT_CHOICES, MAIL_TEMPLATE_CONTEXT_APPOINTMENT, \
+    MAIL_TEMPLATE_CONTEXT_SUBJECT, MAIL_TEMPLATE_CONTEXT_VISIT
 from ..docx_helper import process_file
 from ..models import Appointment, Visit, Subject, Worker
 
diff --git a/smash/web/templates/configuration/index.html b/smash/web/templates/configuration/index.html
index 0b891582..7330cbc8 100644
--- a/smash/web/templates/configuration/index.html
+++ b/smash/web/templates/configuration/index.html
@@ -64,7 +64,7 @@
                 success: function (response) {
                     var message;
                     var classString;
-                    if (response.status == "ok") {
+                    if (response.status === "ok") {
                         message = "Element modified successfully";
                         classString = "alert alert-success"
                     } else {
diff --git a/smash/web/templates/subjects/add.html b/smash/web/templates/subjects/add.html
index b3b490c6..0d22f5b1 100644
--- a/smash/web/templates/subjects/add.html
+++ b/smash/web/templates/subjects/add.html
@@ -79,7 +79,7 @@
     <script src="{% static 'AdminLTE/plugins/awesomplete/awesomplete.min.js' %}"></script>
     <script>
         $(document).ready(function () {
-            // If ever to debug and thinking why it doesn't work => look if theres 'null' in data from API
+            // If ever to debug and thinking why it doesn't work => look if there is 'null' in data from API
             $.get("{% url 'web.api.cities' %}", function (data) {
                 new Awesomplete(document.querySelector("#id_city")).list = data.cities;
             });
diff --git a/smash/web/templates/subjects/edit.html b/smash/web/templates/subjects/edit.html
index e2cb7121..f1dbc493 100644
--- a/smash/web/templates/subjects/edit.html
+++ b/smash/web/templates/subjects/edit.html
@@ -158,7 +158,7 @@
                     <div class="modal-header">
                         <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span
                                 aria-hidden="true">&times;</span></button>
-                        <h4 class="modal-title">Are you sure that you want to perfom this operation?</h4>
+                        <h4 class="modal-title">Are you sure that you want to perform this operation?</h4>
                     </div>
                     <div class="modal-body">
                         <p>Screening number shouldn't change.</p>
diff --git a/smash/web/tests/functions.py b/smash/web/tests/functions.py
index 24cd16c2..a492a1e6 100644
--- a/smash/web/tests/functions.py
+++ b/smash/web/tests/functions.py
@@ -35,14 +35,14 @@ def create_appointment_type():
     )
 
 
-def create_subject(id=1):
+def create_subject(subject_id=1):
     return Subject.objects.create(
         first_name="Piotr",
         last_name="Gawron",
         default_location=get_test_location(),
         sex=SEX_CHOICES_MALE,
         type=SUBJECT_TYPE_CHOICES_CONTROL,
-        screening_number="piotr's number" + str(id),
+        screening_number="piotr's number" + str(subject_id),
         country="france"
     )
 
diff --git a/smash/web/tests/test_AvailabilityAddForm.py b/smash/web/tests/test_AvailabilityAddForm.py
index 2f6b9b35..85987100 100644
--- a/smash/web/tests/test_AvailabilityAddForm.py
+++ b/smash/web/tests/test_AvailabilityAddForm.py
@@ -9,7 +9,6 @@ from web.models import Worker
 
 class AvailabilityAddFormTests(TestCase):
     def setUp(self):
-        location = get_test_location()
         self.user = create_user()
 
         worker = Worker.get_by_user(self.user)
diff --git a/smash/web/tests/test_AvailabilityEditForm.py b/smash/web/tests/test_AvailabilityEditForm.py
index 3f3a3c85..9d2d3bd1 100644
--- a/smash/web/tests/test_AvailabilityEditForm.py
+++ b/smash/web/tests/test_AvailabilityEditForm.py
@@ -9,7 +9,6 @@ from web.models import Worker
 
 class AvailabilityEditFormTests(TestCase):
     def setUp(self):
-        location = get_test_location()
         self.user = create_user()
 
         worker = Worker.get_by_user(self.user)
diff --git a/smash/web/tests/test_api_appointment_type.py b/smash/web/tests/test_api_appointment_type.py
index 24b06c1f..ea1610b7 100644
--- a/smash/web/tests/test_api_appointment_type.py
+++ b/smash/web/tests/test_api_appointment_type.py
@@ -33,8 +33,8 @@ class TestApi(TestCase):
         appointment_types = json.loads(response.content)['appointment_types']
 
         found = False
-        for type in appointment_types:
-            if type['type'] == type_name:
+        for appointment_type in appointment_types:
+            if appointment_type['type'] == type_name:
                 found = True
 
         self.assertTrue(found)
diff --git a/smash/web/tests/test_api_configuration_item.py b/smash/web/tests/test_api_configuration_item.py
index 78ef0d16..102e3a5b 100644
--- a/smash/web/tests/test_api_configuration_item.py
+++ b/smash/web/tests/test_api_configuration_item.py
@@ -6,9 +6,7 @@ from django.urls import reverse
 from web.models import ConfigurationItem
 from web.tests.functions import create_configuration_item
 from . import LoggedInTestCase
-from web.models.constants import CANCELLED_APPOINTMENT_COLOR_CONFIGURATION_TYPE, \
-    NO_SHOW_APPOINTMENT_COLOR_CONFIGURATION_TYPE, KIT_EMAIL_HOUR_CONFIGURATION_TYPE, \
-    KIT_EMAIL_DAY_OF_WEEK_CONFIGURATION_TYPE
+from web.models.constants import CANCELLED_APPOINTMENT_COLOR_CONFIGURATION_TYPE
 
 
 class TestConfigurationItemApi(LoggedInTestCase):
diff --git a/smash/web/tests/test_api_subject.py b/smash/web/tests/test_api_subject.py
index 9a947b41..8fbce03c 100644
--- a/smash/web/tests/test_api_subject.py
+++ b/smash/web/tests/test_api_subject.py
@@ -280,12 +280,12 @@ class TestApi(TestCase):
     def test_subjects_filter_unknown(self):
         subject = self.subject
 
-        self.check_subject_filtered([["some_unknown", "zxczxc"]], [subject])
+        self.check_subject_filtered([["some_unknown", "unknown data"]], [subject])
         self.check_subject_filtered([["", ""]], [subject])
 
     def test_serialize_subject(self):
         subject = self.subject
         subject.dead = True
 
-        subject_json = serialize_subject(subject);
-        self.assertEqual("YES", subject_json["dead"]);
+        subject_json = serialize_subject(subject)
+        self.assertEqual("YES", subject_json["dead"])
diff --git a/smash/web/tests/test_api_worker.py b/smash/web/tests/test_api_worker.py
index f3f353d3..1b93de26 100644
--- a/smash/web/tests/test_api_worker.py
+++ b/smash/web/tests/test_api_worker.py
@@ -6,7 +6,7 @@ from django.test import Client
 from django.test import TestCase
 from django.urls import reverse
 
-from web.tests.functions import create_subject, create_worker
+from web.tests.functions import create_worker
 
 
 class TestApi(TestCase):
diff --git a/smash/web/tests/test_process_file.py b/smash/web/tests/test_process_file.py
index f46bcac4..d7ef2bb4 100644
--- a/smash/web/tests/test_process_file.py
+++ b/smash/web/tests/test_process_file.py
@@ -21,8 +21,8 @@ class TestDocxProcessor(TestCase):
         changes = {
             "##SIR##": "Mr",
             "##NAME##": "Jan",
-            "##SURNAME##": "Weglarz",
-            "##ADDRESS1##": "Piotrowo 23",
+            "##SURNAME##": "Gawron",
+            "##ADDRESS1##": "Rock'n'roll 23",
             "##ADDRESS2##": "61-234, Poznan",
             "##COUNTRY##": "POLAND",
             "##CONTENT##": "1",
diff --git a/smash/web/tests/test_view_appointments.py b/smash/web/tests/test_view_appointments.py
index b29533c2..e32a1b54 100644
--- a/smash/web/tests/test_view_appointments.py
+++ b/smash/web/tests/test_view_appointments.py
@@ -94,4 +94,4 @@ class AppointmentsViewTests(LoggedInTestCase):
         self.assertEqual(response.status_code, 302)
 
         updated_subject = Subject.objects.get(id=subject.id)
-        self.assertTrue(updated_subject.information_sent)
\ No newline at end of file
+        self.assertTrue(updated_subject.information_sent)
diff --git a/smash/web/tests/test_view_configuration.py b/smash/web/tests/test_view_configuration.py
index 44082285..4b9bbccd 100644
--- a/smash/web/tests/test_view_configuration.py
+++ b/smash/web/tests/test_view_configuration.py
@@ -2,10 +2,6 @@ import datetime
 
 from django.urls import reverse
 
-from functions import create_subject, create_visit, create_appointment, create_appointment_type
-from web.forms import VisitDetailForm, VisitAddForm
-from web.models import Visit
-from web.views.notifications import get_today_midnight_date
 from . import LoggedInTestCase
 
 
diff --git a/smash/web/tests/test_view_contact_attempt.py b/smash/web/tests/test_view_contact_attempt.py
index 872bfa8f..760119e7 100644
--- a/smash/web/tests/test_view_contact_attempt.py
+++ b/smash/web/tests/test_view_contact_attempt.py
@@ -26,7 +26,7 @@ class ContactAttemptViewTests(LoggedInWithWorkerTestCase):
         form_data = {'datetime_when': now, 'worker': self.worker.id, 'type': contact_type, 'comment': comment}
         response = self.client.post(
             reverse('web.views.contact_add', kwargs={'subject_id': subject.id}), data=form_data)
-        # check correct redirection to suject edit page
+        # check correct redirection to subject edit page
         self.assertRedirects(response, reverse('web.views.subject_edit', kwargs={'id': subject.id}))
         contact_attempts = ContactAttempt.objects.filter(subject=subject).all()
         self.assertEqual(1, len(contact_attempts))
diff --git a/smash/web/tests/test_view_functions.py b/smash/web/tests/test_view_functions.py
index db206b6b..7df3e0a0 100644
--- a/smash/web/tests/test_view_functions.py
+++ b/smash/web/tests/test_view_functions.py
@@ -6,7 +6,7 @@ from web.views.notifications import get_filter_locations
 
 class ViewFunctionsTests(TestCase):
     def setUp(self):
-        create_location("tescik")
+        create_location("testLocation")
         return
 
     def test_locations_for_user(self):
diff --git a/smash/web/tests/test_view_kit_request.py b/smash/web/tests/test_view_kit_request.py
index 4a061d4a..00967ccd 100644
--- a/smash/web/tests/test_view_kit_request.py
+++ b/smash/web/tests/test_view_kit_request.py
@@ -74,7 +74,7 @@ class ViewFunctionsTests(LoggedInTestCase):
         appointment_type.required_equipment.add(item)
         appointment_type.save()
 
-        visit = create_visit();
+        visit = create_visit()
 
         appointment1 = create_appointment(visit)
         appointment1.datetime_when = get_today_midnight_date() + datetime.timedelta(days=3)
diff --git a/smash/web/tests/test_view_notifications.py b/smash/web/tests/test_view_notifications.py
index 1467a169..9c79dd8c 100644
--- a/smash/web/tests/test_view_notifications.py
+++ b/smash/web/tests/test_view_notifications.py
@@ -428,7 +428,7 @@ class NotificationViewTests(LoggedInTestCase):
 
     def test_get_filter_locations_for_invalid_user_2(self):
         try:
-            locations = get_filter_locations("invalid class")
+            get_filter_locations("invalid class")
             self.fail("Exception expected")
         except TypeError:
             pass
diff --git a/smash/web/tests/test_view_subjects.py b/smash/web/tests/test_view_subjects.py
index 92444e1b..2983777c 100644
--- a/smash/web/tests/test_view_subjects.py
+++ b/smash/web/tests/test_view_subjects.py
@@ -82,7 +82,8 @@ class SubjectsViewTests(TestCase):
 
         subject = Subject.objects.all()[0]
         self.assertEqual("L-001", subject.screening_number,
-                         "prefix should start by L as default location prefix is not defined and subject type is control")
+                         "prefix should start by L" +
+                         " as default location prefix is not defined and subject type is control")
 
     def test_subjects_add_patient(self):
 
@@ -105,7 +106,8 @@ class SubjectsViewTests(TestCase):
 
         subject = Subject.objects.all()[0]
         self.assertEqual("P-001", subject.screening_number,
-                         "prefix should start by P as default location prefix is not defined and subject type is patient")
+                         "prefix should start by P" +
+                         " as default location prefix is not defined and subject type is patient")
 
     def test_subjects_add_with_prefixed_location(self):
 
diff --git a/smash/web/views/doctor.py b/smash/web/views/doctor.py
index dca2692f..12e4cace 100644
--- a/smash/web/views/doctor.py
+++ b/smash/web/views/doctor.py
@@ -37,8 +37,8 @@ def doctor_edit(request, doctor_id):
             return redirect('web.views.doctors')
     else:
         form = WorkerEditForm(instance=the_doctor)
-    availabilities = Availability.objects.filter(person=doctor_id).order_by('day_number', 'available_from');
-    holidays = Holiday.objects.filter(person=doctor_id).order_by('-datetime_start');
+    availabilities = Availability.objects.filter(person=doctor_id).order_by('day_number', 'available_from')
+    holidays = Holiday.objects.filter(person=doctor_id).order_by('-datetime_start')
     return wrap_response(request, 'doctors/edit.html',
                          {
                              'form': form,
diff --git a/smash/web/views/export.py b/smash/web/views/export.py
index d76a0465..6f98432d 100644
--- a/smash/web/views/export.py
+++ b/smash/web/views/export.py
@@ -49,7 +49,9 @@ def write_subjects_to_csv(writer):
 def write_appointments_to_csv(writer):
     appointments_fields = []
     for field in Appointment._meta.fields:
-        if field.name != "visit" and field.name != "id" and field.name != "worker_assigned" and field.name != "appointment_types" and field.name != "room" and field.name != "flying_team":
+        if field.name != "visit" and field.name != "id" and \
+                        field.name != "worker_assigned" and field.name != "appointment_types" and \
+                        field.name != "room" and field.name != "flying_team":
             appointments_fields.append(field)
 
     field_names = ['ND number', 'Family name', 'Name', 'Visit']
diff --git a/smash/web/views/kit.py b/smash/web/views/kit.py
index 8c33bbda..4955103d 100644
--- a/smash/web/views/kit.py
+++ b/smash/web/views/kit.py
@@ -129,8 +129,8 @@ def kit_requests_send_mail(request, start_date, end_date=None):
 
 
 class KitRequestEmailSendJob(CronJobBase):
-    RUN_EVERY_MINS = 1
-    schedule = Schedule(run_every_mins=RUN_EVERY_MINS)
+    RUN_EVERY_MINUTES = 1
+    schedule = Schedule(run_every_mins=RUN_EVERY_MINUTES)
     code = 'web.kit_request_weekly_email'  # a unique code
 
     def do(self):
@@ -148,8 +148,8 @@ class KitRequestEmailSendJob(CronJobBase):
         if jobs.count() == 0:
             if pytz.utc.localize(datetime.datetime.utcnow()) > date:
                 if self.match_day_of_week():
-                    data = get_kit_requests(Worker.objects.create());
-                    send_mail(data);
+                    data = get_kit_requests(Worker.objects.create())
+                    send_mail(data)
                     return "mail sent"
                 else:
                     return "day of week doesn't match"
@@ -160,7 +160,7 @@ class KitRequestEmailSendJob(CronJobBase):
 
     def match_day_of_week(self):
         user_day_of_week = ConfigurationItem.objects.get(type=KIT_EMAIL_DAY_OF_WEEK_CONFIGURATION_TYPE).value
-        language = Language.objects.get(name="English");
+        language = Language.objects.get(name="English")
         locale_name = language.locale
         if platform.system() == 'Windows':
             locale_name = language.windows_locale_name
@@ -171,6 +171,6 @@ class KitRequestEmailSendJob(CronJobBase):
             traceback.print_exc(file=sys.stdout)
 
         user_day_of_week_int = int(time.strptime(user_day_of_week, '%A').tm_wday) + 1
-        current_day_of_week_int = int(datetime.datetime.now().strftime("%w"));
+        current_day_of_week_int = int(datetime.datetime.now().strftime("%w"))
 
         return user_day_of_week_int == current_day_of_week_int
diff --git a/smash/web/views/notifications.py b/smash/web/views/notifications.py
index 0f7d4e66..0d47a354 100644
--- a/smash/web/views/notifications.py
+++ b/smash/web/views/notifications.py
@@ -241,4 +241,4 @@ def get_filter_locations(user):
 def get_today_midnight_date():
     today = datetime.datetime.now()
     today_midnight = datetime.datetime(today.year, today.month, today.day)
-    return today_midnight
\ No newline at end of file
+    return today_midnight
-- 
GitLab