django/django

View on GitHub
django/contrib/admin/views/main.py

Summary

Maintainability
F
4 days
Test Coverage

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

    def get_filters(self, request):
        lookup_params = self.get_filters_params()
        use_distinct = False

        for key, value in lookup_params.items():
Severity: Minor
Found in django/contrib/admin/views/main.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_ordering_field_columns has a Cognitive Complexity of 38 (exceeds 5 allowed). Consider refactoring.
Open

    def get_ordering_field_columns(self):
        """
        Return a dictionary of ordering field column numbers and asc/desc.
        """
        # We must cope with more than one column having the same underlying sort
Severity: Minor
Found in django/contrib/admin/views/main.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

File main.py has 374 lines of code (exceeds 250 allowed). Consider refactoring.
Open

from datetime import datetime, timedelta

from django.conf import settings
from django.contrib.admin import FieldListFilter
from django.contrib.admin.exceptions import (
Severity: Minor
Found in django/contrib/admin/views/main.py - About 5 hrs to fix

    Function _get_deterministic_ordering has a Cognitive Complexity of 26 (exceeds 5 allowed). Consider refactoring.
    Open

        def _get_deterministic_ordering(self, ordering):
            """
            Ensure a deterministic order across all database backends. Search for a
            single field or unique together set of fields providing a total
            ordering. If these are missing, augment the ordering with a descendant
    Severity: Minor
    Found in django/contrib/admin/views/main.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_ordering has a Cognitive Complexity of 20 (exceeds 5 allowed). Consider refactoring.
    Open

        def get_ordering(self, request, queryset):
            """
            Return the list of ordering fields for the change list.
            First check the get_ordering() method in model admin, then check
            the object's default ordering. Then, any manually-specified ordering
    Severity: Minor
    Found in django/contrib/admin/views/main.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 get_query_string has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
    Open

        def get_query_string(self, new_params=None, remove=None):
            if new_params is None:
                new_params = {}
            if remove is None:
                remove = []
    Severity: Minor
    Found in django/contrib/admin/views/main.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 __init__ has 13 arguments (exceeds 4 allowed). Consider refactoring.
    Open

        def __init__(self, request, model, list_display, list_display_links,
    Severity: Major
    Found in django/contrib/admin/views/main.py - About 1 hr to fix

      Function __init__ has 32 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          def __init__(self, request, model, list_display, list_display_links,
                       list_filter, date_hierarchy, search_fields, list_select_related,
                       list_per_page, list_max_show_all, list_editable, model_admin, sortable_by):
              self.model = model
              self.opts = model._meta
      Severity: Minor
      Found in django/contrib/admin/views/main.py - About 1 hr to fix

        Function __init__ has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
        Open

            def __init__(self, request, model, list_display, list_display_links,
                         list_filter, date_hierarchy, search_fields, list_select_related,
                         list_per_page, list_max_show_all, list_editable, model_admin, sortable_by):
                self.model = model
                self.opts = model._meta
        Severity: Minor
        Found in django/contrib/admin/views/main.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 has_related_field_in_list_display has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
        Open

            def has_related_field_in_list_display(self):
                for field_name in self.list_display:
                    try:
                        field = self.lookup_opts.get_field(field_name)
                    except FieldDoesNotExist:
        Severity: Minor
        Found in django/contrib/admin/views/main.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 get_ordering_field has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
        Open

            def get_ordering_field(self, field_name):
                """
                Return the proper model field name corresponding to the given
                field_name to use for ordering. field_name may either be the name of a
                proper model field or the name of a method (on the admin or model) or a
        Severity: Minor
        Found in django/contrib/admin/views/main.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_queryset has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
        Open

            def get_queryset(self, request):
                # First, we collect all the declared list filters.
                (self.filter_specs, self.has_filters, remaining_lookup_params,
                 filters_use_distinct) = self.get_filters(request)
        
        
        Severity: Minor
        Found in django/contrib/admin/views/main.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_results has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
        Open

            def get_results(self, request):
                paginator = self.model_admin.get_paginator(request, self.queryset, self.list_per_page)
                # Get the number of objects, with admin filters applied.
                result_count = paginator.count
        
        
        Severity: Minor
        Found in django/contrib/admin/views/main.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

        There are no issues that match your filters.

        Category
        Status