django/django

View on GitHub

Showing 599 of 2,094 total issues

Similar blocks of code found in 2 locations. Consider refactoring.
Open

            if delta.days != 0:
                return cls.time_strings["past-day"] % {
                    "delta": defaultfilters.timesince(
                        value, now, time_strings=cls.past_substrings
                    ),
Severity: Major
Found in django/contrib/humanize/templatetags/humanize.py and 1 other location - About 1 day to fix
django/contrib/humanize/templatetags/humanize.py on lines 310..325

Duplicated Code

Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

Tuning

This issue has a mass of 200.

We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

Refactorings

Further Reading

Similar blocks of code found in 2 locations. Consider refactoring.
Open

            if delta.days != 0:
                return cls.time_strings["future-day"] % {
                    "delta": defaultfilters.timeuntil(
                        value, now, time_strings=cls.future_substrings
                    ),
Severity: Major
Found in django/contrib/humanize/templatetags/humanize.py and 1 other location - About 1 day to fix
django/contrib/humanize/templatetags/humanize.py on lines 292..307

Duplicated Code

Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

Tuning

This issue has a mass of 200.

We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

Refactorings

Further Reading

File defaultfilters.py has 765 lines of code (exceeds 250 allowed). Consider refactoring.
Open

"""Default variable filters."""

import random as random_module
import re
import types
Severity: Major
Found in django/template/defaultfilters.py - About 1 day to fix

    QuerySet has 91 functions (exceeds 20 allowed). Consider refactoring.
    Open

    class QuerySet(AltersData):
        """Represent a lazy database lookup for a set of objects."""
    
        def __init__(self, model=None, query=None, using=None, hints=None):
            self.model = model
    Severity: Major
    Found in django/db/models/query.py - About 1 day to fix

      Query has 90 functions (exceeds 20 allowed). Consider refactoring.
      Open

      class Query(BaseExpression):
          """A single SQL query."""
      
          alias_prefix = "T"
          empty_result_set_value = None
      Severity: Major
      Found in django/db/models/sql/query.py - About 1 day to fix

        File resolvers.py has 693 lines of code (exceeds 250 allowed). Consider refactoring.
        Open

        """
        This module converts requested URLs to callback view functions.
        
        URLResolver is the main class here. Its resolve() method takes a URL (as
        a string) and returns a ResolverMatch object which provides access to all
        Severity: Major
        Found in django/urls/resolvers.py - About 1 day to fix

          File makemessages.py has 688 lines of code (exceeds 250 allowed). Consider refactoring.
          Open

          import glob
          import os
          import re
          import sys
          from functools import total_ordering
          Severity: Major
          Found in django/core/management/commands/makemessages.py - About 1 day to fix

            GEOSGeometryBase has 83 functions (exceeds 20 allowed). Consider refactoring.
            Open

            class GEOSGeometryBase(GEOSBase):
                _GEOS_CLASSES = None
            
                ptr_type = GEOM_PTR
                destructor = capi.destroy_geom
            Severity: Major
            Found in django/contrib/gis/geos/geometry.py - About 1 day to fix

              File operations.py has 684 lines of code (exceeds 250 allowed). Consider refactoring.
              Open

              import datetime
              import decimal
              import json
              import warnings
              from importlib import import_module
              Severity: Major
              Found in django/db/backends/base/operations.py - About 1 day to fix

                File fields.py has 669 lines of code (exceeds 250 allowed). Consider refactoring.
                Open

                import functools
                import itertools
                import warnings
                from collections import defaultdict
                
                
                Severity: Major
                Found in django/contrib/contenttypes/fields.py - About 1 day to fix

                  BaseDatabaseSchemaEditor has 77 functions (exceeds 20 allowed). Consider refactoring.
                  Open

                  class BaseDatabaseSchemaEditor:
                      """
                      This class and its subclasses are responsible for emitting schema-changing
                      statements to the databases - model creation/removal/alteration, field
                      renaming, index fiddling, and so on.
                  Severity: Major
                  Found in django/db/backends/base/schema.py - About 1 day to fix

                    BaseDatabaseOperations has 77 functions (exceeds 20 allowed). Consider refactoring.
                    Open

                    class BaseDatabaseOperations:
                        """
                        Encapsulate backend-specific differences, such as the way a backend
                        performs ordering or calculates the ID of a recently-inserted row.
                        """
                    Severity: Major
                    Found in django/db/backends/base/operations.py - About 1 day to fix

                      File geometries.py has 630 lines of code (exceeds 250 allowed). Consider refactoring.
                      Open

                      """
                       The OGRGeometry is a wrapper for using the OGR Geometry class
                       (see https://gdal.org/api/ogrgeometry_cpp.html#_CPPv411OGRGeometry).
                       OGRGeometry may be instantiated when reading geometries from OGR Data Sources
                       (e.g. SHP files), or when given OGC WKT (a string).
                      Severity: Major
                      Found in django/contrib/gis/gdal/geometries.py - About 1 day to fix

                        File __init__.py has 627 lines of code (exceeds 250 allowed). Consider refactoring.
                        Open

                        """
                        LANG_INFO is a dictionary structure to provide meta information about languages.
                        
                        About name_local: capitalize it as if your language name was appearing
                        inside a sentence in your language.
                        Severity: Major
                        Found in django/conf/locale/__init__.py - About 1 day to fix

                          File geometry.py has 624 lines of code (exceeds 250 allowed). Consider refactoring.
                          Open

                          """
                           This module contains the 'base' GEOSGeometry object -- all GEOS Geometries
                           inherit from this object.
                          """
                          
                          
                          Severity: Major
                          Found in django/contrib/gis/geos/geometry.py - About 1 day to fix

                            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

                              File constraints.py has 616 lines of code (exceeds 250 allowed). Consider refactoring.
                              Open

                              import warnings
                              from enum import Enum
                              from types import NoneType
                              
                              from django.core import checks
                              Severity: Major
                              Found in django/db/models/constraints.py - About 1 day to fix

                                File base.py has 616 lines of code (exceeds 250 allowed). Consider refactoring.
                                Open

                                import _thread
                                import copy
                                import datetime
                                import logging
                                import threading
                                Severity: Major
                                Found in django/db/backends/base/base.py - About 1 day to fix

                                  File dates.py has 612 lines of code (exceeds 250 allowed). Consider refactoring.
                                  Open

                                  import datetime
                                  
                                  from django.conf import settings
                                  from django.core.exceptions import ImproperlyConfigured
                                  from django.db import models
                                  Severity: Major
                                  Found in django/views/generic/dates.py - About 1 day to fix

                                    File operations.py has 607 lines of code (exceeds 250 allowed). Consider refactoring.
                                    Open

                                    import datetime
                                    import uuid
                                    from functools import lru_cache
                                    
                                    from django.conf import settings
                                    Severity: Major
                                    Found in django/db/backends/oracle/operations.py - About 1 day to fix
                                      Severity
                                      Category
                                      Status
                                      Source
                                      Language