django/django

View on GitHub
django/contrib/admin/options.py

Summary

Maintainability
F
1 wk
Test Coverage

File options.py has 1757 lines of code (exceeds 250 allowed). Consider refactoring.
Open

import copy
import json
import operator
import re
from functools import partial, reduce, update_wrapper
Severity: Major
Found in django/contrib/admin/options.py - About 4 days to fix

    ModelAdmin has 65 functions (exceeds 20 allowed). Consider refactoring.
    Open

    class ModelAdmin(BaseModelAdmin):
        """Encapsulate all admin options and functionality for a given model."""
    
        list_display = ('__str__',)
        list_display_links = ()
    Severity: Major
    Found in django/contrib/admin/options.py - About 1 day to fix

      Function changelist_view has a Cognitive Complexity of 43 (exceeds 5 allowed). Consider refactoring.
      Open

          def changelist_view(self, request, extra_context=None):
              """
              The 'change list' admin view for this model.
              """
              from django.contrib.admin.views.main import ERROR_FLAG
      Severity: Minor
      Found in django/contrib/admin/options.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 _changeform_view has a Cognitive Complexity of 37 (exceeds 5 allowed). Consider refactoring.
      Open

          def _changeform_view(self, request, object_id, form_url, extra_context):
              to_field = request.POST.get(TO_FIELD_VAR, request.GET.get(TO_FIELD_VAR))
              if to_field and not self.to_field_allowed(request, to_field):
                  raise DisallowedModelAdminToField("The field %s cannot be referenced." % to_field)
      
      
      Severity: Minor
      Found in django/contrib/admin/options.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

      Function get_formset has a Cognitive Complexity of 25 (exceeds 5 allowed). Consider refactoring.
      Open

          def get_formset(self, request, obj=None, **kwargs):
              """Return a BaseInlineFormSet class for use in admin add/change views."""
              if 'fields' in kwargs:
                  fields = kwargs.pop('fields')
              else:
      Severity: Minor
      Found in django/contrib/admin/options.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_search_results has a Cognitive Complexity of 24 (exceeds 5 allowed). Consider refactoring.
      Open

          def get_search_results(self, request, queryset, search_term):
              """
              Return a tuple containing a queryset to implement the search
              and a boolean indicating if the results may contain duplicates.
              """
      Severity: Minor
      Found in django/contrib/admin/options.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

      BaseModelAdmin has 27 functions (exceeds 20 allowed). Consider refactoring.
      Open

      class BaseModelAdmin(metaclass=forms.MediaDefiningClass):
          """Functionality common to both ModelAdmin and InlineAdmin."""
      
          autocomplete_fields = ()
          raw_id_fields = ()
      Severity: Minor
      Found in django/contrib/admin/options.py - About 3 hrs to fix

        Function lookup_allowed has a Cognitive Complexity of 19 (exceeds 5 allowed). Consider refactoring.
        Open

            def lookup_allowed(self, lookup, value):
                from django.contrib.admin.filters import SimpleListFilter
        
                model = self.model
                # Check FKey lookups that are allowed, so that popups produced by
        Severity: Minor
        Found in django/contrib/admin/options.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 _create_formsets has a Cognitive Complexity of 19 (exceeds 5 allowed). Consider refactoring.
        Open

            def _create_formsets(self, request, obj, change):
                "Helper function to generate formsets for add/change_view."
                formsets = []
                inline_instances = []
                prefixes = {}
        Severity: Minor
        Found in django/contrib/admin/options.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 formfield_for_dbfield has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring.
        Open

            def formfield_for_dbfield(self, db_field, request, **kwargs):
                """
                Hook for specifying the form Field instance for a given database Field
                instance.
        
        
        Severity: Minor
        Found in django/contrib/admin/options.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 response_add has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
        Open

            def response_add(self, request, obj, post_url_continue=None):
                """
                Determine the HttpResponse for the add_view stage.
                """
                opts = obj._meta
        Severity: Minor
        Found in django/contrib/admin/options.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 to_field_allowed has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
        Open

            def to_field_allowed(self, request, to_field):
                """
                Return True if the model associated with this admin should be
                allowed to be referenced by the specified field.
                """
        Severity: Minor
        Found in django/contrib/admin/options.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 _delete_view has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
        Open

            def _delete_view(self, request, object_id, extra_context):
                "The 'delete' admin view for this model."
                opts = self.model._meta
                app_label = opts.app_label
        
        
        Severity: Minor
        Found in django/contrib/admin/options.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 response_action has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
        Open

            def response_action(self, request, queryset):
                """
                Handle an admin action. This is called if a request is POSTed to the
                changelist; it returns an HttpResponse if the action was handled, and
                None otherwise.
        Severity: Minor
        Found in django/contrib/admin/options.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 formfield_for_manytomany has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
        Open

            def formfield_for_manytomany(self, db_field, request, **kwargs):
                """
                Get a form Field for a ManyToManyField.
                """
                # If it uses an intermediary model that isn't auto created, don't show
        Severity: Minor
        Found in django/contrib/admin/options.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 formfield_for_foreignkey has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
        Open

            def formfield_for_foreignkey(self, db_field, request, **kwargs):
                """
                Get a form Field for a ForeignKey.
                """
                db = kwargs.get('using')
        Severity: Minor
        Found in django/contrib/admin/options.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_inline_instances has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
        Open

            def get_inline_instances(self, request, obj=None):
                inline_instances = []
                for inline_class in self.get_inlines(request, obj):
                    inline = inline_class(self.model, self.admin_site)
                    if request:
        Severity: Minor
        Found in django/contrib/admin/options.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_form has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
        Open

            def get_form(self, request, obj=None, change=False, **kwargs):
                """
                Return a Form class for use in the admin add view. This is used by
                add_view and change_view.
                """
        Severity: Minor
        Found in django/contrib/admin/options.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 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 django/contrib/admin/options.py - About 45 mins to fix

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

              def render_change_form(self, request, context, add=False, change=False, form_url='', obj=None):
                  opts = self.model._meta
                  app_label = opts.app_label
                  preserved_filters = self.get_preserved_filters(request)
                  form_url = add_preserved_filters({'preserved_filters': preserved_filters, 'opts': opts}, form_url)
          Severity: Minor
          Found in django/contrib/admin/options.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 response_change has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
          Open

              def response_change(self, request, obj):
                  """
                  Determine the HttpResponse for the change_view stage.
                  """
          
          
          Severity: Minor
          Found in django/contrib/admin/options.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 get_paginator has 5 arguments (exceeds 4 allowed). Consider refactoring.
          Open

              def get_paginator(self, request, queryset, per_page, orphans=0, allow_empty_first_page=True):
          Severity: Minor
          Found in django/contrib/admin/options.py - About 35 mins to fix

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

                def message_user(self, request, message, level=messages.INFO, extra_tags='',
            Severity: Minor
            Found in django/contrib/admin/options.py - About 35 mins to fix

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

                  def get_action(self, action):
                      """
                      Return a given action from a parameter, which can either be a callable,
                      or the name of a method on the ModelAdmin.  Return is a tuple of
                      (callable, name, description).
              Severity: Minor
              Found in django/contrib/admin/options.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 False
              Severity: Major
              Found in django/contrib/admin/options.py - About 30 mins to fix

                Avoid too many return statements within this function.
                Open

                                return HttpResponseRedirect(request.get_full_path())
                Severity: Major
                Found in django/contrib/admin/options.py - About 30 mins to fix

                  Avoid too many return statements within this function.
                  Open

                              return "%s__icontains" % field_name
                  Severity: Major
                  Found in django/contrib/admin/options.py - About 30 mins to fix

                    Avoid too many return statements within this function.
                    Open

                                return HttpResponseRedirect(request.get_full_path())
                    Severity: Major
                    Found in django/contrib/admin/options.py - About 30 mins to fix

                      Avoid too many return statements within this function.
                      Open

                              return TemplateResponse(request, self.change_list_template or [
                      Severity: Major
                      Found in django/contrib/admin/options.py - About 30 mins to fix

                        Avoid too many return statements within this function.
                        Open

                                    return self.response_post_save_change(request, obj)
                        Severity: Major
                        Found in django/contrib/admin/options.py - About 30 mins to fix

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

                              def get_preserved_filters(self, request):
                                  """
                                  Return the preserved filters querystring.
                                  """
                                  match = request.resolver_match
                          Severity: Minor
                          Found in django/contrib/admin/options.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