django/django

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

Summary

Maintainability
D
2 days
Test Coverage

File filters.py has 620 lines of code (exceeds 250 allowed). Consider refactoring.
Open

"""
This encapsulates the logic for displaying filters in the Django admin.
Filters are specified in models with the "list_filter" option.

Each filter subclass knows how to display a filter for a field that passes a
Severity: Major
Found in django/contrib/admin/filters.py - About 1 day to fix

    Function choices has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
    Open

        def choices(self, changelist):
            add_facets = changelist.add_facets
            facet_counts = self.get_facet_queryset(changelist) if add_facets else None
            yield {
                "selected": self.lookup_val is None and self.lookup_val_isnull is None,
    Severity: Minor
    Found in django/contrib/admin/filters.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 choices has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
    Open

        def choices(self, changelist):
            field_choices = dict(self.field.flatchoices)
            add_facets = changelist.add_facets
            facet_counts = self.get_facet_queryset(changelist) if add_facets else None
            for lookup, title, count_field in (
    Severity: Minor
    Found in django/contrib/admin/filters.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 6 arguments (exceeds 4 allowed). Consider refactoring.
    Open

        def __init__(self, field, request, params, model, model_admin, field_path):
    Severity: Minor
    Found in django/contrib/admin/filters.py - About 45 mins to fix

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

          def __init__(self, field, request, params, model, model_admin, field_path):
      Severity: Minor
      Found in django/contrib/admin/filters.py - About 45 mins to fix

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

            def __init__(self, field, request, params, model, model_admin, field_path):
        Severity: Minor
        Found in django/contrib/admin/filters.py - About 45 mins to fix

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

              def create(cls, field, request, params, model, model_admin, field_path):
          Severity: Minor
          Found in django/contrib/admin/filters.py - About 45 mins to fix

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

                def __init__(self, field, request, params, model, model_admin, field_path):
            Severity: Minor
            Found in django/contrib/admin/filters.py - About 45 mins to fix

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

                  def __init__(self, field, request, params, model, model_admin, field_path):
              Severity: Minor
              Found in django/contrib/admin/filters.py - About 45 mins to fix

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

                    def __init__(self, field, request, params, model, model_admin, field_path):
                Severity: Minor
                Found in django/contrib/admin/filters.py - About 45 mins to fix

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

                      def choices(self, changelist):
                          add_facets = changelist.add_facets
                          facet_counts = self.get_facet_queryset(changelist) if add_facets else None
                          yield {
                              "selected": self.value() is None,
                  Severity: Minor
                  Found in django/contrib/admin/filters.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 __init__ has 6 arguments (exceeds 4 allowed). Consider refactoring.
                  Open

                      def __init__(self, field, request, params, model, model_admin, field_path):
                  Severity: Minor
                  Found in django/contrib/admin/filters.py - About 45 mins to fix

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

                        def choices(self, changelist):
                            add_facets = changelist.add_facets
                            facet_counts = self.get_facet_queryset(changelist) if add_facets else None
                            yield {
                                "selected": self.lookup_val is None,
                    Severity: Minor
                    Found in django/contrib/admin/filters.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 choices has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                    Open

                        def choices(self, changelist):
                            add_facets = changelist.add_facets
                            facet_counts = self.get_facet_queryset(changelist) if add_facets else None
                            yield {
                                "selected": self.lookup_val is None and not self.lookup_val_isnull,
                    Severity: Minor
                    Found in django/contrib/admin/filters.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 choices has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                    Open

                        def choices(self, changelist):
                            add_facets = changelist.add_facets
                            facet_counts = self.get_facet_queryset(changelist) if add_facets else None
                            for lookup, title, count_field in (
                                (None, _("All"), None),
                    Severity: Minor
                    Found in django/contrib/admin/filters.py - About 35 mins to fix

                    Cognitive Complexity

                    Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

                    A method's cognitive complexity is based on a few simple rules:

                    • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
                    • Code is considered more complex for each "break in the linear flow of the code"
                    • Code is considered more complex when "flow breaking structures are nested"

                    Further reading

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

                        def __init__(self, field, request, params, model, model_admin, field_path):
                            self.field_generic = "%s__" % field_path
                            self.date_params = {
                                k: v[-1] for k, v in params.items() if k.startswith(self.field_generic)
                            }
                    Severity: Minor
                    Found in django/contrib/admin/filters.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