spicycms/spicy.core

View on GitHub
src/spicy/core/profile/models.py

Summary

Maintainability
F
3 days
Test Coverage

File models.py has 472 lines of code (exceeds 250 allowed). Consider refactoring.
Open

import xlrd
import xlwt
import errno
import random
import smtplib
Severity: Minor
Found in src/spicy/core/profile/models.py - About 7 hrs to fix

    Function import_data has a Cognitive Complexity of 23 (exceeds 5 allowed). Consider refactoring.
    Open

        def import_data(self, src, fields):
            fields.insert(0, 'id')
            workbook = xlrd.open_workbook(file_contents=src.read())
            sheet = workbook.sheet_by_index(0)
            import_fields = {}
    Severity: Minor
    Found in src/spicy/core/profile/models.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

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

    class AbstractProfile(User, MediaConsumerAbstractModel):
        IS_ACTIVATED = 'Already activated'
        user_ptr = models.OneToOneField(User, parent_link=True)
        activation_key = models.CharField(_('activation key'), max_length=40)
        is_banned = models.BooleanField(
    Severity: Minor
    Found in src/spicy/core/profile/models.py - About 2 hrs to fix

      Function create_inactive_user has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
      Open

          def create_inactive_user(
                  self, email, password=None, send_email=True, next_url=None,
                  realhost=None, **kwargs):
              now = dt.datetime.now()
              email = email.lower()
      Severity: Minor
      Found in src/spicy/core/profile/models.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 export_data has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
      Open

          def export_data(self, columns):
              result = StringIO()
              workbook = xlwt.Workbook()
              sheet = workbook.add_sheet('Profile')
      
      
      Severity: Minor
      Found in src/spicy/core/profile/models.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 create_inactive_user has 6 arguments (exceeds 4 allowed). Consider refactoring.
      Open

          def create_inactive_user(
      Severity: Minor
      Found in src/spicy/core/profile/models.py - About 45 mins to fix

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

            def email_user(self, subject, message, email=None, html_body=None):
                email = email or self.email
        
                if not email:
                    # No email - do nothing.
        Severity: Minor
        Found in src/spicy/core/profile/models.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 generate_activation_key has 5 arguments (exceeds 4 allowed). Consider refactoring.
        Open

            def generate_activation_key(
        Severity: Minor
        Found in src/spicy/core/profile/models.py - About 35 mins to fix

          Function email_user has 5 arguments (exceeds 4 allowed). Consider refactoring.
          Open

              def email_user(self, subject, message, email=None, html_body=None):
          Severity: Minor
          Found in src/spicy/core/profile/models.py - About 35 mins to fix

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

                def get_field_label(cls, field):
                    try:
                        label = cls._meta.get_field_by_name(field)[0].verbose_name
                    except FieldDoesNotExist:
                        try:
            Severity: Minor
            Found in src/spicy/core/profile/models.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

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

                def delete_expired_users(self):
                    raise NotImplementedError
                    # # XXX: antisvin 2011-02-24: This would delete shop orders from
                    # express registration. Fix foreign keys to Profile or use trash app
                    # before deleting expirted users.
            Severity: Minor
            Found in src/spicy/core/profile/models.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 save has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
            Open

                def save(self, *args, **kwargs):
                    is_old = bool(self.id or False)
                    if is_old:
                        old = self.__class__.objects.get(pk=self.pk)
            
            
            Severity: Minor
            Found in src/spicy/core/profile/models.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 5 locations. Consider refactoring.
            Open

                    if defaults.USE_HTML_EMAIL:
                        html_body = render_to_string(
                            'spicy.core.profile/mail/passwd_email.html', context)
                        self.email_user(subject, message, html_body=html_body)
                    else:
            Severity: Major
            Found in src/spicy/core/profile/models.py and 4 other locations - About 1 hr to fix
            src/spicy/core/profile/models.py on lines 388..393
            src/spicy/core/profile/models.py on lines 404..409
            src/spicy/core/profile/models.py on lines 444..449
            src/spicy/core/profile/models.py on lines 514..519

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

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

                    if defaults.USE_HTML_EMAIL:
                        html_body = render_to_string(
                            'spicy.core.profile/mail/banned_email.html', context)
                        self.email_user(subject, message, html_body=html_body)
                    else:
            Severity: Major
            Found in src/spicy/core/profile/models.py and 4 other locations - About 1 hr to fix
            src/spicy/core/profile/models.py on lines 388..393
            src/spicy/core/profile/models.py on lines 444..449
            src/spicy/core/profile/models.py on lines 463..468
            src/spicy/core/profile/models.py on lines 514..519

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

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

                    if defaults.USE_HTML_EMAIL:
                        html_body = render_to_string(
                            'spicy.core.profile/mail/forgotten_password_email.html', context)
                        self.email_user(subject, message, html_body=html_body)
                    else:
            Severity: Major
            Found in src/spicy/core/profile/models.py and 4 other locations - About 1 hr to fix
            src/spicy/core/profile/models.py on lines 388..393
            src/spicy/core/profile/models.py on lines 404..409
            src/spicy/core/profile/models.py on lines 444..449
            src/spicy/core/profile/models.py on lines 463..468

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

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

                    if defaults.USE_HTML_EMAIL:
                        html_body = render_to_string(
                            'spicy.core.profile/mail/hello_email.html', context)
                        self.email_user(subject, message, html_body=html_body)
                    else:
            Severity: Major
            Found in src/spicy/core/profile/models.py and 4 other locations - About 1 hr to fix
            src/spicy/core/profile/models.py on lines 404..409
            src/spicy/core/profile/models.py on lines 444..449
            src/spicy/core/profile/models.py on lines 463..468
            src/spicy/core/profile/models.py on lines 514..519

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

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

                    if defaults.USE_HTML_EMAIL:
                        html_body = render_to_string(
                            'spicy.core.profile/mail/activation_email.html', context)
                        self.email_user(subject, message, html_body=html_body)
                    else:
            Severity: Major
            Found in src/spicy/core/profile/models.py and 4 other locations - About 1 hr to fix
            src/spicy/core/profile/models.py on lines 388..393
            src/spicy/core/profile/models.py on lines 404..409
            src/spicy/core/profile/models.py on lines 463..468
            src/spicy/core/profile/models.py on lines 514..519

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

            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