tuomas2/serviceform

View on GitHub
serviceform/serviceform/admin.py

Summary

Maintainability
C
1 day
Test Coverage
D
63%

File admin.py has 282 lines of code (exceeds 250 allowed). Consider refactoring.
Open

# -*- coding: utf-8 -*-
# (c) 2017 Tuomas Airaksinen
#
# This file is part of Serviceform.
#
Severity: Minor
Found in serviceform/serviceform/admin.py - About 2 hrs to fix

    Cyclomatic complexity is too high in method construct_change_message. (10)
    Open

        def construct_change_message(self, request, form, formsets, add=False):
            """Construct a change message from a changed object.
            Copy of contrib/admin/options.py class ModelAdmin with get_text_list
            replaced with self.get_field_change."""
            change_message = []
    Severity: Minor
    Found in serviceform/serviceform/admin.py by radon

    Cyclomatic Complexity

    Cyclomatic Complexity corresponds to the number of decisions a block of code contains plus 1. This number (also called McCabe number) is equal to the number of linearly independent paths through the code. This number can be used as a guide when testing conditional logic in blocks.

    Radon analyzes the AST tree of a Python program to compute Cyclomatic Complexity. Statements have the following effects on Cyclomatic Complexity:

    Construct Effect on CC Reasoning
    if +1 An if statement is a single decision.
    elif +1 The elif statement adds another decision.
    else +0 The else statement does not cause a new decision. The decision is at the if.
    for +1 There is a decision at the start of the loop.
    while +1 There is a decision at the while statement.
    except +1 Each except branch adds a new conditional path of execution.
    finally +0 The finally block is unconditionally executed.
    with +1 The with statement roughly corresponds to a try/except block (see PEP 343 for details).
    assert +1 The assert statement internally roughly equals a conditional statement.
    Comprehension +1 A list/set/dict comprehension of generator expression is equivalent to a for loop.
    Boolean Operator +1 Every boolean operator (and, or) adds a decision point.

    Source: http://radon.readthedocs.org/en/latest/intro.html

    Cyclomatic complexity is too high in method get_field_change. (7)
    Open

        def get_field_change(self, form, changed_fields):
            """Mentions old and new value for changed fields"""
            changes = []
            for field_name in changed_fields:
                field = form.fields[field_name]
    Severity: Minor
    Found in serviceform/serviceform/admin.py by radon

    Cyclomatic Complexity

    Cyclomatic Complexity corresponds to the number of decisions a block of code contains plus 1. This number (also called McCabe number) is equal to the number of linearly independent paths through the code. This number can be used as a guide when testing conditional logic in blocks.

    Radon analyzes the AST tree of a Python program to compute Cyclomatic Complexity. Statements have the following effects on Cyclomatic Complexity:

    Construct Effect on CC Reasoning
    if +1 An if statement is a single decision.
    elif +1 The elif statement adds another decision.
    else +0 The else statement does not cause a new decision. The decision is at the if.
    for +1 There is a decision at the start of the loop.
    while +1 There is a decision at the while statement.
    except +1 Each except branch adds a new conditional path of execution.
    finally +0 The finally block is unconditionally executed.
    with +1 The with statement roughly corresponds to a try/except block (see PEP 343 for details).
    assert +1 The assert statement internally roughly equals a conditional statement.
    Comprehension +1 A list/set/dict comprehension of generator expression is equivalent to a for loop.
    Boolean Operator +1 Every boolean operator (and, or) adds a decision point.

    Source: http://radon.readthedocs.org/en/latest/intro.html

    Cyclomatic complexity is too high in class ExtendedLogMixin. (7)
    Open

    class ExtendedLogMixin:
        """
        Adds changed content into log message in Admin
        """
    
    
    Severity: Minor
    Found in serviceform/serviceform/admin.py by radon

    Cyclomatic Complexity

    Cyclomatic Complexity corresponds to the number of decisions a block of code contains plus 1. This number (also called McCabe number) is equal to the number of linearly independent paths through the code. This number can be used as a guide when testing conditional logic in blocks.

    Radon analyzes the AST tree of a Python program to compute Cyclomatic Complexity. Statements have the following effects on Cyclomatic Complexity:

    Construct Effect on CC Reasoning
    if +1 An if statement is a single decision.
    elif +1 The elif statement adds another decision.
    else +0 The else statement does not cause a new decision. The decision is at the if.
    for +1 There is a decision at the start of the loop.
    while +1 There is a decision at the while statement.
    except +1 Each except branch adds a new conditional path of execution.
    finally +0 The finally block is unconditionally executed.
    with +1 The with statement roughly corresponds to a try/except block (see PEP 343 for details).
    assert +1 The assert statement internally roughly equals a conditional statement.
    Comprehension +1 A list/set/dict comprehension of generator expression is equivalent to a for loop.
    Boolean Operator +1 Every boolean operator (and, or) adds a decision point.

    Source: http://radon.readthedocs.org/en/latest/intro.html

    Cyclomatic complexity is too high in method get_form. (6)
    Open

        def get_form(self, request: HttpRequest, obj: models.ServiceForm=None, **kwargs):
            form = super().get_form(request, obj, **kwargs)
            if obj:
                request._responsibles = responsibles = models.ResponsibilityPerson.objects.filter(
                    form=obj)
    Severity: Minor
    Found in serviceform/serviceform/admin.py by radon

    Cyclomatic Complexity

    Cyclomatic Complexity corresponds to the number of decisions a block of code contains plus 1. This number (also called McCabe number) is equal to the number of linearly independent paths through the code. This number can be used as a guide when testing conditional logic in blocks.

    Radon analyzes the AST tree of a Python program to compute Cyclomatic Complexity. Statements have the following effects on Cyclomatic Complexity:

    Construct Effect on CC Reasoning
    if +1 An if statement is a single decision.
    elif +1 The elif statement adds another decision.
    else +0 The else statement does not cause a new decision. The decision is at the if.
    for +1 There is a decision at the start of the loop.
    while +1 There is a decision at the while statement.
    except +1 Each except branch adds a new conditional path of execution.
    finally +0 The finally block is unconditionally executed.
    with +1 The with statement roughly corresponds to a try/except block (see PEP 343 for details).
    assert +1 The assert statement internally roughly equals a conditional statement.
    Comprehension +1 A list/set/dict comprehension of generator expression is equivalent to a for loop.
    Boolean Operator +1 Every boolean operator (and, or) adds a decision point.

    Source: http://radon.readthedocs.org/en/latest/intro.html

    Function construct_change_message has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
    Open

        def construct_change_message(self, request, form, formsets, add=False):
            """Construct a change message from a changed object.
            Copy of contrib/admin/options.py class ModelAdmin with get_text_list
            replaced with self.get_field_change."""
            change_message = []
    Severity: Minor
    Found in serviceform/serviceform/admin.py - About 1 hr to fix

    Cognitive Complexity

    Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

    A method's cognitive complexity is based on a few simple rules:

    • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
    • Code is considered more complex for each "break in the linear flow of the code"
    • Code is considered more complex when "flow breaking structures are nested"

    Further reading

    Function get_form has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
    Open

        def get_form(self, request: HttpRequest, obj: models.ServiceForm=None, **kwargs):
            form = super().get_form(request, obj, **kwargs)
            if obj:
                request._responsibles = responsibles = models.ResponsibilityPerson.objects.filter(
                    form=obj)
    Severity: Minor
    Found in serviceform/serviceform/admin.py - About 1 hr to fix

    Cognitive Complexity

    Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

    A method's cognitive complexity is based on a few simple rules:

    • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
    • Code is considered more complex for each "break in the linear flow of the code"
    • Code is considered more complex when "flow breaking structures are nested"

    Further reading

    Function get_field_change has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
    Open

        def get_field_change(self, form, changed_fields):
            """Mentions old and new value for changed fields"""
            changes = []
            for field_name in changed_fields:
                field = form.fields[field_name]
    Severity: Minor
    Found in serviceform/serviceform/admin.py - About 55 mins to fix

    Cognitive Complexity

    Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

    A method's cognitive complexity is based on a few simple rules:

    • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
    • Code is considered more complex for each "break in the linear flow of the code"
    • Code is considered more complex when "flow breaking structures are nested"

    Further reading

    Function save_model has 5 arguments (exceeds 4 allowed). Consider refactoring.
    Open

        def save_model(self, request: HttpRequest, obj: models.ServiceForm, form, change: bool):
    Severity: Minor
    Found in serviceform/serviceform/admin.py - About 35 mins to fix

      Function save_related has 5 arguments (exceeds 4 allowed). Consider refactoring.
      Open

          def save_related(self, request: HttpRequest, form, formsets, change: bool):
      Severity: Minor
      Found in serviceform/serviceform/admin.py - About 35 mins to fix

        Function map_field_value has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
        Open

            def map_field_value(self, values, choices):
                def do_map(value, choices):
                    if value is None:
                        return '?'
                    elif isinstance(value, Model):
        Severity: Minor
        Found in serviceform/serviceform/admin.py - About 35 mins to fix

        Cognitive Complexity

        Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

        A method's cognitive complexity is based on a few simple rules:

        • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
        • Code is considered more complex for each "break in the linear flow of the code"
        • Code is considered more complex when "flow breaking structures are nested"

        Further reading

        Continuation line missing indentation or outdented
        Open

            ('visible_year_of_birth', 'visible_street_address', 'visible_phone_number'),)
        Severity: Minor
        Found in serviceform/serviceform/admin.py by pep8

        Continuation lines indentation.

        Continuation lines should align wrapped elements either vertically
        using Python's implicit line joining inside parentheses, brackets
        and braces, or using a hanging indent.
        
        When using a hanging indent these considerations should be applied:
        - there should be no arguments on the first line, and
        - further indentation should be used to clearly distinguish itself
          as a continuation line.
        
        Okay: a = (\n)
        E123: a = (\n    )
        
        Okay: a = (\n    42)
        E121: a = (\n   42)
        E122: a = (\n42)
        E123: a = (\n    42\n    )
        E124: a = (24,\n     42\n)
        E125: if (\n    b):\n    pass
        E126: a = (\n        42)
        E127: a = (24,\n      42)
        E128: a = (24,\n    42)
        E129: if (a or\n    b):\n    pass
        E131: a = (\n    42\n 24)

        Missing whitespace around parameter equals
        Open

            def formfield_for_manytomany(self, db_field: Field, request: HttpRequest=None, **kwargs):
        Severity: Minor
        Found in serviceform/serviceform/admin.py by pep8

        Don't use spaces around the '=' sign in function arguments.

        Don't use spaces around the '=' sign when used to indicate a
        keyword argument or a default parameter value, except when
        using a type annotation.
        
        Okay: def complex(real, imag=0.0):
        Okay: return magic(r=real, i=imag)
        Okay: boolean(a == b)
        Okay: boolean(a != b)
        Okay: boolean(a <= b)
        Okay: boolean(a >= b)
        Okay: def foo(arg: int = 42):
        Okay: async def foo(arg: int = 42):
        
        E251: def complex(real, imag = 0.0):
        E251: return magic(r = real, i = imag)
        E252: def complex(real, image: float=0.0):

        Missing whitespace around parameter equals
        Open

            def get_inline_instances(self, request: HttpRequest, obj: models.ServiceForm=None):
        Severity: Minor
        Found in serviceform/serviceform/admin.py by pep8

        Don't use spaces around the '=' sign in function arguments.

        Don't use spaces around the '=' sign when used to indicate a
        keyword argument or a default parameter value, except when
        using a type annotation.
        
        Okay: def complex(real, imag=0.0):
        Okay: return magic(r=real, i=imag)
        Okay: boolean(a == b)
        Okay: boolean(a != b)
        Okay: boolean(a <= b)
        Okay: boolean(a >= b)
        Okay: def foo(arg: int = 42):
        Okay: async def foo(arg: int = 42):
        
        E251: def complex(real, imag = 0.0):
        E251: return magic(r = real, i = imag)
        E252: def complex(real, image: float=0.0):

        Missing whitespace around parameter equals
        Open

            def get_fieldsets(self, request: HttpRequest, obj: models.ServiceForm=None):
        Severity: Minor
        Found in serviceform/serviceform/admin.py by pep8

        Don't use spaces around the '=' sign in function arguments.

        Don't use spaces around the '=' sign when used to indicate a
        keyword argument or a default parameter value, except when
        using a type annotation.
        
        Okay: def complex(real, imag=0.0):
        Okay: return magic(r=real, i=imag)
        Okay: boolean(a == b)
        Okay: boolean(a != b)
        Okay: boolean(a <= b)
        Okay: boolean(a >= b)
        Okay: def foo(arg: int = 42):
        Okay: async def foo(arg: int = 42):
        
        E251: def complex(real, imag = 0.0):
        E251: return magic(r = real, i = imag)
        E252: def complex(real, image: float=0.0):

        Continuation line missing indentation or outdented
        Open

            ('required_year_of_birth', 'required_street_address', 'required_phone_number'),)
        Severity: Minor
        Found in serviceform/serviceform/admin.py by pep8

        Continuation lines indentation.

        Continuation lines should align wrapped elements either vertically
        using Python's implicit line joining inside parentheses, brackets
        and braces, or using a hanging indent.
        
        When using a hanging indent these considerations should be applied:
        - there should be no arguments on the first line, and
        - further indentation should be used to clearly distinguish itself
          as a continuation line.
        
        Okay: a = (\n)
        E123: a = (\n    )
        
        Okay: a = (\n    42)
        E121: a = (\n   42)
        E122: a = (\n42)
        E123: a = (\n    42\n    )
        E124: a = (24,\n     42\n)
        E125: if (\n    b):\n    pass
        E126: a = (\n        42)
        E127: a = (24,\n      42)
        E128: a = (24,\n    42)
        E129: if (a or\n    b):\n    pass
        E131: a = (\n    42\n 24)

        Missing whitespace around parameter equals
        Open

            def get_form(self, request: HttpRequest, obj: models.ServiceForm=None, **kwargs):
        Severity: Minor
        Found in serviceform/serviceform/admin.py by pep8

        Don't use spaces around the '=' sign in function arguments.

        Don't use spaces around the '=' sign when used to indicate a
        keyword argument or a default parameter value, except when
        using a type annotation.
        
        Okay: def complex(real, imag=0.0):
        Okay: return magic(r=real, i=imag)
        Okay: boolean(a == b)
        Okay: boolean(a != b)
        Okay: boolean(a <= b)
        Okay: boolean(a >= b)
        Okay: def foo(arg: int = 42):
        Okay: async def foo(arg: int = 42):
        
        E251: def complex(real, imag = 0.0):
        E251: return magic(r = real, i = imag)
        E252: def complex(real, image: float=0.0):

        Missing whitespace around parameter equals
        Open

            def get_form(self, request: HttpRequest, obj: models.ServiceForm=None, **kwargs):
        Severity: Minor
        Found in serviceform/serviceform/admin.py by pep8

        Don't use spaces around the '=' sign in function arguments.

        Don't use spaces around the '=' sign when used to indicate a
        keyword argument or a default parameter value, except when
        using a type annotation.
        
        Okay: def complex(real, imag=0.0):
        Okay: return magic(r=real, i=imag)
        Okay: boolean(a == b)
        Okay: boolean(a != b)
        Okay: boolean(a <= b)
        Okay: boolean(a >= b)
        Okay: def foo(arg: int = 42):
        Okay: async def foo(arg: int = 42):
        
        E251: def complex(real, imag = 0.0):
        E251: return magic(r = real, i = imag)
        E252: def complex(real, image: float=0.0):

        Missing whitespace around parameter equals
        Open

            def get_inline_instances(self, request: HttpRequest, obj: models.ServiceForm=None):
        Severity: Minor
        Found in serviceform/serviceform/admin.py by pep8

        Don't use spaces around the '=' sign in function arguments.

        Don't use spaces around the '=' sign when used to indicate a
        keyword argument or a default parameter value, except when
        using a type annotation.
        
        Okay: def complex(real, imag=0.0):
        Okay: return magic(r=real, i=imag)
        Okay: boolean(a == b)
        Okay: boolean(a != b)
        Okay: boolean(a <= b)
        Okay: boolean(a >= b)
        Okay: def foo(arg: int = 42):
        Okay: async def foo(arg: int = 42):
        
        E251: def complex(real, imag = 0.0):
        E251: return magic(r = real, i = imag)
        E252: def complex(real, image: float=0.0):

        Missing whitespace around parameter equals
        Open

            def formfield_for_manytomany(self, db_field: Field, request: HttpRequest=None, **kwargs):
        Severity: Minor
        Found in serviceform/serviceform/admin.py by pep8

        Don't use spaces around the '=' sign in function arguments.

        Don't use spaces around the '=' sign when used to indicate a
        keyword argument or a default parameter value, except when
        using a type annotation.
        
        Okay: def complex(real, imag=0.0):
        Okay: return magic(r=real, i=imag)
        Okay: boolean(a == b)
        Okay: boolean(a != b)
        Okay: boolean(a <= b)
        Okay: boolean(a >= b)
        Okay: def foo(arg: int = 42):
        Okay: async def foo(arg: int = 42):
        
        E251: def complex(real, imag = 0.0):
        E251: return magic(r = real, i = imag)
        E252: def complex(real, image: float=0.0):

        Missing whitespace around parameter equals
        Open

            def get_fieldsets(self, request: HttpRequest, obj: models.ServiceForm=None):
        Severity: Minor
        Found in serviceform/serviceform/admin.py by pep8

        Don't use spaces around the '=' sign in function arguments.

        Don't use spaces around the '=' sign when used to indicate a
        keyword argument or a default parameter value, except when
        using a type annotation.
        
        Okay: def complex(real, imag=0.0):
        Okay: return magic(r=real, i=imag)
        Okay: boolean(a == b)
        Okay: boolean(a != b)
        Okay: boolean(a <= b)
        Okay: boolean(a >= b)
        Okay: def foo(arg: int = 42):
        Okay: async def foo(arg: int = 42):
        
        E251: def complex(real, imag = 0.0):
        E251: return magic(r = real, i = imag)
        E252: def complex(real, image: float=0.0):

        There are no issues that match your filters.

        Category
        Status