um-cseg/chez-betty

View on GitHub
chezbetty/views_user.py

Summary

Maintainability
F
4 days
Test Coverage

File views_user.py has 392 lines of code (exceeds 250 allowed). Consider refactoring.
Open

from pyramid.events import subscriber
from pyramid.events import BeforeRender
from pyramid.httpexceptions import HTTPFound
from pyramid.renderers import render
from pyramid.renderers import render_to_response
Severity: Minor
Found in chezbetty/views_user.py - About 5 hrs to fix

    Function user_deposit_cc_submit has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
    Open

    def user_deposit_cc_submit(request):
        token = request.POST['stripeToken']
        amount = Decimal(request.POST['betty_amount'])
        total_cents = int(request.POST['betty_total_cents'])
        to_account = request.POST['betty_to_account']
    Severity: Minor
    Found in chezbetty/views_user.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 transaction_history_queries has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
    Open

    def transaction_history_queries(request, user_or_pool):
        # Web library native date format: 2015/06/19 19:00
        # DO NOT CHANGE: The datetimepicker has a bug and tries to parse the
        #                prepopulated value before reading the format string,
        #                which means you have to use its native format string
    Severity: Minor
    Found in chezbetty/views_user.py - About 55 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 user_pool_addmember_submit has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
    Open

    def user_pool_addmember_submit(request):
        try:
            pool = Pool.from_id(request.POST['pool-id'])
            if pool.owner != request.user.id:
                request.session.flash('You do not have permission to view that pool.', 'error')
    Severity: Minor
    Found in chezbetty/views_user.py - About 55 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

    Avoid too many return statements within this function.
    Open

            return HTTPFound(location=request.route_url('user_pool', pool_id=pool.id))
    Severity: Major
    Found in chezbetty/views_user.py - About 30 mins to fix

      Avoid too many return statements within this function.
      Open

              return HTTPFound(location=request.route_url('user_pools'))
      Severity: Major
      Found in chezbetty/views_user.py - About 30 mins to fix

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

        def user_pool_changename_submit(request):
            try:
                pool = Pool.from_id(request.POST['pool-id'])
                if pool.owner != request.user.id:
                    request.session.flash('You do not have permission to view that pool.', 'error')
        Severity: Minor
        Found in chezbetty/views_user.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

        @view_config(route_name='user_item_list',
                     renderer='templates/user/item_list.jinja2',
                     permission='user')
        def item_list(request):
            items = DBSession.query(Item)\
        Severity: Major
        Found in chezbetty/views_user.py and 1 other location - About 1 day to fix
        chezbetty/views_public.py on lines 36..51

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

        We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

        The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

        If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

        See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

        Refactorings

        Further Reading

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

                for u in pool.users:
                    if u.user_id == user.id:
                        request.session.flash('User is already in pool.', 'error')
                        return HTTPFound(location=request.route_url('user_pool', pool_id=pool.id))
        Severity: Major
        Found in chezbetty/views_user.py and 1 other location - About 1 hr to fix
        chezbetty/views_user.py on lines 417..419

        Duplicated Code

        Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

        Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

        When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

        Tuning

        This issue has a mass of 47.

        We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

        The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

        If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

        See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

        Refactorings

        Further Reading

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

                if user.id == pool.owner:
                    request.session.flash('You cannot add yourself to a pool. By owning the pool you are automatically a part of it.', 'error')
                    return HTTPFound(location=request.route_url('user_pool', pool_id=pool.id))
        Severity: Major
        Found in chezbetty/views_user.py and 1 other location - About 1 hr to fix
        chezbetty/views_user.py on lines 422..425

        Duplicated Code

        Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

        Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

        When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

        Tuning

        This issue has a mass of 47.

        We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

        The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

        If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

        See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

        Refactorings

        Further Reading

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

                if pool.owner != request.user.id:
                    request.session.flash('You do not have permission to view that pool.', 'error')
                    return HTTPFound(location=request.route_url('user_pools'))
        Severity: Major
        Found in chezbetty/views_user.py and 2 other locations - About 1 hr to fix
        chezbetty/views_user.py on lines 385..387
        chezbetty/views_user.py on lines 447..449

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

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

                if pool.owner != request.user.id:
                    request.session.flash('You do not have permission to view that pool.', 'error')
                    return HTTPFound(location=request.route_url('user_pools'))
        Severity: Major
        Found in chezbetty/views_user.py and 2 other locations - About 1 hr to fix
        chezbetty/views_user.py on lines 385..387
        chezbetty/views_user.py on lines 406..408

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

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

                if pool.owner != request.user.id:
                    request.session.flash('You do not have permission to view that pool.', 'error')
                    return HTTPFound(location=request.route_url('user_pools'))
        Severity: Major
        Found in chezbetty/views_user.py and 2 other locations - About 1 hr to fix
        chezbetty/views_user.py on lines 406..408
        chezbetty/views_user.py on lines 447..449

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

        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

            try:
                pool_name = request.POST['pool-name'].strip()
                if len(pool_name) > 255:
                    pool_name = pool_name[0:255]
                if len(pool_name) < 5:
        Severity: Major
        Found in chezbetty/views_user.py and 3 other locations - About 1 hr to fix
        chezbetty/views_user.py on lines 383..397
        chezbetty/views_user.py on lines 404..438
        chezbetty/views_user.py on lines 445..465

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

        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

            try:
                pool = Pool.from_id(request.matchdict['pool_id'])
                if pool.owner != request.user.id:
                    request.session.flash('You do not have permission to view that pool.', 'error')
                    return HTTPFound(location=request.route_url('user_pools'))
        Severity: Major
        Found in chezbetty/views_user.py and 3 other locations - About 1 hr to fix
        chezbetty/views_user.py on lines 358..376
        chezbetty/views_user.py on lines 404..438
        chezbetty/views_user.py on lines 445..465

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

        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

            try:
                pool = Pool.from_id(request.POST['pool-id'])
                if pool.owner != request.user.id:
                    request.session.flash('You do not have permission to view that pool.', 'error')
                    return HTTPFound(location=request.route_url('user_pools'))
        Severity: Major
        Found in chezbetty/views_user.py and 3 other locations - About 1 hr to fix
        chezbetty/views_user.py on lines 358..376
        chezbetty/views_user.py on lines 383..397
        chezbetty/views_user.py on lines 445..465

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

        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

            try:
                pool = Pool.from_id(request.POST['pool-id'])
                if pool.owner != request.user.id:
                    request.session.flash('You do not have permission to view that pool.', 'error')
                    return HTTPFound(location=request.route_url('user_pools'))
        Severity: Major
        Found in chezbetty/views_user.py and 3 other locations - About 1 hr to fix
        chezbetty/views_user.py on lines 358..376
        chezbetty/views_user.py on lines 383..397
        chezbetty/views_user.py on lines 404..438

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

        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