divio/django-cms

View on GitHub
cms/templatetags/cms_tags.py

Summary

Maintainability
F
5 days
Test Coverage

File cms_tags.py has 851 lines of code (exceeds 250 allowed). Consider refactoring.
Open

from collections import OrderedDict, namedtuple
from copy import copy
from datetime import datetime

from classytags.arguments import Argument, MultiKeywordArgument, MultiValueArgument
Severity: Major
Found in cms/templatetags/cms_tags.py - About 2 days to fix

    Function _get_editable_context has a Cognitive Complexity of 38 (exceeds 5 allowed). Consider refactoring.
    Open

        def _get_editable_context(self, context, instance, language, edit_fields,
                                  view_method, view_url, querystring, editmode=True):
            """
            Populate the context with the requested attributes to trigger the change form
            """
    Severity: Minor
    Found in cms/templatetags/cms_tags.py - About 5 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_page_by_untyped_arg has a Cognitive Complexity of 29 (exceeds 5 allowed). Consider refactoring.
    Open

    def _get_page_by_untyped_arg(page_lookup, request, site_id):
        """
        The `page_lookup` argument can be of any of the following types:
        - Integer: interpreted as `pk` of the desired page
        - String: interpreted as `reverse_id` of the desired page
    Severity: Minor
    Found in cms/templatetags/cms_tags.py - About 4 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_data_context has a Cognitive Complexity of 19 (exceeds 5 allowed). Consider refactoring.
    Open

        def _get_data_context(self, context, instance, attribute, edit_fields,
                              language, filters, view_url, view_method):
            """
            Renders the requested attribute and attach changeform trigger to it
    
    
    Severity: Minor
    Found in cms/templatetags/cms_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 render_extra_menu_items has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
    Open

    def render_extra_menu_items(context, obj, template='cms/toolbar/dragitem_extra_menu.html'):
        request = context['request']
        toolbar = get_toolbar_from_request(request)
        template = toolbar.templates.get_cached_template(template)
    
    
    Severity: Minor
    Found in cms/templatetags/cms_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_data_context has 8 arguments (exceeds 4 allowed). Consider refactoring.
    Open

        def _get_data_context(self, context, instance, attribute, edit_fields,
    Severity: Major
    Found in cms/templatetags/cms_tags.py - About 1 hr to fix

      Function _get_editable_context has 8 arguments (exceeds 4 allowed). Consider refactoring.
      Open

          def _get_editable_context(self, context, instance, language, edit_fields,
      Severity: Major
      Found in cms/templatetags/cms_tags.py - About 1 hr to fix

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

            def render_tag(self, context, code, extra_bits, nodelist=None):
                request = context.get('request')
        
                if not code or not request:
                    # an empty string was passed in or the variable is not available in the context
        Severity: Minor
        Found in cms/templatetags/cms_tags.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 _get_empty_context has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
        Open

            def _get_empty_context(self, context, instance, edit_fields, language,
                                   view_url, view_method, editmode=True):
                """
                Inject in a copy of the context the data requested to trigger the edit.
        
        
        Severity: Minor
        Found in cms/templatetags/cms_tags.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 _get_empty_context has 7 arguments (exceeds 4 allowed). Consider refactoring.
        Open

            def _get_empty_context(self, context, instance, edit_fields, language,
        Severity: Major
        Found in cms/templatetags/cms_tags.py - About 50 mins to fix

          Function _show_placeholder_by_id has 6 arguments (exceeds 4 allowed). Consider refactoring.
          Open

          def _show_placeholder_by_id(context, placeholder_name, reverse_id,
          Severity: Minor
          Found in cms/templatetags/cms_tags.py - About 45 mins to fix

            Function get_context has 6 arguments (exceeds 4 allowed). Consider refactoring.
            Open

                def get_context(self, context, instance, language, view_url, view_method,
            Severity: Minor
            Found in cms/templatetags/cms_tags.py - About 45 mins to fix

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

                  def _get_content(self, context, instance, attribute, language, filters):
              Severity: Minor
              Found in cms/templatetags/cms_tags.py - About 35 mins to fix

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

                    def _get_content(self, context, instance, attribute, language, filters):
                        """
                        Renders the requested attribute
                        """
                        extra_context = copy(context)
                Severity: Minor
                Found in cms/templatetags/cms_tags.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

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

                def _show_placeholder_by_id(context, placeholder_name, reverse_id,
                                            lang=None, site=None, use_cache=True):
                    validate_placeholder_name(placeholder_name)
                
                    request = context['request']
                Severity: Minor
                Found in cms/templatetags/cms_tags.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

                Avoid too many return statements within this function.
                Open

                            return pages.select_related('node').get(**page_lookup)
                Severity: Major
                Found in cms/templatetags/cms_tags.py - About 30 mins to fix

                  Avoid too many return statements within this function.
                  Open

                                      return page.publisher_public
                  Severity: Major
                  Found in cms/templatetags/cms_tags.py - About 30 mins to fix

                    Avoid too many return statements within this function.
                    Open

                                return None
                    Severity: Major
                    Found in cms/templatetags/cms_tags.py - About 30 mins to fix

                      Avoid too many return statements within this function.
                      Open

                                          return page
                      Severity: Major
                      Found in cms/templatetags/cms_tags.py - About 30 mins to fix

                        Avoid too many return statements within this function.
                        Open

                                            return page.publisher_draft
                        Severity: Major
                        Found in cms/templatetags/cms_tags.py - About 30 mins to fix

                          Function get_value has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                          Open

                              def get_value(self, context, page_lookup, lang, site):
                          
                                  site_id = get_site_id(site)
                                  request = context.get('request', False)
                          
                          
                          Severity: Minor
                          Found in cms/templatetags/cms_tags.py - About 25 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

                          There are no issues that match your filters.

                          Category
                          Status