Showing 517 of 5,909 total issues

Function chrome_getdata_view has a Cognitive Complexity of 32 (exceeds 5 allowed). Consider refactoring.
Open

def chrome_getdata_view(request):
    """Get the data of the last notification sent to the current user.

    This is needed because Chrome, as of version 44, doesn't support
    sending a data payload to a notification. Thus, information on what
Severity: Minor
Found in intranet/apps/notifications/views.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 save_preferred_pic has a Cognitive Complexity of 32 (exceeds 5 allowed). Consider refactoring.
Open

def save_preferred_pic(request, user):
    preferred_pic = get_preferred_pic(user)
    preferred_pic_form = PreferredPictureForm(user, data=request.POST, initial=preferred_pic)
    if preferred_pic_form.is_valid():
        if preferred_pic_form.has_changed():
Severity: Minor
Found in intranet/apps/preferences/views.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 search_view has a Cognitive Complexity of 32 (exceeds 5 allowed). Consider refactoring.
Open

def search_view(request):
    if not request.user.has_admin_permission("itemreg") and not request.user.is_teacher:
        raise http.Http404

    item_type = request.GET.get("type", "")
Severity: Minor
Found in intranet/apps/itemreg/views.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 print_job has a Cognitive Complexity of 31 (exceeds 5 allowed). Consider refactoring.
Open

def print_job(obj: PrintJob, do_print: bool = True):
    printer = obj.printer
    if printer not in get_printers().keys():
        raise Exception("Printer not authorized.")

Severity: Minor
Found in intranet/apps/printing/views.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 gen_sponsor_schedule has a Cognitive Complexity of 31 (exceeds 5 allowed). Consider refactoring.
Open

def gen_sponsor_schedule(user, sponsor=None, num_blocks=6, surrounding_blocks=None, given_date=None):
    r"""Return a list of :class:`EighthScheduledActivity`\s in which the
    given user is sponsoring.

    Returns:
Severity: Minor
Found in intranet/apps/dashboard/views.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 files_upload has a Cognitive Complexity of 31 (exceeds 5 allowed). Consider refactoring.
Open

def files_upload(request, fstype=None):
    fsdir = request.GET.get("dir", None)
    if fsdir is None:
        return redirect("files")

Severity: Minor
Found in intranet/apps/files/views.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 handle has a Cognitive Complexity of 30 (exceeds 5 allowed). Consider refactoring.
Open

    def handle(self, *args, **options):
        # Read the data file
        with open(options["filename"], "r", encoding="utf-8") as csvfile:
            data = list(csv.DictReader(csvfile))

Severity: Minor
Found in intranet/apps/dataimport/management/commands/import_students.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

File tests.py has 350 lines of code (exceeds 250 allowed). Consider refactoring.
Open

import json

from django.contrib.auth import get_user_model
from django.urls import reverse
from django.utils import timezone
Severity: Minor
Found in intranet/apps/announcements/tests.py - About 4 hrs to fix

    Function test_api_eighth_signup_list has 107 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        def test_api_eighth_signup_list(self):
            self.make_token()
    
            # Don't let blocks created in other tests contaminate these results
            EighthBlock.objects.all().delete()
    Severity: Major
    Found in intranet/apps/api/tests.py - About 4 hrs to fix

      File tests.py has 344 lines of code (exceeds 250 allowed). Consider refactoring.
      Open

      import datetime
      import json
      
      from django.urls import reverse
      from django.utils import timezone
      Severity: Minor
      Found in intranet/apps/polls/tests.py - About 4 hrs to fix

        Function edit_group_view has a Cognitive Complexity of 29 (exceeds 5 allowed). Consider refactoring.
        Open

        def edit_group_view(request, group_id):
            try:
                group = Group.objects.get(id=group_id)
            except Group.DoesNotExist as e:
                raise http.Http404 from e
        Severity: Minor
        Found in intranet/apps/eighth/views/admin/groups.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

        File serializers.py has 337 lines of code (exceeds 250 allowed). Consider refactoring.
        Open

        # pylint: disable=abstract-method
        import collections
        import functools
        import logging
        
        
        Severity: Minor
        Found in intranet/apps/eighth/serializers.py - About 4 hrs to fix

          Function determine_ranked_choice_winners has a Cognitive Complexity of 27 (exceeds 5 allowed). Consider refactoring.
          Open

          def determine_ranked_choice_winners(poll):
              # pyrankvote's Candidate class is broken, so use a custom class instead
              class Candidate:
                  """A candidate in the election."""
          
          
          Severity: Minor
          Found in intranet/apps/polls/views.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

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

          import logging
          
          from django import http
          from django.contrib import messages
          from django.contrib.auth.decorators import login_required
          Severity: Minor
          Found in intranet/apps/announcements/views.py - About 3 hrs to fix

            Function generate_activities has a Cognitive Complexity of 26 (exceeds 5 allowed). Consider refactoring.
            Open

            def generate_activities(args: argparse.Namespace) -> None:
                ids = EighthActivity.available_ids()
                groups = [Group.objects.get_or_create(name=group)[0] for group in args.groups]
                teachers = User.objects.filter(user_type="teacher")
                for _, id in zip(range(args.count), ids):
            Severity: Minor
            Found in config/scripts/create_activities.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

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

            import logging
            import math
            import os
            import re
            import subprocess
            Severity: Minor
            Found in intranet/apps/printing/views.py - About 3 hrs to fix

              Function success has 90 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                          success: function(response) {
                              var activity = activityModels.get(aid);
              
                              if (response.indexOf("added to waitlist") === -1) {
                                  // If:
              Severity: Major
              Found in intranet/static/js/eighth/signup.js - About 3 hrs to fix

                Function fuzzy_date has a Cognitive Complexity of 25 (exceeds 5 allowed). Consider refactoring.
                Open

                def fuzzy_date(date):
                    """Formats a `datetime.datetime` object relative to the current time."""
                
                    if date.tzinfo is None:
                        date = timezone.make_aware(date)
                Severity: Minor
                Found in intranet/apps/templatetags/dates.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 add_widgets_context has a Cognitive Complexity of 25 (exceeds 5 allowed). Consider refactoring.
                Open

                def add_widgets_context(request, context):
                    """
                    WIDGETS:
                    * Eighth signup (STUDENT)
                    * Eighth attendance (TEACHER or ADMIN)
                Severity: Minor
                Found in intranet/apps/dashboard/views.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

                EighthScheduledActivity has 29 functions (exceeds 20 allowed). Consider refactoring.
                Open

                class EighthScheduledActivity(AbstractBaseEighthModel):
                    r"""Represents the relationship between an activity and a block in which it has been scheduled.
                    Attributes:
                        block : :class:`EighthBlock`
                            The :class:`EighthBlock` during which an
                Severity: Minor
                Found in intranet/apps/eighth/models.py - About 3 hrs to fix
                  Severity
                  Category
                  Status
                  Source
                  Language