hack4impact/maps4all

View on GitHub
app/descriptor/views.py

Summary

Maintainability
D
3 days
Test Coverage

File views.py has 387 lines of code (exceeds 250 allowed). Consider refactoring.
Open

from flask import abort, flash, render_template, redirect, url_for, request
from flask.ext.login import login_required
from sqlalchemy.exc import IntegrityError
from wtforms.fields import SelectField
from flask_wtf.file import InputRequired
Severity: Minor
Found in app/descriptor/views.py - About 5 hrs to fix

    Function review_required_option_descriptor has a Cognitive Complexity of 24 (exceeds 5 allowed). Consider refactoring.
    Open

    def review_required_option_descriptor():
        req_opt_desc_const = RequiredOptionDescriptorConstructor.query.all()[0]
        form = RequiredOptionDescriptorMissingForm()
        missing_resources = []
        resources = Resource.query.all()
    Severity: Minor
    Found in app/descriptor/views.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 new_descriptor has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
    Open

    def new_descriptor():
        """Create a new descriptor."""
        form = NewDescriptorForm()
        for i in range(10):
            form.option_values.append_entry()
    Severity: Minor
    Found in app/descriptor/views.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 change_required_option_descriptor has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
    Open

    def change_required_option_descriptor():
        descriptors = Descriptor.query.all()
        choices = []
        for d in descriptors:
            if d.values:
    Severity: Minor
    Found in app/descriptor/views.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 remove_option_value has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
    Open

    def remove_option_value(desc_id, option_index):
        """Remove a descriptor's selected option value."""
        descriptor = Descriptor.query.get(desc_id)
        if descriptor is None or len(descriptor.values) == 0:
            abort(404)
    Severity: Minor
    Found in app/descriptor/views.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 edit_name has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
    Open

    def edit_name(desc_id):
        """Edit a descriptor's name."""
        descriptor = Descriptor.query.get(desc_id)
        if descriptor is None:
            abort(404)
    Severity: Minor
    Found in app/descriptor/views.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

    Avoid deeply nested control flow statements.
    Open

                        for val in form.resources.data[j]:
                            new_association = OptionAssociation(
                                                resource_id=resource.id,
                                                descriptor_id=descriptor.id,
                                                option=descriptor.values.index(val),
    Severity: Major
    Found in app/descriptor/views.py - About 45 mins to fix

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

      def change_option_values_index(desc_id):
          """Shows the page to add/edit/remove a descriptor's option values."""
          descriptor = Descriptor.query.get(desc_id)
          if descriptor is None:
              abort(404)
      Severity: Minor
      Found in app/descriptor/views.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 edit_option_value has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
      Open

      def edit_option_value(desc_id, option_index):
          """Edit a descriptor's selected option value."""
          descriptor = Descriptor.query.get(desc_id)
          if descriptor is None:
              abort(404)
      Severity: Minor
      Found in app/descriptor/views.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 2 locations. Consider refactoring.
      Open

          for j, r_name in enumerate(missing_resources):
              form.resources.append_entry()
              form.resources[j].label = r_name
              form.resources[j].choices = [(v, v) for v in req_opt_desc_const.values]
      Severity: Major
      Found in app/descriptor/views.py and 1 other location - About 3 hrs to fix
      app/bulk_resource/views.py on lines 563..566

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

      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

          if req_opt_desc.descriptor_id != -1:
              descriptor = Descriptor.query.filter_by(
                  id=req_opt_desc.descriptor_id
              ).first()
              if descriptor is not None:
      Severity: Major
      Found in app/descriptor/views.py and 1 other location - About 2 hrs to fix
      app/bulk_resource/views.py on lines 517..522

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

      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

              try:
                  db.session.commit()
                  flash('Name for descriptor {} successfully changed to {}.'.format(old_name, descriptor.name),
                      'form-success')
              except IntegrityError:
      Severity: Major
      Found in app/descriptor/views.py and 1 other location - About 2 hrs to fix
      app/contact/views.py on lines 80..87

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

      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

                          for val in form.resources.data[j]:
                              new_association = OptionAssociation(
                                                  resource_id=resource.id,
                                                  descriptor_id=descriptor.id,
                                                  option=descriptor.values.index(val),
      Severity: Major
      Found in app/descriptor/views.py and 1 other location - About 1 hr to fix
      app/bulk_resource/views.py on lines 783..789

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

      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