mangroveorg/datawinners

View on GitHub
datawinners/entity/view/all_datasenders.py

Summary

Maintainability
D
2 days
Test Coverage

File all_datasenders.py has 264 lines of code (exceeds 250 allowed). Consider refactoring.
Open

import json
import os
from sets import Set

from django.contrib.auth.decorators import login_required
Severity: Minor
Found in datawinners/entity/view/all_datasenders.py - About 2 hrs to fix

    Function post has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
    Open

        def post(self, request, *args, **kwargs):
            manager = get_database_manager(request.user)
            questionnaires = self._get_projects(manager, request)
            projects_name = Set()
            removed_rep_ids = Set()
    Severity: Minor
    Found in datawinners/entity/view/all_datasenders.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 _convert_contacts_to_datasenders has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
    Open

        def _convert_contacts_to_datasenders(self, contact_short_codes, manager, request):
            datasender_id_email_map = {}
            for contact_short_code in contact_short_codes:
                datasender = contact_by_short_code(manager, contact_short_code)
                if datasender.is_contact:
    Severity: Minor
    Found in datawinners/entity/view/all_datasenders.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

            if len(removed_rep_ids):
                UserActivityLog().log(request, action=REMOVED_DATA_SENDER_TO_QUESTIONNAIRES,
                                      detail=json.dumps({"Unique ID": "[%s]" % ", ".join(removed_rep_ids),
                                                         "Projects": "[%s]" % ", ".join(projects_name)}))
    Severity: Major
    Found in datawinners/entity/view/all_datasenders.py and 1 other location - About 3 hrs to fix
    datawinners/entity/view/all_datasenders.py on lines 198..201

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

    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 len(ids):
                UserActivityLog().log(request, action=ADDED_DATA_SENDERS_TO_QUESTIONNAIRES,
                                      detail=json.dumps({"Unique ID": "[%s]" % ", ".join(ids),
                                                         "Projects": "[%s]" % ", ".join(projects_name)}))
    Severity: Major
    Found in datawinners/entity/view/all_datasenders.py and 1 other location - About 3 hrs to fix
    datawinners/entity/view/all_datasenders.py on lines 255..258

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

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

            return HttpResponse(
                jsonpickle.encode(
                    {
                        'data': datasenders,
                        'iTotalDisplayRecords': filtered_count,
    Severity: Major
    Found in datawinners/entity/view/all_datasenders.py and 2 other locations - About 2 hrs to fix
    datawinners/project/views/datasenders.py on lines 63..70
    datawinners/entity/views.py on lines 232..239

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

    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_datasender)
    Severity: Major
    Found in datawinners/entity/view/all_datasenders.py and 3 other locations - About 2 hrs to fix
    datawinners/blue/view.py on lines 298..305
    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

    Similar blocks of code found in 7 locations. Consider refactoring.
    Open

        @method_decorator(login_required)
        @method_decorator(session_not_expired)
        @method_decorator(is_not_expired)
        @method_decorator(is_new_user)
        @method_decorator(is_datasender)
    Severity: Major
    Found in datawinners/entity/view/all_datasenders.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 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
    datawinners/blue/view.py on lines 70..76

    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 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/entity/view/all_datasenders.py and 6 other locations - About 1 hr to fix
    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
    datawinners/blue/view.py on lines 70..76

    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 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/entity/view/all_datasenders.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/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
    datawinners/blue/view.py on lines 70..76

    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

            return HttpResponse(json.dumps(
                {
                    'success': error_message is None and is_empty(failure_imports),
                    'message': success_message,
                    'error_message': error_message,
    Severity: Major
    Found in datawinners/entity/view/all_datasenders.py and 1 other location - About 1 hr to fix
    datawinners/entity/views.py on lines 338..343

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

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

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

    There are no issues that match your filters.

    Category
    Status