divio/django-cms

View on GitHub
cms/toolbar/toolbar.py

Summary

Maintainability
F
3 days
Test Coverage

File toolbar.py has 395 lines of code (exceeds 250 allowed). Consider refactoring.
Open

import functools
import operator
from collections import OrderedDict

from classytags.utils import flatten_context
Severity: Minor
Found in cms/toolbar/toolbar.py - About 5 hrs to fix

    CMSToolbar has 30 functions (exceeds 20 allowed). Consider refactoring.
    Open

    class CMSToolbar(BaseToolbar):
        """
        The default CMS Toolbar
        """
    
    
    Severity: Minor
    Found in cms/toolbar/toolbar.py - About 3 hrs to fix

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

          def init_toolbar(self, request, request_path=None):
              self.request = request
              self.is_staff = self.request.user.is_staff
              self.show_toolbar = self.is_staff or self.request.session.get('cms_edit', False)
      
      
      Severity: Minor
      Found in cms/toolbar/toolbar.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 add_sideframe_button has 9 arguments (exceeds 4 allowed). Consider refactoring.
      Open

          def add_sideframe_button(self, name, url, active=False, disabled=False, extra_classes=None, extra_wrapper_classes=None,
      Severity: Major
      Found in cms/toolbar/toolbar.py - About 1 hr to fix

        Function add_modal_button has 9 arguments (exceeds 4 allowed). Consider refactoring.
        Open

            def add_modal_button(self, name, url, active=False, disabled=False, extra_classes=None, extra_wrapper_classes=None,
        Severity: Major
        Found in cms/toolbar/toolbar.py - About 1 hr to fix

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

              def _add_item(self, item, position=None):
                  item.toolbar = self
          
                  if item.right:
                      if position and position < 0:
          Severity: Minor
          Found in cms/toolbar/toolbar.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 add_button has 8 arguments (exceeds 4 allowed). Consider refactoring.
          Open

              def add_button(self, name, url, active=False, disabled=False, extra_classes=None, extra_wrapper_classes=None,
          Severity: Major
          Found in cms/toolbar/toolbar.py - About 1 hr to fix

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

                def __init__(self, request, request_path=None, _async=False):
                    super().__init__()
                    self._async = _async
                    self.right_items = []
                    self.left_items = []
            Severity: Minor
            Found in cms/toolbar/toolbar.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_or_create_menu has 5 arguments (exceeds 4 allowed). Consider refactoring.
            Open

                def get_or_create_menu(self, key, verbose_name=None, disabled=False, side=LEFT, position=None):
            Severity: Minor
            Found in cms/toolbar/toolbar.py - About 35 mins to fix

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

                  def get_or_create_menu(self, key, verbose_name=None, disabled=False, side=LEFT, position=None):
                      self.populate()
                      if key in self.menus:
                          menu = self.menus[key]
                          if verbose_name:
              Severity: Minor
              Found in cms/toolbar/toolbar.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_object_draft_url has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
              Open

                  def get_object_draft_url(self):
                      if self.obj:
                          with force_language(self.request_language):
                              try:
                                  return self.obj.get_draft_url()
              Severity: Minor
              Found in cms/toolbar/toolbar.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 _call_toolbar has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
              Open

                  def _call_toolbar(self, func_name):
                      with force_language(self.toolbar_language):
                          first = ('cms.cms_toolbars.BasicToolbar', 'cms.cms_toolbars.PlaceholderToolbar')
              
                          for key in first:
              Severity: Minor
              Found in cms/toolbar/toolbar.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

              Similar blocks of code found in 2 locations. Consider refactoring.
              Open

                  def add_modal_button(self, name, url, active=False, disabled=False, extra_classes=None, extra_wrapper_classes=None,
                                 side=LEFT, position=None, on_close=REFRESH_PAGE):
                      self.populate()
                      item = ButtonList(extra_classes=extra_wrapper_classes, side=side)
                      item.add_modal_button(name, url, active=active, disabled=disabled, extra_classes=extra_classes, on_close=on_close)
              Severity: Major
              Found in cms/toolbar/toolbar.py and 1 other location - About 4 hrs to fix
              cms/toolbar/toolbar.py on lines 284..290

              Duplicated Code

              Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

              Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

              When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

              Tuning

              This issue has a mass of 83.

              We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

              The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

              If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

              See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

              Refactorings

              Further Reading

              Similar blocks of code found in 2 locations. Consider refactoring.
              Open

                  def add_sideframe_button(self, name, url, active=False, disabled=False, extra_classes=None, extra_wrapper_classes=None,
                                 side=LEFT, position=None, on_close=None):
                      self.populate()
                      item = ButtonList(extra_classes=extra_wrapper_classes, side=side)
                      item.add_sideframe_button(name, url, active=active, disabled=disabled, extra_classes=extra_classes, on_close=on_close)
              Severity: Major
              Found in cms/toolbar/toolbar.py and 1 other location - About 4 hrs to fix
              cms/toolbar/toolbar.py on lines 276..282

              Duplicated Code

              Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

              Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

              When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

              Tuning

              This issue has a mass of 83.

              We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

              The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

              If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

              See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

              Refactorings

              Further Reading

              Similar blocks of code found in 2 locations. Consider refactoring.
              Open

                  def get_left_items(self):
                      self.populate()
                      items = self.left_items + list(reversed(self.last_left_items))
                      return items
              Severity: Major
              Found in cms/toolbar/toolbar.py and 1 other location - About 1 hr to fix
              cms/toolbar/toolbar.py on lines 378..381

              Duplicated Code

              Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

              Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

              When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

              Tuning

              This issue has a mass of 39.

              We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

              The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

              If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

              See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

              Refactorings

              Further Reading

              Similar blocks of code found in 2 locations. Consider refactoring.
              Open

                  def get_right_items(self):
                      self.populate()
                      items = self.right_items + list(reversed(self.last_right_items))
                      return items
              Severity: Major
              Found in cms/toolbar/toolbar.py and 1 other location - About 1 hr to fix
              cms/toolbar/toolbar.py on lines 373..376

              Duplicated Code

              Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

              Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

              When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

              Tuning

              This issue has a mass of 39.

              We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

              The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

              If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

              See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

              Refactorings

              Further Reading

              Similar blocks of code found in 2 locations. Consider refactoring.
              Open

                      if item.right:
                          if position and position < 0:
                              target = self.last_right_items
                              position = abs(position)
                          else:
              Severity: Major
              Found in cms/toolbar/toolbar.py and 1 other location - About 1 hr to fix
              cms/toolbar/toolbar.py on lines 338..349

              Duplicated Code

              Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

              Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

              When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

              Tuning

              This issue has a mass of 39.

              We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

              The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

              If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

              See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

              Refactorings

              Further Reading

              There are no issues that match your filters.

              Category
              Status