divio/django-cms

View on GitHub
cms/cms_toolbars.py

Summary

Maintainability
F
4 days
Test Coverage

File cms_toolbars.py has 626 lines of code (exceeds 250 allowed). Consider refactoring.
Open

from django.conf import settings
from django.contrib import admin
from django.contrib.auth import get_permission_codename, get_user_model
from django.contrib.auth.models import AnonymousUser
from django.contrib.sites.models import Site
Severity: Major
Found in cms/cms_toolbars.py - About 1 day to fix

    Function add_page_menu has a Cognitive Complexity of 58 (exceeds 5 allowed). Consider refactoring.
    Open

        def add_page_menu(self):
            if self.page:
                edit_mode = self.toolbar.edit_mode_active
                refresh = self.toolbar.REFRESH_PAGE
                can_change = user_can_change_page(
    Severity: Minor
    Found in cms/cms_toolbars.py - About 1 day 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 change_language_menu has a Cognitive Complexity of 36 (exceeds 5 allowed). Consider refactoring.
    Open

        def change_language_menu(self):
            if self.toolbar.edit_mode_active and self.page:
                can_change = page_permissions.user_can_change_page(
                    user=self.request.user,
                    page=self.page,
    Severity: Minor
    Found in cms/cms_toolbars.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

    PageToolbar has 24 functions (exceeds 20 allowed). Consider refactoring.
    Open

    class PageToolbar(CMSToolbar):
        _changed_admin_menu = None
        watch_models = [Page, PageType]
    
        def init_placeholders(self):
    Severity: Minor
    Found in cms/cms_toolbars.py - About 2 hrs to fix

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

          def add_draft_live(self):
              if self.page:
                  if self.toolbar.edit_mode_active and not self.title:
                      self.add_page_settings_button()
      
      
      Severity: Minor
      Found in cms/cms_toolbars.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 add_admin_menu has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
      Open

          def add_admin_menu(self):
              if not self._admin_menu:
                  self._admin_menu = self.toolbar.get_or_create_menu(ADMIN_MENU_IDENTIFIER, self.current_site.name)
                  # Users button
                  self.add_users_button(self._admin_menu)
      Severity: Minor
      Found in cms/cms_toolbars.py - About 45 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 add_help_menu has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
      Open

          def add_help_menu(self):
              """ Adds the help menu if it's enabled in settings """
              if get_cms_setting('ENABLE_HELP'):
                  self._help_menu = self.toolbar.get_or_create_menu(HELP_MENU_IDENTIFIER, _('Help'), position=-1)
                  self._help_menu.items = []  # reset the items so we don't duplicate
      Severity: Minor
      Found in cms/cms_toolbars.py - About 45 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 deeply nested control flow statements.
      Open

                              if path == TEMPLATE_INHERITANCE_MAGIC:
                                  templates_menu.add_break(TEMPLATE_MENU_BREAK)
                              templates_menu.add_ajax_item(
      Severity: Major
      Found in cms/cms_toolbars.py - About 45 mins to fix

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

            def add_structure_mode(self):
                if self.page and not self.page.application_urls:
                    if user_can_change_page(self.request.user, page=self.page):
                        return self.add_structure_mode_item()
        
        
        Severity: Minor
        Found in cms/cms_toolbars.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 get_publish_button has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
        Open

            def get_publish_button(self, classes=None):
                dirty = self.has_dirty_objects()
                classes = list(classes or [])
        
                if dirty and 'cms-btn-publish-active' not in classes:
        Severity: Minor
        Found in cms/cms_toolbars.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 add_language_menu has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
        Open

            def add_language_menu(self):
                if settings.USE_I18N and not self._language_menu:
                    self._language_menu = self.toolbar.get_or_create_menu(LANGUAGE_MENU_IDENTIFIER, _('Language'), position=-1)
                    language_changer = getattr(self.request, '_language_changer', DefaultLanguageChanger(self.request))
                    for code, name in get_language_tuple(self.current_site.pk):
        Severity: Minor
        Found in cms/cms_toolbars.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

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

            def add_logout_button(self, parent):
                # If current page is not published or has view restrictions user is redirected to the home page:
                # * published page: no redirect
                # * unpublished page: redirect to the home page
                # * published page with login_required: redirect to the home page
        Severity: Minor
        Found in cms/cms_toolbars.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

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

            def has_dirty_objects(self):
                language = self.current_lang
        
                if self.page:
                    if self.dirty_statics:
        Severity: Minor
        Found in cms/cms_toolbars.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

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

            def init_placeholders(self):
                request = self.request
                toolbar = self.toolbar
        
                if toolbar._async and 'placeholders[]' in request.GET:
        Severity: Minor
        Found in cms/cms_toolbars.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