jazzband/django-simple-history

View on GitHub

Showing 20 of 50 total issues

File models.py has 999 lines of code (exceeds 500 allowed). Consider refactoring.
Open

import copy
import importlib
import uuid
import warnings
from collections.abc import Iterable, Sequence
Severity: Major
Found in simple_history/models.py - About 1 day to fix

    HistoricalRecords has 28 functions (exceeds 20 allowed). Consider refactoring.
    Open

    class HistoricalRecords:
    DEFAULT_MODEL_NAME_PREFIX = "Historical"
     
    thread = context = LocalContext() # retain thread for backwards compatibility
    m2m_models = {}
    Severity: Minor
    Found in simple_history/models.py - About 3 hrs to fix

      Function __init__ has 27 arguments (exceeds 7 allowed). Consider refactoring.
      Open

      def __init__(
      Severity: Major
      Found in simple_history/models.py - About 3 hrs to fix

        Function copy_fields has a Cognitive Complexity of 19 (exceeds 7 allowed). Consider refactoring.
        Open

        def copy_fields(self, model):
        """
        Creates copies of the model's original fields, returning
        a dictionary mapping field name to copied field object.
        """
        Severity: Minor
        Found in simple_history/models.py - About 2 hrs to fix

        SimpleHistoryAdmin has 21 functions (exceeds 20 allowed). Consider refactoring.
        Open

        class SimpleHistoryAdmin(admin.ModelAdmin):
        history_list_display = []
         
        object_history_template = "simple_history/object_history.html"
        object_history_list_template = "simple_history/object_history_list.html"
        Severity: Minor
        Found in simple_history/admin.py - About 2 hrs to fix

          Function _get_m2m_field_changes_for_diff has a Cognitive Complexity of 18 (exceeds 7 allowed). Consider refactoring.
          Open

          def _get_m2m_field_changes_for_diff(
          self,
          old_history: "HistoricalChanges",
          m2m_fields: Iterable[str],
          foreign_keys_are_objs: bool,
          Severity: Minor
          Found in simple_history/models.py - About 2 hrs to fix

          Function _get_field_changes_for_diff has a Cognitive Complexity of 17 (exceeds 7 allowed). Consider refactoring.
          Open

          def _get_field_changes_for_diff(
          self,
          old_history: "HistoricalChanges",
          fields: Iterable[str],
          foreign_keys_are_objs: bool,
          Severity: Minor
          Found in simple_history/models.py - About 1 hr to fix

          Function _process has a Cognitive Complexity of 16 (exceeds 7 allowed). Consider refactoring.
          Open

          def _process(self, to_process, date_back=None, dry_run=True):
          if date_back:
          stop_date = timezone.now() - timezone.timedelta(minutes=date_back)
          else:
          stop_date = None
          Severity: Minor
          Found in simple_history/management/commands/clean_duplicate_history.py - About 1 hr to fix

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

          def __init__(
          self,
          verbose_name=None,
          verbose_name_plural=None,
          bases=(models.Model,),
          Severity: Minor
          Found in simple_history/models.py - About 1 hr to fix

            Function history_view has a Cognitive Complexity of 12 (exceeds 7 allowed). Consider refactoring.
            Open

            def history_view(self, request, object_id, extra_context=None):
            """The 'history' admin view for this model."""
            request.current_app = self.admin_site.name
            model = self.model
            opts = model._meta
            Severity: Minor
            Found in simple_history/admin.py - About 1 hr to fix

            Function update_change_reason has a Cognitive Complexity of 10 (exceeds 7 allowed). Consider refactoring.
            Open

            def update_change_reason(instance, reason):
            attrs = {}
            model = type(instance)
            manager = instance if instance.pk is not None else model
            history = get_history_manager_for_model(manager)
            Severity: Minor
            Found in simple_history/utils.py - About 45 mins to fix

            Function bulk_create_with_history has a Cognitive Complexity of 10 (exceeds 7 allowed). Consider refactoring.
            Open

            def bulk_create_with_history(
            objs,
            model,
            batch_size=None,
            ignore_conflicts=False,
            Severity: Minor
            Found in simple_history/utils.py - About 45 mins to fix

            Function bulk_update_with_history has 9 arguments (exceeds 7 allowed). Consider refactoring.
            Open

            def bulk_update_with_history(
            Severity: Major
            Found in simple_history/utils.py - About 45 mins to fix

              Function bulk_create_with_history has 8 arguments (exceeds 7 allowed). Consider refactoring.
              Open

              def bulk_create_with_history(
              Severity: Major
              Found in simple_history/utils.py - About 35 mins to fix

                Function related_manager_cls has a Cognitive Complexity of 9 (exceeds 7 allowed). Consider refactoring.
                Open

                def related_manager_cls(self):
                related_model = self.rel.related_model
                 
                class HistoricRelationModelManager(related_model._default_manager.__class__):
                def get_queryset(self):
                Severity: Minor
                Found in simple_history/models.py - About 35 mins to fix

                Function transform_field has a Cognitive Complexity of 9 (exceeds 7 allowed). Consider refactoring.
                Open

                def transform_field(field):
                """Customize field appropriately for use in historical model"""
                field.name = field.attname
                if isinstance(field, models.BigAutoField):
                field.__class__ = models.BigIntegerField
                Severity: Minor
                Found in simple_history/models.py - About 35 mins to fix

                Function history_form_view has a Cognitive Complexity of 9 (exceeds 7 allowed). Consider refactoring.
                Open

                def history_form_view(self, request, object_id, version_id, extra_context=None):
                request.current_app = self.admin_site.name
                original_opts = self.model._meta
                model = getattr(
                self.model, self.model._meta.simple_history_manager_attribute
                Severity: Minor
                Found in simple_history/admin.py - About 35 mins to fix

                Function finalize has a Cognitive Complexity of 9 (exceeds 7 allowed). Consider refactoring.
                Open

                def finalize(self, sender, **kwargs):
                inherited = False
                if self.cls is not sender: # set in concrete
                inherited = self.inherit and issubclass(sender, self.cls)
                if not inherited:
                Severity: Minor
                Found in simple_history/models.py - About 35 mins to fix

                Function _bulk_history_create has a Cognitive Complexity of 8 (exceeds 7 allowed). Consider refactoring.
                Open

                def _bulk_history_create(self, model, batch_size):
                """Save a copy of all instances to the historical model.
                 
                :param model: Model you want to bulk create
                :param batch_size: number of models to create at once.
                Severity: Minor
                Found in simple_history/management/commands/populate_history.py - About 25 mins to fix

                Function handle has a Cognitive Complexity of 8 (exceeds 7 allowed). Consider refactoring.
                Open

                def handle(self, *args, **options):
                self.verbosity = options["verbosity"]
                 
                to_process = set()
                model_strings = options.get("models", []) or args
                Severity: Minor
                Found in simple_history/management/commands/populate_history.py - About 25 mins to fix
                Severity
                Category
                Status
                Source
                Language