Cloud-CV/EvalAI

View on GitHub
apps/participants/views.py

Summary

Maintainability
F
3 days
Test Coverage

File views.py has 474 lines of code (exceeds 250 allowed). Consider refactoring.
Open

from django.contrib.auth.models import User

from drf_yasg import openapi
from drf_yasg.utils import swagger_auto_schema
from rest_framework import permissions, status
Severity: Minor
Found in apps/participants/views.py - About 7 hrs to fix

    Function invite_participant_to_team has a Cognitive Complexity of 44 (exceeds 5 allowed). Consider refactoring.
    Open

    def invite_participant_to_team(request, pk):
        try:
            participant_team = ParticipantTeam.objects.get(pk=pk)
        except ParticipantTeam.DoesNotExist:
            response_data = {"error": "Participant Team does not exist"}
    Severity: Minor
    Found in apps/participants/views.py - About 6 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 participant_team_detail has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
    Open

    def participant_team_detail(request, pk):
    
        try:
            participant_team = ParticipantTeam.objects.get(pk=pk)
        except ParticipantTeam.DoesNotExist:
    Severity: Minor
    Found in apps/participants/views.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 remove_participant_team_from_challenge has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
    Open

    def remove_participant_team_from_challenge(
        request, challenge_pk, participant_team_pk
    ):
        """
        API to remove the participant team from a challenge
    Severity: Minor
    Found in apps/participants/views.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

                        for domain in challenge.allowed_email_domains:
                            domains = "{}{}{}".format(domains, "/", domain)
                        domains = domains[1:]
    Severity: Major
    Found in apps/participants/views.py - About 45 mins to fix

      Avoid deeply nested control flow statements.
      Open

                          if participant_email in challenge.banned_email_ids:
                              message = "You cannot invite as you're a part of {} team and it has been banned "
                              "from this challenge. Please contact the challenge host."
                              response_data = {
                                  "error": message.format(participant_team.team_name)
      Severity: Major
      Found in apps/participants/views.py - About 45 mins to fix

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

        def delete_participant_from_team(request, participant_team_pk, participant_pk):
            """
            Deletes a participant from a Participant Team
            """
            try:
        Severity: Minor
        Found in apps/participants/views.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

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

        def get_teams_and_corresponding_challenges_for_a_participant(
            request, challenge_pk
        ):
            """
            Returns list of teams and corresponding challenges for a participant
        Severity: Minor
        Found in apps/participants/views.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 Response(
        Severity: Major
        Found in apps/participants/views.py - About 30 mins to fix

          Avoid too many return statements within this function.
          Open

                      return Response(response_data, status=status.HTTP_200_OK)
          Severity: Major
          Found in apps/participants/views.py - About 30 mins to fix

            Avoid too many return statements within this function.
            Open

                    return Response(response_data, status=status.HTTP_406_NOT_ACCEPTABLE)
            Severity: Major
            Found in apps/participants/views.py - About 30 mins to fix

              Avoid too many return statements within this function.
              Open

                                  return Response(
              Severity: Major
              Found in apps/participants/views.py - About 30 mins to fix

                Avoid too many return statements within this function.
                Open

                    return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
                Severity: Major
                Found in apps/participants/views.py - About 30 mins to fix

                  Avoid too many return statements within this function.
                  Open

                                          return Response(
                  Severity: Major
                  Found in apps/participants/views.py - About 30 mins to fix

                    Avoid too many return statements within this function.
                    Open

                            return Response(response_data, status=status.HTTP_401_UNAUTHORIZED)
                    Severity: Major
                    Found in apps/participants/views.py - About 30 mins to fix

                      Avoid too many return statements within this function.
                      Open

                                  return Response(errors, status=status.HTTP_400_BAD_REQUEST)
                      Severity: Major
                      Found in apps/participants/views.py - About 30 mins to fix

                        Avoid too many return statements within this function.
                        Open

                                            return Response(
                        Severity: Major
                        Found in apps/participants/views.py - About 30 mins to fix

                          Avoid too many return statements within this function.
                          Open

                                  return Response(response_data, status=status.HTTP_202_ACCEPTED)
                          Severity: Major
                          Found in apps/participants/views.py - About 30 mins to fix

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

                            def remove_self_from_participant_team(request, participant_team_pk):
                                """
                                A user can remove himself from the participant team.
                                """
                                try:
                            Severity: Minor
                            Found in apps/participants/views.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