django/django

View on GitHub
django/forms/formsets.py

Summary

Maintainability
D
3 days
Test Coverage

File formsets.py has 362 lines of code (exceeds 250 allowed). Consider refactoring.
Open

from django.core.exceptions import ValidationError
from django.forms import Form
from django.forms.fields import BooleanField, IntegerField
from django.forms.utils import ErrorList
from django.forms.widgets import HiddenInput, NumberInput
Severity: Minor
Found in django/forms/formsets.py - About 4 hrs to fix

    BaseFormSet has 35 functions (exceeds 20 allowed). Consider refactoring.
    Open

    class BaseFormSet:
        """
        A collection of instances of the same Form class.
        """
        ordering_widget = NumberInput
    Severity: Minor
    Found in django/forms/formsets.py - About 4 hrs to fix

      Function ordered_forms has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
      Open

          def ordered_forms(self):
              """
              Return a list of form in the order specified by the incoming data.
              Raise an AttributeError if ordering is not allowed.
              """
      Severity: Minor
      Found in django/forms/formsets.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 deleted_forms has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
      Open

          def deleted_forms(self):
              """Return a list of forms that have been marked for deletion."""
              if not self.is_valid() or not self.can_delete:
                  return []
              # construct _deleted_form_indexes which is just a list of form indexes
      Severity: Minor
      Found in django/forms/formsets.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 full_clean has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
      Open

          def full_clean(self):
              """
              Clean all of self.data and populate self._errors and
              self._non_form_errors.
              """
      Severity: Minor
      Found in django/forms/formsets.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 formset_factory has 9 arguments (exceeds 4 allowed). Consider refactoring.
      Open

      def formset_factory(form, formset=BaseFormSet, extra=1, can_order=False,
      Severity: Major
      Found in django/forms/formsets.py - About 1 hr to fix

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

            def __init__(self, data=None, files=None, auto_id='id_%s', prefix=None,
        Severity: Major
        Found in django/forms/formsets.py - About 50 mins to fix

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

              def _construct_form(self, i, **kwargs):
                  """Instantiate and return the i-th form instance in a formset."""
                  defaults = {
                      'auto_id': self.auto_id,
                      'prefix': self.add_prefix(i),
          Severity: Minor
          Found in django/forms/formsets.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

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

              def as_ul(self):
                  "Return this formset rendered as HTML <li>s."
                  forms = ' '.join(form.as_ul() for form in self)
                  return mark_safe(str(self.management_form) + '\n' + forms)
          Severity: Major
          Found in django/forms/formsets.py and 2 other locations - About 2 hrs to fix
          django/forms/formsets.py on lines 415..421
          django/forms/formsets.py on lines 423..426

          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 57.

          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 3 locations. Consider refactoring.
          Open

              def as_p(self):
                  "Return this formset rendered as HTML <p>s."
                  forms = ' '.join(form.as_p() for form in self)
                  return mark_safe(str(self.management_form) + '\n' + forms)
          Severity: Major
          Found in django/forms/formsets.py and 2 other locations - About 2 hrs to fix
          django/forms/formsets.py on lines 415..421
          django/forms/formsets.py on lines 428..431

          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 57.

          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 3 locations. Consider refactoring.
          Open

              def as_table(self):
                  "Return this formset rendered as HTML <tr>s -- excluding the <table></table>."
                  # XXX: there is no semantic division between forms here, there
                  # probably should be. It might make sense to render each form as a
                  # table row with each field as a td.
          Severity: Major
          Found in django/forms/formsets.py and 2 other locations - About 2 hrs to fix
          django/forms/formsets.py on lines 423..426
          django/forms/formsets.py on lines 428..431

          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 57.

          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

          There are no issues that match your filters.

          Category
          Status