Showing 282 of 537 total issues
File views.py
has 1019 lines of code (exceeds 250 allowed). Consider refactoring. Open
import logging
from django.core.exceptions import PermissionDenied
from django.db import transaction
from django.http.response import JsonResponse, HttpResponse
File clients.py
has 864 lines of code (exceeds 250 allowed). Consider refactoring. Open
import random
import timeit
import uuid
import sys
from django.utils import timezone
File serializers.py
has 828 lines of code (exceeds 250 allowed). Consider refactoring. Open
from rest_framework import serializers
from rest_framework.relations import PrimaryKeyRelatedField
from api.core.helpers import str_to_bool
from api.core.serializers import KeyValueChoiceField, ControlListEntryField, GoodControlReviewSerializer
File context_generator.py
has 777 lines of code (exceeds 250 allowed). Consider refactoring. Open
from collections import defaultdict
from datetime import timedelta
from django.contrib.humanize.templatetags.humanize import intcomma
from django.db.models import Q
File applications.py
has 730 lines of code (exceeds 250 allowed). Consider refactoring. Open
from copy import deepcopy
from uuid import UUID
from django.db import transaction
from django.db.models import F, Q
File serializers.py
has 645 lines of code (exceeds 250 allowed). Consider refactoring. Open
from django.contrib.contenttypes.models import ContentType
from django.core.exceptions import ValidationError
from django.utils import timezone
from rest_framework import serializers
Function prefetch_generic_relations
has a Cognitive Complexity of 66 (exceeds 5 allowed). Consider refactoring. Open
def prefetch_generic_relations(qs): # noqa
"""
Prefetches the models attributed to all generic fields in a queryset
From https://djangosnippets.org/snippets/2492/ with some tweaks.
- Read upRead up
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 models.py
has 551 lines of code (exceeds 250 allowed). Consider refactoring. Open
import logging
import uuid
from collections import defaultdict
from typing import Optional
Function search
has a Cognitive Complexity of 55 (exceeds 5 allowed). Consider refactoring. Open
def search( # noqa
self,
queue_id=None,
is_work_queue=None,
user=None,
- Read upRead up
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 managers.py
has 474 lines of code (exceeds 250 allowed). Consider refactoring. Open
from datetime import datetime
from typing import List
from django.apps import apps
from django.db import models, transaction
DataTestClient
has 50 functions (exceeds 20 allowed). Consider refactoring. Open
class DataTestClient(APITestCase, URLPatternsTestCase):
"""
Test client which creates seeds the database with system data and sets up an initial organisation and user
"""
File models.py
has 441 lines of code (exceeds 250 allowed). Consider refactoring. Open
import uuid
from django.contrib.contenttypes.fields import GenericRelation
from django.contrib.postgres.fields import ArrayField
from django.db import models
File views.py
has 430 lines of code (exceeds 250 allowed). Consider refactoring. Open
import logging
from django.conf import settings
from django.core.exceptions import PermissionDenied
from django.db import transaction
CaseQuerySet
has 45 functions (exceeds 20 allowed). Consider refactoring. Open
class CaseQuerySet(models.QuerySet):
"""
Custom queryset for the Case model. This allows us to chain application specific
filtering logic in a reusable way.
Function search
has 49 arguments (exceeds 4 allowed). Consider refactoring. Open
def search( # noqa
File serializers.py
has 415 lines of code (exceeds 250 allowed). Consider refactoring. Open
import re
from django.db import transaction
from django.utils import timezone
from phonenumber_field.serializerfields import PhoneNumberField
File settings.py
has 397 lines of code (exceeds 250 allowed). Consider refactoring. Open
import logging
import os
import sys
from pathlib import Path
from urllib.parse import urlencode
File good.py
has 357 lines of code (exceeds 250 allowed). Consider refactoring. Open
from rest_framework import serializers
from rest_framework.fields import DecimalField, ChoiceField, BooleanField
from rest_framework.relations import PrimaryKeyRelatedField
from django.forms.models import model_to_dict
Function _get_refused_goods_type_context
has a Cognitive Complexity of 30 (exceeds 5 allowed). Consider refactoring. Open
def _get_refused_goods_type_context(case_pk, goods_types, refused_goods_type_on_country_decisions):
# Refused goods types on country from GoodCountryDecisions
context = {}
if refused_goods_type_on_country_decisions:
for decision in refused_goods_type_on_country_decisions:
- Read upRead up
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 __init__
has a Cognitive Complexity of 29 (exceeds 5 allowed). Consider refactoring. Open
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
if hasattr(self, "initial_data"):
if not self.initial_data.get("control_list_entries") and not self.partial:
- Read upRead up
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"