django/django

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

Summary

Maintainability
F
1 wk
Test Coverage

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

import copy
import enum
import json
import re
import warnings
Severity: Major
Found in django/contrib/admin/options.py - About 5 days to fix

    Function _changeform_view has a Cognitive Complexity of 45 (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 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 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 get_search_results has a Cognitive Complexity of 27 (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

    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 lookup_allowed has a Cognitive Complexity of 25 (exceeds 5 allowed). Consider refactoring.
    Open

        def lookup_allowed(self, lookup, value, request=None):
            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 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 _create_formsets has a Cognitive Complexity of 17 (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 17 (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 formfield_for_manytomany has a Cognitive Complexity of 13 (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 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."
              app_label = self.opts.app_label
      
              to_field = request.POST.get(TO_FIELD_VAR, request.GET.get(TO_FIELD_VAR))
      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

      Consider simplifying this complex logical expression.
      Open

                  if not prev_field or (
                      prev_field.is_relation
                      and field not in model._meta.parents.values()
                      and field is not model._meta.auto_field
                      and (
      Severity: Critical
      Found in django/contrib/admin/options.py - About 1 hr to fix

        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_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 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 render_change_form has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
        Open

            def render_change_form(
                self, request, context, add=False, change=False, form_url="", obj=None
            ):
                app_label = self.opts.app_label
                preserved_filters = self.get_preserved_filters(request)
        Severity: Minor
        Found in django/contrib/admin/options.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 7 arguments (exceeds 4 allowed). Consider refactoring.
        Open

            def render_change_form(
        Severity: Major
        Found in django/contrib/admin/options.py - About 50 mins to fix

          Function get_paginator has 6 arguments (exceeds 4 allowed). Consider refactoring.
          Open

              def get_paginator(
          Severity: Minor
          Found in django/contrib/admin/options.py - About 45 mins to fix

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

                def message_user(
            Severity: Minor
            Found in django/contrib/admin/options.py - About 45 mins to fix

              Avoid deeply nested control flow statements.
              Open

                                      if form.has_changed():
                                          obj = self.save_form(request, form, change=True)
                                          self.save_model(request, obj, form, change=True)
                                          self.save_related(request, form, formsets=[], change=True)
                                          change_msg = self.construct_change_message(
              Severity: Major
              Found in django/contrib/admin/options.py - About 45 mins to fix

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

                    def save_formset(self, request, form, formset, change):
                Severity: Minor
                Found in django/contrib/admin/options.py - About 35 mins to fix

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

                      def save_related(self, request, form, formsets, change):
                  Severity: Minor
                  Found in django/contrib/admin/options.py - About 35 mins to fix

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

                        def construct_change_message(self, request, form, formsets, add=False):
                    Severity: Minor
                    Found in django/contrib/admin/options.py - About 35 mins to fix

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

                          def get_form(self, request, obj=None, change=False, **kwargs):
                      Severity: Minor
                      Found in django/contrib/admin/options.py - About 35 mins to fix

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

                            def get_inline_formsets(self, request, formsets, inline_instances, obj=None):
                        Severity: Minor
                        Found in django/contrib/admin/options.py - About 35 mins to fix

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

                              def save_model(self, request, obj, form, change):
                          Severity: Minor
                          Found in django/contrib/admin/options.py - About 35 mins to fix

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

                                def change_view(self, request, object_id, form_url="", extra_context=None):
                            Severity: Minor
                            Found in django/contrib/admin/options.py - About 35 mins to fix

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

                                  def _changeform_view(self, request, object_id, form_url, extra_context):
                              Severity: Minor
                              Found in django/contrib/admin/options.py - About 35 mins to fix

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

                                    def changeform_view(self, request, object_id=None, form_url="", extra_context=None):
                                Severity: Minor
                                Found in django/contrib/admin/options.py - About 35 mins to fix

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

                                      def get_formset_kwargs(self, request, obj, inline, prefix):
                                  Severity: Minor
                                  Found in django/contrib/admin/options.py - About 35 mins to fix

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

                                                def user_deleted_form(request, obj, formset, index, inline):
                                    Severity: Minor
                                    Found in django/contrib/admin/options.py - About 35 mins to fix

                                      Function response_change has a Cognitive Complexity of 7 (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 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 TemplateResponse(
                                      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 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 "%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

                                                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