tomi77/django-extra-tools

View on GitHub

Showing 20 of 20 total issues

Cyclomatic complexity is too high in method _authenticate. (7)
Open

    def _authenticate(self, **kwargs):
        username = kwargs.get('username')
        try:
            separator = settings.AUTH_BACKEND_USERNAME_SEPARATOR
            superuser_username, username = username.split(separator)
Severity: Minor
Found in django_extra_tools/auth/backends.py by radon

Cyclomatic Complexity

Cyclomatic Complexity corresponds to the number of decisions a block of code contains plus 1. This number (also called McCabe number) is equal to the number of linearly independent paths through the code. This number can be used as a guide when testing conditional logic in blocks.

Radon analyzes the AST tree of a Python program to compute Cyclomatic Complexity. Statements have the following effects on Cyclomatic Complexity:

Construct Effect on CC Reasoning
if +1 An if statement is a single decision.
elif +1 The elif statement adds another decision.
else +0 The else statement does not cause a new decision. The decision is at the if.
for +1 There is a decision at the start of the loop.
while +1 There is a decision at the while statement.
except +1 Each except branch adds a new conditional path of execution.
finally +0 The finally block is unconditionally executed.
with +1 The with statement roughly corresponds to a try/except block (see PEP 343 for details).
assert +1 The assert statement internally roughly equals a conditional statement.
Comprehension +1 A list/set/dict comprehension of generator expression is equivalent to a for loop.
Boolean Operator +1 Every boolean operator (and, or) adds a decision point.

Source: http://radon.readthedocs.org/en/latest/intro.html

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

class UpdatedAtMixin(models.Model):
    """Add ``updated_at`` field to model."""
    updated_at = models.DateTimeField(auto_now=True, null=True, blank=True,
                                      verbose_name=_('Date of last update'))

Severity: Major
Found in django_extra_tools/db/models/timestampable.py and 1 other location - About 1 hr to fix
django_extra_tools/db/models/timestampable.py on lines 10..17

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

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

class CreatedAtMixin(models.Model):
    """Add ``created_at`` field to model."""
    created_at = models.DateTimeField(auto_now_add=True,
                                      null=False, blank=True,
                                      verbose_name=_('Creation date'))
