django/django

View on GitHub
django/views/generic/dates.py

Summary

Maintainability
F
4 days
Test Coverage

File dates.py has 558 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

    Function _get_next_prev has a Cognitive Complexity of 25 (exceeds 5 allowed). Consider refactoring.
    Open

    def _get_next_prev(generic_view, date, is_previous, period):
        """
        Get the next or the previous valid date. The idea is to allow links on
        month/day views to never be 404s by never providing a date that'll be
        invalid for the given view.
    Severity: Minor
    Found in django/views/generic/dates.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 _date_from_string has 7 arguments (exceeds 4 allowed). Consider refactoring.
    Open

    def _date_from_string(year, year_format, month='', month_format='', day='', day_format='', delim='__'):
    Severity: Major
    Found in django/views/generic/dates.py - About 50 mins to fix

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

          def get_dated_queryset(self, **lookup):
              """
              Get a queryset properly filtered according to `allow_future` and any
              extra lookup kwargs.
              """
      Severity: Minor
      Found in django/views/generic/dates.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_month has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
      Open

          def get_month(self):
              """Return the month for which this view should display data."""
              month = self.month
              if month is None:
                  try:
      Severity: Minor
      Found in django/views/generic/dates.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

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

          def get_year(self):
              """Return the year for which this view should display data."""
              year = self.year
              if year is None:
                  try:
      Severity: Minor
      Found in django/views/generic/dates.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

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

          def get_day(self):
              """Return the day for which this view should display data."""
              day = self.day
              if day is None:
                  try:
      Severity: Minor
      Found in django/views/generic/dates.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

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

          def get_week(self):
              """Return the week for which this view should display data."""
              week = self.week
              if week is None:
                  try:
      Severity: Minor
      Found in django/views/generic/dates.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 4 locations. Consider refactoring.
      Open

          def get_month(self):
              """Return the month for which this view should display data."""
              month = self.month
              if month is None:
                  try:
      Severity: Major
      Found in django/views/generic/dates.py and 3 other locations - About 4 hrs to fix
      django/views/generic/dates.py on lines 31..42
      django/views/generic/dates.py on lines 132..143
      django/views/generic/dates.py on lines 178..189

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

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

          def get_year(self):
              """Return the year for which this view should display data."""
              year = self.year
              if year is None:
                  try:
      Severity: Major
      Found in django/views/generic/dates.py and 3 other locations - About 4 hrs to fix
      django/views/generic/dates.py on lines 80..91
      django/views/generic/dates.py on lines 132..143
      django/views/generic/dates.py on lines 178..189

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

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

          def get_week(self):
              """Return the week for which this view should display data."""
              week = self.week
              if week is None:
                  try:
      Severity: Major
      Found in django/views/generic/dates.py and 3 other locations - About 4 hrs to fix
      django/views/generic/dates.py on lines 31..42
      django/views/generic/dates.py on lines 80..91
      django/views/generic/dates.py on lines 132..143

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

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

          def get_day(self):
              """Return the day for which this view should display data."""
              day = self.day
              if day is None:
                  try:
      Severity: Major
      Found in django/views/generic/dates.py and 3 other locations - About 4 hrs to fix
      django/views/generic/dates.py on lines 31..42
      django/views/generic/dates.py on lines 80..91
      django/views/generic/dates.py on lines 178..189

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

      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

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

              if date.month == 12:
                  try:
                      return date.replace(year=date.year + 1, month=1, day=1)
                  except ValueError:
                      raise Http404(_("Date out of range"))
      Severity: Major
      Found in django/views/generic/dates.py and 1 other location - About 1 hr to fix
      django/views/generic/dates.py on lines 58..61

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

      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

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

              try:
                  return date.replace(year=date.year + 1, month=1, day=1)
              except ValueError:
                  raise Http404(_("Date out of range"))
      Severity: Major
      Found in django/views/generic/dates.py and 1 other location - About 1 hr to fix
      django/views/generic/dates.py on lines 107..111

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

      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