divio/django-cms

View on GitHub
menus/templatetags/menu_tags.py

Summary

Maintainability
D
2 days
Test Coverage

File menu_tags.py has 344 lines of code (exceeds 250 allowed). Consider refactoring.
Open

# -*- coding: utf-8 -*-
from django import template
from django.contrib.sites.models import Site
from django.urls import reverse, NoReverseMatch
from django.utils.encoding import force_text
Severity: Minor
Found in menus/templatetags/menu_tags.py - About 4 hrs to fix

    Function get_context has a Cognitive Complexity of 27 (exceeds 5 allowed). Consider refactoring.
    Open

        def get_context(self, context, levels, root_level, nephews, template):
            # Django 1.4 doesn't accept 'None' as a tag value and resolve to ''
            # So we need to force it to None again
            if not root_level and root_level != 0:
                root_level = None
    Severity: Minor
    Found in menus/templatetags/menu_tags.py - About 3 hrs 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 cut_levels has a Cognitive Complexity of 21 (exceeds 5 allowed). Consider refactoring.
    Open

    def cut_levels(nodes, from_level, to_level, extra_inactive, extra_active):
        """
        cutting nodes away from menus
        """
        final = []
    Severity: Minor
    Found in menus/templatetags/menu_tags.py - About 2 hrs 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_context has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring.
    Open

        def get_context(self, context, start_level, template, only_visible):
            try:
                # If there's an exception (500), default context_processors may not be called.
                request = context['request']
            except KeyError:
    Severity: Minor
    Found in menus/templatetags/menu_tags.py - About 2 hrs 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_context has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring.
    Open

        def get_context(self, context, from_level, to_level, extra_inactive,
                        extra_active, template, namespace, root_id, next_page):
            try:
                # If there's an exception (500), default context_processors may not be called.
                request = context['request']
    Severity: Minor
    Found in menus/templatetags/menu_tags.py - About 2 hrs 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 cut_after has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
    Open

    def cut_after(node, levels, removed):
        """
        given a tree of nodes cuts after N levels
        """
        if levels == 0:
    Severity: Minor
    Found in menus/templatetags/menu_tags.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_context has 9 arguments (exceeds 4 allowed). Consider refactoring.
    Open

        def get_context(self, context, from_level, to_level, extra_inactive,
    Severity: Major
    Found in menus/templatetags/menu_tags.py - About 1 hr to fix

      Function get_context has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
      Open

          def get_context(self, context, template, i18n_mode):
              if template in MARKERS:
                  _tmp = template
                  if i18n_mode not in MARKERS:
                      template = i18n_mode
      Severity: Minor
      Found in menus/templatetags/menu_tags.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_context has 5 arguments (exceeds 4 allowed). Consider refactoring.
      Open

          def get_context(self, context, levels, root_level, nephews, template):
      Severity: Minor
      Found in menus/templatetags/menu_tags.py - About 35 mins to fix

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

        def cut_levels(nodes, from_level, to_level, extra_inactive, extra_active):
        Severity: Minor
        Found in menus/templatetags/menu_tags.py - About 35 mins to fix

          There are no issues that match your filters.

          Category
          Status