mangroveorg/datawinners

View on GitHub
datawinners/blue/view.py

Summary

Maintainability
F
1 wk
Test Coverage

File view.py has 765 lines of code (exceeds 250 allowed). Consider refactoring.
Open

import json
import logging
import mimetypes
import os
import re
Severity: Major
Found in datawinners/blue/view.py - About 1 day to fix

    Function get_edited_details_for_field_set has a Cognitive Complexity of 69 (exceeds 5 allowed). Consider refactoring.
    Open

    def get_edited_details_for_field_set(edit_details, questionnaire, code, value):
        if len(value['new_data']) == len(value['old_data']):
            if value['old_data'] != value['new_data']:
                for index, i in enumerate(value['new_data']):
                    for key, val in i.items():
    Severity: Minor
    Found in datawinners/blue/view.py - About 1 day 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 _try_parse_xls has a Cognitive Complexity of 27 (exceeds 5 allowed). Consider refactoring.
    Open

    def _try_parse_xls(manager, request, questionnaire_name, excel_file=None):
        try:
            file_validation_results = _perform_file_validations(request)
            if isinstance(file_validation_results, HttpResponse):
                return file_validation_results
    Severity: Minor
    Found in datawinners/blue/view.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 _to_html has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
    Open

        def _to_html(self, data):
            html = '<ul>'
            for key, value in data.items():
                if isinstance(value, dict):
                    continue
    Severity: Minor
    Found in datawinners/blue/view.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

                            if val and val != value['old_data'][index][key]:
                                question = questionnaire.get_field_by_code(key).label
                                edit_details.update({code+'_'+str(index)+'_'+key: {'question': question,
                                                             'old': value['old_data'][index][key], 'new': val}})
                    except IndexError:
    Severity: Major
    Found in datawinners/blue/view.py - About 45 mins to fix

      Avoid deeply nested control flow statements.
      Open

                              if val != value['new_data'][index][key]:
                                  question = questionnaire.get_field_by_code(key).label
                                  edit_details.update({code+'_'+str(index)+'_'+key: {'question': question, 'old': val,
                                                               'new': value['new_data'][index][key]}})
                      except IndexError:
      Severity: Major
      Found in datawinners/blue/view.py - About 45 mins to fix

        Avoid deeply nested control flow statements.
        Open

                            if key in value['old_data'][index]:
                                if val and val != value['old_data'][index][key]:
                                    question = questionnaire.get_field_by_code(key).label
                                    edit_details.update({code+'_'+str(index)+'_'+key: {'question': question,
                                                                                       'old': value['old_data'][index][key], 'new': val}})
        Severity: Major
        Found in datawinners/blue/view.py - About 45 mins to fix

          Avoid too many return statements within this function.
          Open

                  return HttpResponse(
          Severity: Major
          Found in datawinners/blue/view.py - About 30 mins to fix

            Avoid too many return statements within this function.
            Open

                    return HttpResponse(
            Severity: Major
            Found in datawinners/blue/view.py - About 30 mins to fix

              Avoid too many return statements within this function.
              Open

                      return HttpResponse(content_type='application/json', content=json.dumps({
              Severity: Major
              Found in datawinners/blue/view.py - About 30 mins to fix

                Avoid too many return statements within this function.
                Open

                        return HttpResponse(content_type='application/json', content=json.dumps({
                Severity: Major
                Found in datawinners/blue/view.py - About 30 mins to fix

                  Avoid too many return statements within this function.
                  Open

                      return xls_parser_response
                  Severity: Major
                  Found in datawinners/blue/view.py - About 30 mins to fix

                    Avoid too many return statements within this function.
                    Open

                                return HttpResponse(content_type='application/json', content=json.dumps({
                    Severity: Major
                    Found in datawinners/blue/view.py - About 30 mins to fix

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

                      def _create_details_for_edit_info(new_data_dict, old_data, questionnaire):
                          details = dict()
                          for key, value in new_data_dict.iteritems():
                              if key in old_data and key not in {"intro", "meta", "form_code"}:
                                  if new_data_dict[key] != old_data[key]:
                      Severity: Minor
                      Found in datawinners/blue/view.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 2 locations. Consider refactoring.
                      Open

                                      try:
                                          if key in value['old_data'][index]:
                                              if val and val != value['old_data'][index][key]:
                                                  question = questionnaire.get_field_by_code(key).label
                                                  edit_details.update({code+'_'+str(index)+'_'+key: {'question': question,
                      Severity: Major
                      Found in datawinners/blue/view.py and 1 other location - About 1 day to fix
                      datawinners/blue/view.py on lines 495..500

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

                      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

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

                                      for key, val in i.items():
                                          if key in value['old_data'][index]:
                                              if val and val != value['old_data'][index][key]:
                                                  question = questionnaire.get_field_by_code(key).label
                                                  edit_details.update({code+'_'+str(index)+'_'+key: {'question': question,
                      Severity: Major
                      Found in datawinners/blue/view.py and 1 other location - About 1 day to fix
                      datawinners/blue/view.py on lines 505..510

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

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

                          @method_decorator(csrf_view_exempt)
                          @method_decorator(csrf_response_exempt)
                          @method_decorator(login_required)
                          @method_decorator(session_not_expired)
                          @method_decorator(is_not_expired)
                      Severity: Major
                      Found in datawinners/blue/view.py and 3 other locations - About 2 hrs to fix
                      datawinners/entity/view/all_datasenders.py on lines 115..122
                      datawinners/common/lang/views.py on lines 42..49
                      datawinners/common/lang/views.py on lines 137..144

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

                      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

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

                              except QuestionCodeAlreadyExistsException as e:
                                  return HttpResponse(content_type='application/json', content=json.dumps({
                                      'success': False,
                                      'error_msg': [
                                          _(e.message) % e.data[0]
                      Severity: Major
                      Found in datawinners/blue/view.py and 1 other location - About 2 hrs to fix
                      datawinners/blue/view.py on lines 117..121

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

                      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

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

                              except QuestionCodeAlreadyExistsException as e:
                                  return HttpResponse(content_type='application/json', content=json.dumps({
                                      'success': False,
                                      'error_msg': [
                                          _(e.message) % e.data[0]
                      Severity: Major
                      Found in datawinners/blue/view.py and 1 other location - About 2 hrs to fix
                      datawinners/blue/view.py on lines 363..367

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

                      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

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

                              except QuestionAlreadyExistsException as e:
                                  return HttpResponse(content_type='application/json', content=json.dumps({
                                      'success': False,
                                      'error_msg': [
                                          _(e.message)
                      Severity: Major
                      Found in datawinners/blue/view.py and 1 other location - About 2 hrs to fix
                      datawinners/blue/view.py on lines 277..285

                      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

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

                          except QuestionAlreadyExistsException as e:
                              return HttpResponse(content_type='application/json', content=json.dumps({
                                  'success': False,
                                  'error_msg': [
                                      _(e.message)
                      Severity: Major
                      Found in datawinners/blue/view.py and 1 other location - About 2 hrs to fix
                      datawinners/blue/view.py on lines 353..361

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

                          @method_decorator(csrf_view_exempt)
                          @method_decorator(csrf_response_exempt)
                          @method_decorator(login_required)
                          @method_decorator(session_not_expired)
                          @method_decorator(is_not_expired)
                      Severity: Major
                      Found in datawinners/blue/view.py and 6 other locations - About 1 hr to fix
                      datawinners/entity/view/all_datasenders.py on lines 158..164
                      datawinners/entity/view/all_datasenders.py on lines 177..183
                      datawinners/entity/view/all_datasenders.py on lines 305..311
                      datawinners/project/views/change_language.py on lines 58..64
                      datawinners/project/views/datasenders.py on lines 73..79
                      datawinners/project/views/import_submissions_views.py on lines 63..69

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

                      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

                          email = EmailMessage(subject="[INFO - No regd. unique-ids] : %s" % organization.name,
                                               body=re.sub("\n", "<br/>", email_message),
                                               from_email=EMAIL_HOST_USER, to=[HNI_SUPPORT_EMAIL_ID])
                      Severity: Major
                      Found in datawinners/blue/view.py and 1 other location - About 1 hr to fix
                      datawinners/xforms/views.py on lines 208..210

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

                              file_name_slugifed = "%s.%s" % (slugify(".".join(attachment_name.split('.')[:-1])), file_extension)
                      Severity: Minor
                      Found in datawinners/blue/view.py and 1 other location - About 50 mins to fix
                      datawinners/blue/xform_submission_exporter.py on lines 88..88

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

                      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

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

                                  form_context.update({'xform_xml': re.sub(r"\n", " ", XFormTransformer(
                                      self.questionnaire.do_enrich_xform()).transform())})
                      Severity: Minor
                      Found in datawinners/blue/view.py and 1 other location - About 45 mins to fix
                      datawinners/blue/view.py on lines 819..822

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

                      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

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

                                  form_context.update(
                                      {
                                          'xform_xml': re.sub(r"\n", " ", XFormTransformer(
                                              self.questionnaire.do_enrich_xform()).transform())
                      Severity: Minor
                      Found in datawinners/blue/view.py and 1 other location - About 45 mins to fix
                      datawinners/blue/view.py on lines 851..852

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

                      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