divio/django-cms

View on GitHub
cms/models/pagemodel.py

Summary

Maintainability
F
1 wk
Test Coverage

File pagemodel.py has 1273 lines of code (exceeds 250 allowed). Consider refactoring.
Open

import copy
from collections import OrderedDict
from logging import getLogger
from os.path import join

Severity: Major
Found in cms/models/pagemodel.py - About 3 days to fix

    Page has 93 functions (exceeds 20 allowed). Consider refactoring.
    Open

    class Page(models.Model):
        """
        A simple hierarchical page model
        """
        LIMIT_VISIBILITY_IN_MENU_CHOICES = (
    Severity: Major
    Found in cms/models/pagemodel.py - About 1 day to fix

      Function copy has a Cognitive Complexity of 22 (exceeds 5 allowed). Consider refactoring.
      Open

          def copy(self, site, parent_node=None, language=None,
                   translations=True, permissions=False, extensions=True):
              from cms.utils.page import get_available_slug
      
              if parent_node:
      Severity: Minor
      Found in cms/models/pagemodel.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 get_admin_tree_title has a Cognitive Complexity of 21 (exceeds 5 allowed). Consider refactoring.
      Open

          def get_admin_tree_title(self):
              from cms.models.titlemodels import EmptyTitle
              language = get_language()
      
              if not self.title_cache:
      Severity: Minor
      Found in cms/models/pagemodel.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 move_page has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
      Open

          def move_page(self, target_node, position='first-child'):
              """
              Called from admin interface when page is moved. Should be used on
              all the places which are changing page position. Used like an interface
              to django-treebeard, but after move is done page_moved signal is fired.
      Severity: Minor
      Found in cms/models/pagemodel.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_title_cache has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
      Open

          def _get_title_cache(self, language, fallback, force_reload):
              if not language:
                  language = get_language()
      
              force_reload = (force_reload or language not in self.title_cache)
      Severity: Minor
      Found in cms/models/pagemodel.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 copy_with_descendants has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
      Open

          def copy_with_descendants(self, target_node=None, position=None,
                                    copy_permissions=True, target_site=None):
              """
              Copy a page [ and all its descendants to a new location ]
              """
      Severity: Minor
      Found in cms/models/pagemodel.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 copy has 7 arguments (exceeds 4 allowed). Consider refactoring.
      Open

          def copy(self, site, parent_node=None, language=None,
      Severity: Major
      Found in cms/models/pagemodel.py - About 50 mins to fix

        Function publish has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
        Open

            def publish(self, language):
                """
                :returns: True if page was successfully published.
                """
                from cms.utils.permissions import get_current_user_name
        Severity: Minor
        Found in cms/models/pagemodel.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 is_new_dirty has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
        Open

            def is_new_dirty(self):
                if self.pk:
                    fields = [
                        'publication_date', 'publication_end_date', 'in_navigation', 'soft_root', 'reverse_id',
                        'navigation_extenders', 'template', 'login_required', 'limit_visibility_in_menu'
        Severity: Minor
        Found in cms/models/pagemodel.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 copy_with_descendants has 5 arguments (exceeds 4 allowed). Consider refactoring.
        Open

            def copy_with_descendants(self, target_node=None, position=None,
        Severity: Minor
        Found in cms/models/pagemodel.py - About 35 mins to fix

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

              def get_title_obj_attribute(self, attrname, language=None, fallback=True, force_reload=False):
          Severity: Minor
          Found in cms/models/pagemodel.py - About 35 mins to fix

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

                def _update_title_path_recursive(self, language, slug=None):
                    assert self.publisher_is_draft
                    from cms.models import Title
            
                    if self.node.is_leaf() or language not in self.get_languages():
            Severity: Minor
            Found in cms/models/pagemodel.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 title.slug
            Severity: Major
            Found in cms/models/pagemodel.py - About 30 mins to fix

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

                  def clear_cache(self, language=None, menu=False, placeholder=False):
                      from cms.cache import invalidate_cms_page_cache
              
                      if get_cms_setting('PAGE_CACHE'):
                          # Clears all the page caches
              Severity: Minor
              Found in cms/models/pagemodel.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 update has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
              Open

                  def update(self, refresh=False, draft_only=True, **data):
                      assert self.publisher_is_draft
              
                      cls = self.__class__
              
              
              Severity: Minor
              Found in cms/models/pagemodel.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 save has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
              Open

                  def save(self, **kwargs):
                      # delete template cache
                      if hasattr(self, '_template_cache'):
                          delattr(self, '_template_cache')
              
              
              Severity: Minor
              Found in cms/models/pagemodel.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 rescan_placeholders has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
              Open

                  def rescan_placeholders(self):
                      """
                      Rescan and if necessary create placeholders in the current template.
                      """
                      existing = OrderedDict()
              Severity: Minor
              Found in cms/models/pagemodel.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