mangroveorg/datawinners

View on GitHub
datawinners/accountmanagement/admin.py

Summary

Maintainability
F
1 wk
Test Coverage

File admin.py has 436 lines of code (exceeds 250 allowed). Consider refactoring.
Open

# vim: ai ts=4 sts=4 et sw=4 encoding=utf-8
import datetime
import logging

from django.contrib.auth.admin import UserAdmin
Severity: Minor
Found in datawinners/accountmanagement/admin.py - About 6 hrs to fix

    Function save_model has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring.
    Open

        def save_model(self, request, obj, form, change):
            super(DWUserAdmin, self).save_model(request, obj, form, change)
    
            if change:
                if 'email' in form.changed_data or 'username' in form.changed_data:
    Severity: Minor
    Found in datawinners/accountmanagement/admin.py - About 2 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 export_user_list_to_excel has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
    Open

    def export_user_list_to_excel(a,b,c):
        #Custom Method to export user details.
        def is_required(user):
            return True if user.groups.filter(name="NGO Admins").count() or user.groups.filter(name="Project Managers").count() \
                or user.groups.filter(name="Extended Users").count()else False
    Severity: Minor
    Found in datawinners/accountmanagement/admin.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 get_query_set has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
    Open

        def get_query_set(self):
            if not self.params.get("q", ""):
                return super(OrganizationChangeList, self).get_query_set()
    
            from django.db import connection
    Severity: Minor
    Found in datawinners/accountmanagement/admin.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 get_query_set has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
    Open

        def get_query_set(self):
            if not self.params.get("q", ""):
                return super(OrganizationChangeList, self).get_query_set()
    
            from django.db import connection
    Severity: Minor
    Found in datawinners/accountmanagement/admin.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 clean has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
    Open

        def clean(self):
            cleaned_data = self.cleaned_data
            if 'email' in cleaned_data:
                username = cleaned_data.get('email').strip()
                if not len(username):
    Severity: Minor
    Found in datawinners/accountmanagement/admin.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

    class OrganizationChangeList(ChangeList):
        def get_query_set(self):
            if not self.params.get("q", ""):
                return super(OrganizationChangeList, self).get_query_set()
    
    
    Severity: Major
    Found in datawinners/accountmanagement/admin.py and 1 other location - About 3 days to fix
    datawinners/accountmanagement/admin.py on lines 178..212

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

    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

    class OrganizationChangeList(ChangeList):
        def get_query_set(self):
            if not self.params.get("q", ""):
                return super(OrganizationChangeList, self).get_query_set()
    
    
    Severity: Major
    Found in datawinners/accountmanagement/admin.py and 1 other location - About 3 days to fix
    datawinners/accountmanagement/admin.py on lines 215..249

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

    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 activate_organizations(modeladmin, request, queryset):
            queryset.exclude(status__in=['Activated','Pending Activation']).update(status='Activated', status_changed_datetime=datetime.datetime.now())
            messages.success(request, _('The accounts selected have been activated successfully.'))
            selected = request.POST.getlist(admin.ACTION_CHECKBOX_NAME)
            orgs_id = Organization.objects.filter(org_id__in=selected).exclude(status='Pending Activation').\
    Severity: Major
    Found in datawinners/accountmanagement/admin.py and 1 other location - About 1 day to fix
    datawinners/accountmanagement/admin.py on lines 269..276

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

    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 deactivate_organizations(modeladmin, request, queryset):
            queryset.exclude(status__in=['Deactivated','Pending Activation']).update(status='Deactivated',
                                                          status_changed_datetime=datetime.datetime.now())
            messages.success(request, _('The accounts selected have been deactivated successfully.'))
            selected = request.POST.getlist(admin.ACTION_CHECKBOX_NAME)
    Severity: Major
    Found in datawinners/accountmanagement/admin.py and 1 other location - About 1 day to fix
    datawinners/accountmanagement/admin.py on lines 280..286

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

    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 country_name(self, obj):
            return ' ,'.join([country.country_name for country in obj.country.all()])
    Severity: Minor
    Found in datawinners/accountmanagement/admin.py and 1 other location - About 30 mins to fix
    datawinners/feature_toggle/admin.py on lines 11..12

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

    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