svthalia/concrexit

View on GitHub
website/events/services.py

Summary

Maintainability
F
3 days
Test Coverage

File services.py has 447 lines of code (exceeds 250 allowed). Consider refactoring.
Open

from collections import OrderedDict
from datetime import date, timedelta

from django.db.models import Q
from django.utils import timezone
Severity: Minor
Found in website/events/services.py - About 6 hrs to fix

Function event_permissions has a Cognitive Complexity of 31 (exceeds 5 allowed). Consider refactoring.
Open

def event_permissions(member, event: Event, name=None, registration_prefetch=False):
    """Return a dictionary with the available event permissions of the user.

    :param member: the user
    :param event: the event
Severity: Minor
Found in website/events/services.py - About 4 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 registration_status has a Cognitive Complexity of 26 (exceeds 5 allowed). Consider refactoring.
Open

def registration_status(event: Event, registration: EventRegistration, member):
    if not event.registration_required and not event.optional_registration_allowed:
        return status.STATUS_NONE

    if not member or not member.is_authenticated:
Severity: Minor
Found in website/events/services.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 update_registration has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring.
Open

def update_registration(
    member=None, event=None, name=None, registration=None, field_values=None, actor=None
):
    """Update a user registration of an event.

Severity: Minor
Found in website/events/services.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 cancel_registration has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
Open

def cancel_registration(member, event):
    """Cancel a user registration for an event.

    :param member: the user
    :param event: the event
Severity: Minor
Found in website/events/services.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 create_registration has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
Open

def create_registration(member, event):
    """Create a new user registration for an event.

    :param member: the user
    :param event: the event
Severity: Minor
Found in website/events/services.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 registration_fields has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
Open

def registration_fields(request, member=None, event=None, registration=None, name=None):
    """Return information about the registration fields of a registration.

    :param member: the user (optional if registration provided)
    :param name: the name of a non member registration
Severity: Minor
Found in website/events/services.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 update_registration_by_organiser has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
Open

def update_registration_by_organiser(registration, member, data):
    if not is_organiser(member, registration.event):
        raise RegistrationError(_("You are not allowed to update this registration."))

    if "present" in data:
Severity: Minor
Found in website/events/services.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 update_registration has 6 arguments (exceeds 4 allowed). Consider refactoring.
Open

def update_registration(
Severity: Minor
Found in website/events/services.py - About 45 mins to fix

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

def registration_fields(request, member=None, event=None, registration=None, name=None):
Severity: Minor
Found in website/events/services.py - About 35 mins to fix

Function is_eventdocument_owner has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
Open

def is_eventdocument_owner(member, event_doc):
    if member and member.is_authenticated:
        if member.is_superuser or member.has_perm("documents.override_owner"):
            return True

Severity: Minor
Found in website/events/services.py - About 35 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 status.STATUS_CANCELLED_LATE
Severity: Major
Found in website/events/services.py - About 30 mins to fix

Avoid too many return statements within this function.
Open

        return status.STATUS_OPEN
Severity: Major
Found in website/events/services.py - About 30 mins to fix

Avoid too many return statements within this function.
Open

            return status.STATUS_WAITINGLIST
Severity: Major
Found in website/events/services.py - About 30 mins to fix

Avoid too many return statements within this function.
Open

        return status.STATUS_EXPIRED
Severity: Major
Found in website/events/services.py - About 30 mins to fix

Avoid too many return statements within this function.
Open

        return False
Severity: Major
Found in website/events/services.py - About 30 mins to fix

Avoid too many return statements within this function.
Open

            return status.STATUS_CANCELLED_FINAL
Severity: Major
Found in website/events/services.py - About 30 mins to fix

Avoid too many return statements within this function.
Open

            return status.STATUS_OPTIONAL_REGISTERED
Severity: Major
Found in website/events/services.py - About 30 mins to fix

Avoid too many return statements within this function.
Open

        return status.STATUS_FULL
Severity: Major
Found in website/events/services.py - About 30 mins to fix

Avoid too many return statements within this function.
Open

        return status.STATUS_REGISTERED
Severity: Major
Found in website/events/services.py - About 30 mins to fix

Avoid too many return statements within this function.
Open

        return status.STATUS_OPTIONAL
Severity: Major
Found in website/events/services.py - About 30 mins to fix

Avoid too many return statements within this function.
Open

                return status.STATUS_CANCELLED
Severity: Major
Found in website/events/services.py - About 30 mins to fix

Avoid too many return statements within this function.
Open

        return status.STATUS_WILL_OPEN
Severity: Major
Found in website/events/services.py - About 30 mins to fix

Avoid too many return statements within this function.
Open

        return False
Severity: Major
Found in website/events/services.py - About 30 mins to fix

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

def is_organiser(member, event):
    if member and member.is_authenticated:
        if member.is_superuser or member.has_perm("events.override_organiser"):
            return True

Severity: Minor
Found in website/events/services.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

There are no issues that match your filters.

Category
Status