batiste/django-page-cms

View on GitHub
pages/placeholders.py

Summary

Maintainability
D
3 days
Test Coverage

File placeholders.py has 407 lines of code (exceeds 250 allowed). Consider refactoring.
Open

"""Placeholder module, that's where the smart things happen."""
from pages.widgets_registry import get_widget
from pages import settings
from pages.models import Content, Media
from pages.widgets import ImageInput, FileInput
Severity: Minor
Found in pages/placeholders.py - About 5 hrs to fix

    Function parse_placeholder has a Cognitive Complexity of 27 (exceeds 5 allowed). Consider refactoring.
    Open

    def parse_placeholder(parser, token):
        """Parse the `PlaceholderNode` parameters.
    
        Return a tuple with the name and parameters."""
        params = {}
    Severity: Minor
    Found in pages/placeholders.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 __init__ has 11 arguments (exceeds 4 allowed). Consider refactoring.
    Open

        def __init__(
    Severity: Major
    Found in pages/placeholders.py - About 1 hr to fix

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

          def get_content(self, page_obj, lang, lang_fallback=True):
              if self.untranslated:
                  lang = settings.PAGE_DEFAULT_LANGUAGE
                  lang_fallback = False
              if self.shared:
      Severity: Minor
      Found in pages/placeholders.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 save has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
      Open

          def save(self, page, language, data, change, extra_data=None):
              """Actually save the placeholder data into the Content object."""
              # if this placeholder is untranslated, we save everything
              # in the default language
              if self.untranslated:
      Severity: Minor
      Found in pages/placeholders.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 render has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
      Open

          def render(self, context):
              """Output the content of the `PlaceholdeNode` as a template."""
              content = self.get_render_content(context)
              request = context.get('request')
              render_edit_tag = False
      Severity: Minor
      Found in pages/placeholders.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 render has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
      Open

          def render(self, context):
              request = context.get('request', None)
              if not request:
                  raise ValueError('request not available in the context.')
              if request.method == 'POST':
      Severity: Minor
      Found in pages/placeholders.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 save has 5 arguments (exceeds 4 allowed). Consider refactoring.
      Open

          def save(self, page, language, data, change, extra_data=None):
      Severity: Minor
      Found in pages/placeholders.py - About 35 mins to fix

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

            def save(self, page, language, data, change, extra_data=None):
        Severity: Minor
        Found in pages/placeholders.py - About 35 mins to fix

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

              def save(self, page, language, data, change, extra_data=None):
                  if self.shared:
                      page = None
          
                  if extra_data and 'delete' in extra_data:
          Severity: Minor
          Found in pages/placeholders.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 ''
          Severity: Major
          Found in pages/placeholders.py - About 30 mins to fix

            Avoid too many return statements within this function.
            Open

                        return super(FilePlaceholderNode, self).save(
            Severity: Major
            Found in pages/placeholders.py - About 30 mins to fix

              Avoid too many return statements within this function.
              Open

                          return
              Severity: Major
              Found in pages/placeholders.py - About 30 mins to fix

                Avoid too many return statements within this function.
                Open

                                return
                Severity: Major
                Found in pages/placeholders.py - About 30 mins to fix

                  Avoid too many return statements within this function.
                  Open

                              return super(FilePlaceholderNode, self).save(
                  Severity: Major
                  Found in pages/placeholders.py - About 30 mins to fix

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

                        if len(name_parts) > 1:
                            name = slugify('.'.join(name_parts[:-1]), allow_unicode=True)
                            ext = slugify(name_parts[-1])
                            name = name + '.' + ext
                    Severity: Major
                    Found in pages/placeholders.py and 1 other location - About 2 hrs to fix
                    pages/models.py on lines 557..560

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

                    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

                        def get_field(self, page, language, initial=None):
                            help_text = ""
                            widget = FileInput(page, language)
                            return FileField(
                    Severity: Major
                    Found in pages/placeholders.py and 1 other location - About 1 hr to fix
                    pages/placeholders.py on lines 402..405

                    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

                        def get_field(self, page, language, initial=None):
                            help_text = ""
                            widget = ImageInput(page, language)
                            return ImageField(
                    Severity: Major
                    Found in pages/placeholders.py and 1 other location - About 1 hr to fix
                    pages/placeholders.py on lines 339..342

                    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

                    There are no issues that match your filters.

                    Category
                    Status