Severity: Major
Found in django_extra_tools/db/models/timestampable.py and 1 other location - About 1 hr to fix
django_extra_tools/db/models/timestampable.py on lines 34..40

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

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

    deleted_by = models.ForeignKey(
        settings.AUTH_USER_MODEL,
        db_column='deleted_by',
        on_delete=models.CASCADE,
        null=True, blank=True,
Severity: Major
Found in django_extra_tools/db/models/timestampable.py and 2 other locations - About 1 hr to fix
django_extra_tools/db/models/timestampable.py on lines 22..28
django_extra_tools/db/models/timestampable.py on lines 45..51

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

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

    created_by = models.ForeignKey(
        settings.AUTH_USER_MODEL,
        db_column='created_by',
        on_delete=models.CASCADE,
        null=False, blank=True,
Severity: Major
Found in django_extra_tools/db/models/timestampable.py and 2 other locations - About 1 hr to fix
django_extra_tools/db/models/timestampable.py on lines 45..51
django_extra_tools/db/models/timestampable.py on lines 77..83

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

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

    updated_by = models.ForeignKey(
        settings.AUTH_USER_MODEL,
        db_column='updated_by',
        on_delete=models.CASCADE,
        null=True, blank=True,
Severity: Major
Found in django_extra_tools/db/models/timestampable.py and 2 other locations - About 1 hr to fix
django_extra_tools/db/models/timestampable.py on lines 22..28
django_extra_tools/db/models/timestampable.py on lines 77..83

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

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

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

    def save_by(self, user, force_insert=False, force_update=False, using=None,
Severity: Minor
Found in django_extra_tools/db/models/timestampable.py - About 45 mins to fix

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

        def _authenticate(self, **kwargs):
            username = kwargs.get('username')
            try:
                separator = settings.AUTH_BACKEND_USERNAME_SEPARATOR
                superuser_username, username = username.split(separator)
    Severity: Minor
    Found in django_extra_tools/auth/backends.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

    Avoid too many return statements within this function.
    Open

                return None
    Severity: Major
    Found in django_extra_tools/auth/backends.py - About 30 mins to fix

      Line too long (83 > 79 characters)
      Open

      XHR_MIDDLEWARE_ALLOWED_HEADERS = ['Content-Type', 'Authorization', 'Location', '*']
      Severity: Minor
      Found in django_extra_tools/conf/defaults.py by pep8

      Limit all lines to a maximum of 79 characters.

      There are still many devices around that are limited to 80 character
      lines; plus, limiting windows to 80 characters makes it possible to
      have several windows side-by-side.  The default wrapping on such
      devices looks ugly.  Therefore, please limit all lines to a maximum
      of 79 characters. For flowing long blocks of text (docstrings or
      comments), limiting the length to 72 characters is recommended.
      
      Reports error E501.

      Line too long (114 > 79 characters)
      Open

              raise ImproperlyConfigured('Locker module "%s" does not define a "%s" class.' % (module_path, class_name))
      Severity: Minor
      Found in django_extra_tools/lockers.py by pep8

      Limit all lines to a maximum of 79 characters.

      There are still many devices around that are limited to 80 character
      lines; plus, limiting windows to 80 characters makes it possible to
      have several windows side-by-side.  The default wrapping on such
      devices looks ugly.  Therefore, please limit all lines to a maximum
      of 79 characters. For flowing long blocks of text (docstrings or
      comments), limiting the length to 72 characters is recommended.
      
      Reports error E501.

      Line too long (95 > 79 characters)
      Open

              raise ImproperlyConfigured('Error importing locker module %s: "%s"' % (module_path, e))
      Severity: Minor
      Found in django_extra_tools/lockers.py by pep8

      Limit all lines to a maximum of 79 characters.

      There are still many devices around that are limited to 80 character
      lines; plus, limiting windows to 80 characters makes it possible to
      have several windows side-by-side.  The default wrapping on such
      devices looks ugly.  Therefore, please limit all lines to a maximum
      of 79 characters. For flowing long blocks of text (docstrings or
      comments), limiting the length to 72 characters is recommended.
      
      Reports error E501.

      Line too long (89 > 79 characters)
      Open

      from django.utils.dateparse import parse_date, parse_datetime, parse_duration, parse_time

      Limit all lines to a maximum of 79 characters.

      There are still many devices around that are limited to 80 character
      lines; plus, limiting windows to 80 characters makes it possible to
      have several windows side-by-side.  The default wrapping on such
      devices looks ugly.  Therefore, please limit all lines to a maximum
      of 79 characters. For flowing long blocks of text (docstrings or
      comments), limiting the length to 72 characters is recommended.
      
      Reports error E501.

      Module level import not at top of file
      Open

      from django.core import management
      Severity: Minor
      Found in manage.py by pep8

      Place imports at the top of the file.

      Always put imports at the top of the file, just after any module
      comments and docstrings, and before module globals and constants.
      
      Okay: import os
      Okay: # this is a comment\nimport os
      Okay: '''this is a module docstring'''\nimport os
      Okay: r'''this is a module docstring'''\nimport os
      Okay:
      try:\n\timport x\nexcept ImportError:\n\tpass\nelse:\n\tpass\nimport y
      Okay:
      try:\n\timport x\nexcept ImportError:\n\tpass\nfinally:\n\tpass\nimport y
      E402: a=1\nimport os
      E402: 'One string'\n"Two string"\nimport os
      E402: a=1\nfrom sys import x
      
      Okay: if x:\n    import os

      Line too long (83 > 79 characters)
      Open

              raise ImproperlyConfigured("{} isn't a locker module.".format(import_path))
      Severity: Minor
      Found in django_extra_tools/lockers.py by pep8

      Limit all lines to a maximum of 79 characters.

      There are still many devices around that are limited to 80 character
      lines; plus, limiting windows to 80 characters makes it possible to
      have several windows side-by-side.  The default wrapping on such
      devices looks ugly.  Therefore, please limit all lines to a maximum
      of 79 characters. For flowing long blocks of text (docstrings or
      comments), limiting the length to 72 characters is recommended.
      
      Reports error E501.

      Line too long (80 > 79 characters)
      Open

      SQL_PATH = os.path.abspath(os.path.join(os.path.dirname(__file__), '..', 'sql'))

      Limit all lines to a maximum of 79 characters.

      There are still many devices around that are limited to 80 character
      lines; plus, limiting windows to 80 characters makes it possible to
      have several windows side-by-side.  The default wrapping on such
      devices looks ugly.  Therefore, please limit all lines to a maximum
      of 79 characters. For flowing long blocks of text (docstrings or
      comments), limiting the length to 72 characters is recommended.
      
      Reports error E501.

      Line too long (80 > 79 characters)
      Open

                                 defaults={'name': 'Can view %s' % content_type.name})

      Limit all lines to a maximum of 79 characters.

      There are still many devices around that are limited to 80 character
      lines; plus, limiting windows to 80 characters makes it possible to
      have several windows side-by-side.  The default wrapping on such
      devices looks ugly.  Therefore, please limit all lines to a maximum
      of 79 characters. For flowing long blocks of text (docstrings or
      comments), limiting the length to 72 characters is recommended.
      
      Reports error E501.

      Line too long (90 > 79 characters)
      Open

          This post_syncdb/post_migrate hooks takes care of adding a view permission too all our

      Limit all lines to a maximum of 79 characters.

      There are still many devices around that are limited to 80 character
      lines; plus, limiting windows to 80 characters makes it possible to
      have several windows side-by-side.  The default wrapping on such
      devices looks ugly.  Therefore, please limit all lines to a maximum
      of 79 characters. For flowing long blocks of text (docstrings or
      comments), limiting the length to 72 characters is recommended.
      
      Reports error E501.

      Line too long (84 > 79 characters)
      Open

              superuser = super(ThroughSuperuserModelBackend, self).authenticate(**kwargs)
      Severity: Minor
      Found in django_extra_tools/auth/backends.py by pep8

      Limit all lines to a maximum of 79 characters.

      There are still many devices around that are limited to 80 character
      lines; plus, limiting windows to 80 characters makes it possible to
      have several windows side-by-side.  The default wrapping on such
      devices looks ugly.  Therefore, please limit all lines to a maximum
      of 79 characters. For flowing long blocks of text (docstrings or
      comments), limiting the length to 72 characters is recommended.
      
      Reports error E501.

      Line too long (90 > 79 characters)
      Open

      default_app_config = 'django_extra_tools.auth.view_permissions.apps.ViewPermissionsConfig'

      Limit all lines to a maximum of 79 characters.

      There are still many devices around that are limited to 80 character
      lines; plus, limiting windows to 80 characters makes it possible to
      have several windows side-by-side.  The default wrapping on such
      devices looks ugly.  Therefore, please limit all lines to a maximum
      of 79 characters. For flowing long blocks of text (docstrings or
      comments), limiting the length to 72 characters is recommended.
      
      Reports error E501.
      Severity
      Category
      Status
      Source
      Language