Fix Flake8 Violations 51/70551/1
authorTrevor Bramwell <tbramwell@linuxfoundation.org>
Wed, 15 Jul 2020 20:00:53 +0000 (13:00 -0700)
committerTrevor Bramwell <tbramwell@linuxfoundation.org>
Wed, 15 Jul 2020 20:00:53 +0000 (13:00 -0700)
Several minor issues found through flake8 should now be fixed in the
code.

Signed-off-by: Trevor Bramwell <tbramwell@linuxfoundation.org>
Change-Id: I4f6e5dac5ed8378911598ded714602bbb3f6bd6b

src/account/models.py
src/account/tasks.py
src/account/views.py
src/api/migrations/0013_manual_20200218_1536.py
src/api/models.py
src/api/views.py
src/resource_inventory/migrations/0012_auto_20200103_1850.py
src/workflow/resource_bundle_workflow.py

index 4aab306..9624a53 100644 (file)
@@ -16,6 +16,7 @@ import random
 
 from collections import Counter
 
+
 class LabStatus(object):
     """
     A Poor man's enum for the status of a lab.
@@ -216,7 +217,7 @@ class Lab(models.Model):
 
     def get_available_resources(self):
         # Cannot import model normally due to ciruclar import
-        Server = apps.get_model('resource_inventory', 'Server') # TODO: Find way to import ResourceQuery
+        Server = apps.get_model('resource_inventory', 'Server')  # TODO: Find way to import ResourceQuery
         resources = [str(resource.profile) for resource in Server.objects.filter(lab=self, booked=False)]
         return dict(Counter(resources))
 
index 53fbaf5..df98c73 100644 (file)
@@ -28,7 +28,7 @@ def sync_jira_accounts():
             continue
         try:
             user.email = user_dict['emailAddress']
-        except:
+        except KeyError:
             pass
         user.userprofile.url = user_dict['self']
         user.userprofile.full_name = user_dict['displayName']
index 1cb2275..d11a199 100644 (file)
@@ -130,7 +130,7 @@ class JiraAuthenticatedView(RedirectView):
         email = ""
         try:
             email = jira.user(username).emailAddress
-        except:
+        except AttributeError:
             email = ""
         url = '/'
         # Step 3. Lookup the user or create them if they don't exist.
index 0b76e84..3ac427e 100644 (file)
@@ -1,6 +1,6 @@
 # Generated by Django 2.2 on 2020-02-18 15:36
 
-from django.db import migrations, models
+from django.db import migrations
 
 
 class Migration(migrations.Migration):
index addc02d..231ae31 100644 (file)
@@ -176,12 +176,12 @@ class LabManager(object):
 
     def format_user(self, userprofile):
         return {
-                    "id": userprofile.user.id,
-                    "username": userprofile.user.username,
-                    "email": userprofile.email_addr,
-                    "first_name": userprofile.user.first_name,
-                    "last_name": userprofile.user.last_name,
-                    "company": userprofile.company
+            "id": userprofile.user.id,
+            "username": userprofile.user.username,
+            "email": userprofile.email_addr,
+            "first_name": userprofile.user.first_name,
+            "last_name": userprofile.user.last_name,
+            "company": userprofile.company
         }
 
     def get_users(self):
index 4e0d058..75a0db3 100644 (file)
@@ -97,11 +97,13 @@ def lab_status(request, lab_name=""):
         return JsonResponse(lab_manager.set_status(request.POST), safe=False)
     return JsonResponse(lab_manager.get_status(), safe=False)
 
+
 def lab_users(request, lab_name=""):
     lab_token = request.META.get('HTTP_AUTH_TOKEN')
     lab_manager = LabManagerTracker.get(lab_name, lab_token)
     return HttpResponse(lab_manager.get_users(), content_type="text/plain")
 
+
 def lab_user(request, lab_name="", user_id=-1):
     lab_token = request.META.get('HTTP_AUTH_TOKEN')
     lab_manager = LabManagerTracker.get(lab_name, lab_token)
index 569e433..65d8f85 100644 (file)
@@ -54,6 +54,6 @@ class Migration(migrations.Migration):
             model_name='vlan',
             name='network',
             field=models.ForeignKey(on_delete=django.db.models.deletion.DO_NOTHING,
-                to='resource_inventory.PhysicalNetwork', null=True),
+                                    to='resource_inventory.PhysicalNetwork', null=True),
         ),
     ]
index 391d33e..fa05b22 100644 (file)
@@ -10,6 +10,7 @@
 
 from django.conf import settings
 from django.forms import formset_factory
+from django.core.exceptions import ValidationError
 
 from typing import List
 
@@ -251,15 +252,12 @@ class Define_Software(WorkflowStep):
         # TODO: fix headnode in form, currently doesn't return a selected one
         # models['headnode_index'] = post_data.get("headnode", 1)
         formset = self.create_hostformset(hosts, data=post_data)
-        has_headnode = False
         if formset.is_valid():
             for i, form in enumerate(formset):
                 host = hosts[i]
                 image = form.cleaned_data['image']
                 hostname = form.cleaned_data['host_name']
                 headnode = form.cleaned_data['headnode']
-                if headnode:
-                    has_headnode = True
                 host.is_head_node = headnode
                 host.name = hostname
                 host.image = image