divio/django-cms

View on GitHub
cms/admin/pageadmin.py

Summary

Maintainability
F
1 wk
Test Coverage

File pageadmin.py has 1416 lines of code (exceeds 250 allowed). Consider refactoring.
Open

import json
import re
import sys
import uuid
from collections import namedtuple
Severity: Major
Found in cms/admin/pageadmin.py - About 3 days to fix

    BasePageAdmin has 59 functions (exceeds 20 allowed). Consider refactoring.
    Open

    class BasePageAdmin(PlaceholderAdminMixin, admin.ModelAdmin):
        form = AddPageForm
        ordering = ('node__path',)
        search_fields = ('=id', 'title_set__slug', 'title_set__title', 'reverse_id')
        add_general_fields = ['title', 'slug', 'language', 'template']
    Severity: Major
    Found in cms/admin/pageadmin.py - About 1 day to fix

      Function publish_page has a Cognitive Complexity of 46 (exceeds 5 allowed). Consider refactoring.
      Open

          def publish_page(self, request, page_id, language):
              page = self.get_object(request, object_id=page_id)
      
              if page and not self.has_publish_permission(request, obj=page):
                  return HttpResponseForbidden(force_str(_("You do not have permission to publish this page")))
      Severity: Minor
      Found in cms/admin/pageadmin.py - About 7 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 resolve has a Cognitive Complexity of 41 (exceeds 5 allowed). Consider refactoring.
      Open

          def resolve(self, request):
              if not request.user.is_staff:
                  return HttpResponse('/', content_type='text/plain')
              obj = False
              url = False
      Severity: Minor
      Found in cms/admin/pageadmin.py - About 6 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_tree_rows has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring.
      Open

          def get_tree_rows(self, request, pages, language, depth=1,
                            follow_descendants=True):
              """
              Used for rendering the page tree, inserts into context everything what
              we need for single item
      Severity: Minor
      Found in cms/admin/pageadmin.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 delete_translation has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring.
      Open

          def delete_translation(self, request, object_id, extra_context=None):
              if 'delete_language' in request.GET:
                  language = request.GET['delete_language']
              elif 'delete_language' in request.POST:
                  language = request.POST['delete_language']
      Severity: Minor
      Found in cms/admin/pageadmin.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 changelist_view has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
      Open

          def changelist_view(self, request, extra_context=None):
              from django.contrib.admin.views.main import ERROR_FLAG
      
              if not self.has_change_permission(request, obj=None):
                  raise PermissionDenied
      Severity: Minor
      Found in cms/admin/pageadmin.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_copy_dialog has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
      Open

          def get_copy_dialog(self, request, page_id):
              if not get_cms_setting('PERMISSION'):
                  return HttpResponse('')
      
              page = self.get_page_from_id(page_id)
      Severity: Minor
      Found in cms/admin/pageadmin.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 edit_title_fields has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
      Open

          def edit_title_fields(self, request, page_id, language):
              page, translation = self.get_object_with_translation(
                  request=request,
                  object_id=page_id,
                  language=language,
      Severity: Minor
      Found in cms/admin/pageadmin.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 preview_page has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
      Open

          def preview_page(self, request, object_id, language):
              """
              Redirecting preview function based on draft_id
              """
              page = self.get_object(request, object_id=object_id)
      Severity: Minor
      Found in cms/admin/pageadmin.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 delete_view has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
      Open

          def delete_view(self, request, object_id, extra_context=None):
              # This is an unfortunate copy/paste from django's delete view.
              # The reason is to add the descendant pages to the deleted objects list.
              opts = self.model._meta
              app_label = opts.app_label
      Severity: Minor
      Found in cms/admin/pageadmin.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 render_change_form has 6 arguments (exceeds 4 allowed). Consider refactoring.
      Open

          def render_change_form(self, request, context, add=False, change=False, form_url='', obj=None):
      Severity: Minor
      Found in cms/admin/pageadmin.py - About 45 mins to fix

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

            def get_tree_rows(self, request, pages, language, depth=1,
        Severity: Minor
        Found in cms/admin/pageadmin.py - About 35 mins to fix

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

              def copy_page(self, request, page_id):
                  """
                  Copy the page and all its plugins and descendants to the requested
                  target, at the given position
                  """
          Severity: Minor
          Found in cms/admin/pageadmin.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_permissions has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
          Open

              def get_permissions(self, request, page_id):
                  rows = []
                  user = request.user
                  page = self.get_object(request, object_id=page_id)
          
          
          Severity: Minor
          Found in cms/admin/pageadmin.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_form_class has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
          Open

              def get_form_class(self, request, obj=None, **kwargs):
                  if 'advanced' in request.path_info:
                      return self.advanced_form
                  elif 'permission' in request.path_info:
                      return PagePermissionForm
          Severity: Minor
          Found in cms/admin/pageadmin.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 set_home has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
          Open

              def set_home(self, request, object_id):
                  page = self.get_object(request, object_id=object_id)
          
                  if not self.has_change_permission(request, page):
                      raise PermissionDenied("You do not have permission to set 'home'.")
          Severity: Minor
          Found in cms/admin/pageadmin.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 unpublish has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
          Open

              def unpublish(self, request, page_id, language):
                  """
                  Publish or unpublish a language of a page
                  """
                  page = self.get_object(request, object_id=page_id)
          Severity: Minor
          Found in cms/admin/pageadmin.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 copy_language has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
          Open

              def copy_language(self, request, page_id):
                  page = self.get_object(request, object_id=page_id)
                  source_language = request.POST.get('source_language')
                  target_language = request.POST.get('target_language')
          
          
          Severity: Minor
          Found in cms/admin/pageadmin.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 self.duplicate_form
          Severity: Major
          Found in cms/admin/pageadmin.py - About 30 mins to fix

            Avoid too many return statements within this function.
            Open

                    return HttpResponse(json.dumps({"id": new_page.pk}), content_type='application/json')
            Severity: Major
            Found in cms/admin/pageadmin.py - About 30 mins to fix

              Avoid too many return statements within this function.
              Open

                      return self.add_form
              Severity: Major
              Found in cms/admin/pageadmin.py - About 30 mins to fix

                Avoid too many return statements within this function.
                Open

                        return render(request, self.delete_confirmation_template or [
                Severity: Major
                Found in cms/admin/pageadmin.py - About 30 mins to fix

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

                      def change_view(self, request, object_id, form_url='', extra_context=None):
                          """
                          The 'change' admin view for the Page model.
                          """
                          if extra_context is None:
                  Severity: Minor
                  Found in cms/admin/pageadmin.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_add_permission_from_request has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                  Open

                      def _has_add_permission_from_request(self, request):
                          site = self.get_site(request)
                          parent_node_id = request.GET.get('parent_node', None)
                  
                          if parent_node_id:
                  Severity: Minor
                  Found in cms/admin/pageadmin.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