From 454778fc6d67f02908f40ccc21a7153763e94d82 Mon Sep 17 00:00:00 2001 From: Todd Dembrey <todd.dembrey@torchbox.com> Date: Mon, 19 Mar 2018 10:21:57 +0000 Subject: [PATCH] Fix a multitude of linter errors --- opentech/apply/funds/tests/test_models.py | 10 ------ opentech/apply/funds/views.py | 8 +++-- opentech/apply/funds/workflow.py | 37 +++++++++++++++-------- 3 files changed, 29 insertions(+), 26 deletions(-) diff --git a/opentech/apply/funds/tests/test_models.py b/opentech/apply/funds/tests/test_models.py index 644632f2b..a463b9264 100644 --- a/opentech/apply/funds/tests/test_models.py +++ b/opentech/apply/funds/tests/test_models.py @@ -15,14 +15,11 @@ from opentech.apply.funds.models import ApplicationSubmission from opentech.apply.funds.workflow import SingleStage from .factories import ( - ApplicationFormFactory, ApplicationSubmissionFactory, CustomFormFieldsFactory, FundTypeFactory, LabFactory, - LabFormFactory, RoundFactory, - RoundFormFactory, ) @@ -188,13 +185,6 @@ class TestFormSubmission(TestCase): self.name = 'My Name' self.request_factory = RequestFactory() - # set up application form with minimal requirement for creating user - application_form = { - 'form_fields__0__email__': '', - 'form_fields__1__full_name__': '', - 'form_fields__2__title__': '', - } - form = ApplicationFormFactory(**application_form) fund = FundTypeFactory() self.site.root_page = fund diff --git a/opentech/apply/funds/views.py b/opentech/apply/funds/views.py index 205f6d0e7..58b588ef5 100644 --- a/opentech/apply/funds/views.py +++ b/opentech/apply/funds/views.py @@ -195,14 +195,16 @@ def demo_workflow(request, wf_id): wf = int(wf_id) workflow_class = workflows[wf - 1] - workflow = workflow_class([BasicSubmissionForm] * wf) + workflow = workflow_class() + forms = [BasicSubmissionForm] * wf current_phase = request.POST.get('current') current = workflow.current(current_phase) if request.POST: if current.stage.name not in submission: - submitted_form = current.stage.form(request.POST) + form = forms[workflow.stages.index(current.stage)] + submitted_form = form(request.POST) if submitted_form.is_valid(): submission[current.stage.name] = submitted_form.cleaned_data phase = current @@ -223,7 +225,7 @@ def demo_workflow(request, wf_id): submission.clear() if phase.stage.name not in submission: - form = phase.stage.form + form = forms[workflow.stages.index(phase.stage)] else: form = None diff --git a/opentech/apply/funds/workflow.py b/opentech/apply/funds/workflow.py index 612d2b11d..3cadb62e8 100644 --- a/opentech/apply/funds/workflow.py +++ b/opentech/apply/funds/workflow.py @@ -6,6 +6,9 @@ from typing import Dict, Iterable, Iterator, List, Sequence, Set, Type, Union from django.utils.text import slugify +from opentech.apply.users.models import User + + """ This file defines classes which allow you to compose workflows based on the following structure: @@ -126,14 +129,16 @@ class Stage(Iterable): # Make the phases new instances to prevent errors with mutability self.phases = self.copy_phases(self.phases) - def __eq__(self, other): + def __eq__(self, other: object) -> bool: if isinstance(other, Stage): return self.name == other.name return super().__eq__(other) - def __lt__(self, other): - return self.workflow.stages.index(self) < self.workflow.stages.index(other) + def __lt__(self, other: object) -> bool: + if isinstance(other, Stage): + return self.workflow.stages.index(self) < self.workflow.stages.index(other) + return False def copy_phases(self, phases: List['Phase']) -> List['Phase']: new_phases = list() @@ -197,7 +202,7 @@ class PhaseIterator(Iterator): def __init__(self, phases: List['Phase']) -> None: self.phases = phases - def __lt__(self, other): + def __lt__(self, other: object) -> bool: return all(phase < other for phase in self.phases) @property @@ -231,13 +236,17 @@ class PhaseIterator(Iterator): return self.Step(self.phases[self.current - 1]) -class CanEditPermission: - def can_edit(self, user): +class Permission: + pass + + +class CanEditPermission(Permission): + def can_edit(self, user: User) -> bool: return True -class NoEditPermission: - def can_edit(self, user): +class NoEditPermission(Permission): + def can_edit(self, user: User) -> bool: return False @@ -274,10 +283,12 @@ class Phase: to_match = ['stage', 'name', 'step'] return all(getattr(self, attr) == getattr(other, attr) for attr in to_match) - def __lt__(self, other): - if self.stage < other.stage: - return True - return self.step < other.step and self.stage == other.stage + def __lt__(self, other: object) -> bool: + if isinstance(other, Phase): + if self.stage < other.stage: + return True + return self.step < other.step and self.stage == other.stage + return False @property def action_names(self) -> List[str]: @@ -292,7 +303,7 @@ class Phase: def process(self, action: str) -> Union['Phase', None]: return self[action].process(self) - def has_perm(self, user, perm): + def has_perm(self, user: User, perm: str) -> bool: perm_method = getattr(self.permissions, f'can_{perm}', lambda x: False) return perm_method(user) -- GitLab