mangroveorg/datawinners

View on GitHub
datawinners/project/views/submission_views.py

Summary

Maintainability
F
3 days
Test Coverage

File submission_views.py has 701 lines of code (exceeds 250 allowed). Consider refactoring.
Open

from collections import OrderedDict
from copy import deepcopy
import json
import re
import datetime
Severity: Major
Found in datawinners/project/views/submission_views.py - About 1 day to fix

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

    def edit(request, project_id, survey_response_id, tab=0):
        manager = get_database_manager(request.user)
        questionnaire_form_model = Project.get(manager, project_id)
        dashboard_page = settings.HOME_PAGE + "?deleted=true"
        reporter_id = NGOUserProfile.objects.get(user=request.user).reporter_id
    Severity: Minor
    Found in datawinners/project/views/submission_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 construct_request_dict has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
    Open

    def construct_request_dict(survey_response, questionnaire_form_model, short_code):
        result_dict = {}
        for field in questionnaire_form_model.fields:
            value = survey_response.values.get(field.code) if survey_response.values.get(
                field.code) else survey_response.values.get(field.code.lower())
    Severity: Minor
    Found in datawinners/project/views/submission_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 _advanced_questionnaire_export has 10 arguments (exceeds 4 allowed). Consider refactoring.
    Open

    def _advanced_questionnaire_export(current_language, form_model, is_media, is_single_sheet, local_time_delta, manager, project_name,
    Severity: Major
    Found in datawinners/project/views/submission_views.py - About 1 hr to fix

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

      def create_statistics_response(facet_results, form_model):
          analysis_response = OrderedDict()
          for facet_result in facet_results:
              field_code = get_code_from_es_field_name(facet_result['es_field_name'], form_model.id)
              field = form_model.get_field_by_code(field_code)
      Severity: Minor
      Found in datawinners/project/views/submission_views.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 log_edit_action has 5 arguments (exceeds 4 allowed). Consider refactoring.
      Open

      def log_edit_action(old_survey_response, new_survey_response, request, project_name, form_model):
      Severity: Minor
      Found in datawinners/project/views/submission_views.py - About 35 mins to fix

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

        def build_static_info_context(manager, survey_response, ui_model=None, questionnaire_form_model=None, reporter_id=None):
        Severity: Minor
        Found in datawinners/project/views/submission_views.py - About 35 mins to fix

          Avoid too many return statements within this function.
          Open

                          return HttpResponseRedirect(submitted_values.get("redirect_url"))
          Severity: Major
          Found in datawinners/project/views/submission_views.py - About 30 mins to fix

            Avoid too many return statements within this function.
            Open

                    return render_to_response("project/web_questionnaire.html", form_ui_model,
            Severity: Major
            Found in datawinners/project/views/submission_views.py - About 30 mins to fix

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

              def delete(request, project_id):
                  dbm = get_database_manager(request.user)
                  questionnaire = Project.get(dbm, project_id)
                  dashboard_page = settings.HOME_PAGE + "?deleted=true"
                  if questionnaire.is_void():
              Severity: Minor
              Found in datawinners/project/views/submission_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

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

              def get_filterable_fields(fields, filterable_fields, parent_code=None):
                  for field in fields:
                      field_detials = get_filterable_field_details(field, filterable_fields, parent_code)
                      if field_detials:
                          filterable_fields.append(field_detials)
              Severity: Minor
              Found in datawinners/project/views/submission_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

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

              def get_duplicates_filterable_fields(fields, duplicates_filterable_fields, parent_code=None):
                  for field in fields:
                      if isinstance(field, UniqueIdField):
                          duplicates_filterable_fields.append(get_unique_id_field_details(field, parent_code))
                      if isinstance(field, FieldSet) and field.is_group():
              Severity: Minor
              Found in datawinners/project/views/submission_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

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

              def log_edit_action(old_survey_response, new_survey_response, request, project_name, form_model):
                  differences = new_survey_response.differs_from(old_survey_response)
                  diff_dict = {}
                  changed_answers = deepcopy(differences.changed_answers)
                  if differences.changed_answers:
              Severity: Minor
              Found in datawinners/project/views/submission_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

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

              def get_facet_response_for_choice_fields(query_with_criteria, choice_fields, form_model_id):
                  facet_results = []
                  for field in choice_fields:
                      field_name = es_questionnaire_field_name(field.code, form_model_id) + "_exact"
                      facet_response = query_with_criteria.facet(field_name, filtered=True).facet_counts()
              Severity: Minor
              Found in datawinners/project/views/submission_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

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

                  search_parameters.update({"order": "-" if request.POST.get('sSortDir_0') == "desc" else ""})
              Severity: Major
              Found in datawinners/project/views/submission_views.py and 3 other locations - About 35 mins to fix
              datawinners/entity/view/all_datasenders.py on lines 141..141
              datawinners/project/views/datasenders.py on lines 53..53
              datawinners/entity/views.py on lines 229..229

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

              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 isinstance(field, FieldSet) and field.is_group():
                          duplicates_filterable_fields = get_duplicates_filterable_fields(field.fields, duplicates_filterable_fields, field.code)
              Severity: Minor
              Found in datawinners/project/views/submission_views.py and 1 other location - About 35 mins to fix
              datawinners/project/views/submission_views.py on lines 180..181

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

              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 isinstance(field, FieldSet) and field.is_group():
                          filterable_fields = get_filterable_fields(field.fields, filterable_fields, field.code)
              Severity: Minor
              Found in datawinners/project/views/submission_views.py and 1 other location - About 35 mins to fix
              datawinners/project/views/submission_views.py on lines 196..197

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

              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_code(field, parent_code):
                  if parent_code:
                      return parent_code + '-' + field.code
                  return field.code
              Severity: Minor
              Found in datawinners/project/views/submission_views.py and 1 other location - About 35 mins to fix
              datawinners/project/views/submission_views.py on lines 138..141

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

              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 _field_code(field, parent_code):
                  if parent_code:
                      return parent_code + '----' + field.code
                  return field.code
              Severity: Minor
              Found in datawinners/project/views/submission_views.py and 1 other location - About 35 mins to fix
              datawinners/project/views/submission_views.py on lines 143..146

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

              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