divio/django-cms

View on GitHub
cms/cms_toolbars.py

Summary

Maintainability
F
5 days
Test Coverage

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

# -*- coding: utf-8 -*-
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
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

      Avoid deeply nested control flow statements.
      Open

                              if path == TEMPLATE_INHERITANCE_MAGIC:
                                  templates_menu.add_break(TEMPLATE_MENU_BREAK)
                              templates_menu.add_ajax_item(name, action=action, data={'template': path}, active=active,
      Severity: Major
      Found in cms/cms_toolbars.py - About 45 mins to fix

        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_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 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

        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 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

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

                    if self.page.is_page_type:
                        delete_url = admin_reverse('cms_pagetype_delete', args=(self.page.pk,))
                    else:
                        delete_url = admin_reverse('cms_page_delete', args=(self.page.pk,))
        Severity: Major
        Found in cms/cms_toolbars.py and 4 other locations - About 1 hr to fix
        cms/cms_toolbars.py on lines 481..484
        cms/cms_toolbars.py on lines 491..494
        cms/cms_toolbars.py on lines 507..510
        cms/cms_toolbars.py on lines 637..640

        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 47.

        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 5 locations. Consider refactoring.
        Open

                        if self.page.is_page_type:
                            translation_delete_url = admin_reverse('cms_pagetype_delete_translation', args=(self.page.pk,))
                        else:
                            translation_delete_url = admin_reverse('cms_page_delete_translation', args=(self.page.pk,))
        Severity: Major
        Found in cms/cms_toolbars.py and 4 other locations - About 1 hr to fix
        cms/cms_toolbars.py on lines 481..484
        cms/cms_toolbars.py on lines 507..510
        cms/cms_toolbars.py on lines 637..640
        cms/cms_toolbars.py on lines 742..745

        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 47.

        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 5 locations. Consider refactoring.
        Open

                        if self.page.is_page_type:
                            page_change_url = admin_reverse('cms_pagetype_change', args=(self.page.pk,))
                        else:
                            page_change_url = admin_reverse('cms_page_change', args=(self.page.pk,))
        Severity: Major
        Found in cms/cms_toolbars.py and 4 other locations - About 1 hr to fix
        cms/cms_toolbars.py on lines 491..494
        cms/cms_toolbars.py on lines 507..510
        cms/cms_toolbars.py on lines 637..640
        cms/cms_toolbars.py on lines 742..745

        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 47.

        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 5 locations. Consider refactoring.
        Open

                        if self.page.is_page_type:
                            page_copy_url = admin_reverse('cms_pagetype_copy_language', args=(self.page.pk,))
                        else:
                            page_copy_url = admin_reverse('cms_page_copy_language', args=(self.page.pk,))
        Severity: Major
        Found in cms/cms_toolbars.py and 4 other locations - About 1 hr to fix
        cms/cms_toolbars.py on lines 481..484
        cms/cms_toolbars.py on lines 491..494
        cms/cms_toolbars.py on lines 637..640
        cms/cms_toolbars.py on lines 742..745

        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 47.

        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 5 locations. Consider refactoring.
        Open

                        if self.page.is_page_type:
                            action = admin_reverse('cms_pagetype_change_template', args=(self.page.pk,))
                        else:
                            action = admin_reverse('cms_page_change_template', args=(self.page.pk,))
        Severity: Major
        Found in cms/cms_toolbars.py and 4 other locations - About 1 hr to fix
        cms/cms_toolbars.py on lines 481..484
        cms/cms_toolbars.py on lines 491..494
        cms/cms_toolbars.py on lines 507..510
        cms/cms_toolbars.py on lines 742..745

        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 47.

        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 toolbar.structure_mode_active and not toolbar.uses_legacy_structure_mode:
                        # User has explicitly requested structure mode
                        # and the object (page, blog, etc..) allows for the non-legacy structure mode
                        renderer = toolbar.structure_renderer
                    else:
        Severity: Minor
        Found in cms/cms_toolbars.py and 1 other location - About 40 mins to fix
        cms/toolbar/toolbar.py on lines 438..443

        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 34.

        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

                        current_page_menu.add_ajax_item(
                            nav_title,
                            action=nav_action,
                            disabled=(not edit_mode or not can_change),
        Severity: Minor
        Found in cms/cms_toolbars.py and 1 other location - About 30 mins to fix
        cms/cms_toolbars.py on lines 710..713

        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 32.

        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

                        current_page_menu.add_ajax_item(
                            publish_title,
                            action=publish_url,
                            disabled=not edit_mode or not user_can_publish,
        Severity: Minor
        Found in cms/cms_toolbars.py and 1 other location - About 30 mins to fix
        cms/cms_toolbars.py on lines 693..696

        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 32.

        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