Princeton-CDH/ppa-django

View on GitHub

Showing 52 of 72 total issues

File models.py has 912 lines of code (exceeds 250 allowed). Consider refactoring.
Open

import logging
import re
import time
from zipfile import ZipFile

Severity: Major
Found in ppa/archive/models.py - About 2 days to fix

Function handle has a Cognitive Complexity of 54 (exceeds 5 allowed). Consider refactoring.
Open

    def handle(self, *args, **kwargs):
        self.verbosity = kwargs.get("verbosity", self.v_normal)
        if self.verbosity >= self.v_normal:
            self.stdout.write(
                "Indexing with %d processes" % max(2, kwargs["processes"])
Severity: Minor
Found in ppa/archive/management/commands/index_pages.py - About 1 day 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 forms.py has 394 lines of code (exceeds 250 allowed). Consider refactoring.
Open

from django import forms
from django.core.cache import cache
from django.core.exceptions import ValidationError
from django.core.validators import RegexValidator
from django.db.models import Max, Min
Severity: Minor
Found in ppa/archive/forms.py - About 5 hrs to fix

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

import logging

import requests
from django.contrib import messages
from django.contrib.auth.mixins import PermissionRequiredMixin
Severity: Minor
Found in ppa/archive/views.py - About 5 hrs to fix

File import_util.py has 347 lines of code (exceeds 250 allowed). Consider refactoring.
Open

"""

Import utility classes for creating :mod:`ppa.archives` records from
external sources.

Severity: Minor
Found in ppa/archive/import_util.py - About 4 hrs to fix

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

    def get_queryset(self, **kwargs):
        form_opts = self.request.GET.copy()
        # if relevance sort is requested but there is no keyword search
        # term present, clear it out and fallback to default sort
        if not self.form_class().has_keyword_query(form_opts):
Severity: Minor
Found in ppa/archive/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

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

class DigitizedWork(ModelIndexable, TrackChangesModel):
    """
    Record to manage digitized works included in PPA and store their basic
    metadata.
    """
Severity: Minor
Found in ppa/archive/models.py - About 3 hrs to fix

File admin.py has 296 lines of code (exceeds 250 allowed). Consider refactoring.
Open

from django.urls import re_path
from django.contrib import admin
from django.db.models import Count
from django.http import HttpResponseRedirect
from django.urls import reverse
Severity: Minor
Found in ppa/archive/admin.py - About 3 hrs to fix

File models.py has 294 lines of code (exceeds 250 allowed). Consider refactoring.
Open

import bleach
from django.db import models
from django.template.defaultfilters import striptags, truncatechars_html
from django.utils.text import slugify
from wagtail.admin.panels import FieldPanel
Severity: Minor
Found in ppa/pages/models.py - About 3 hrs to fix

Function metadata_from_marc has a Cognitive Complexity of 20 (exceeds 5 allowed). Consider refactoring.
Open

    def metadata_from_marc(self, marc_record, populate=True):
        """Get metadata from MARC record and return a dictionary
        of the data. When populate is True, calls `populate_fields`
        to set values."""

Severity: Minor
Found in ppa/archive/models.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 handle has a Cognitive Complexity of 19 (exceeds 5 allowed). Consider refactoring.
Open

    def handle(self, *args, **kwargs):
        self.verbosity = kwargs.get("verbosity", self.verbosity)

        # find all excerpted, non-suppressed hathi volumes
        hathi_vols = DigitizedWork.objects.filter(
Severity: Minor
Found in ppa/archive/management/commands/check_hathi_excerpts.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 handle has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring.
Open

    def handle(self, *args, **kwargs):
        # disconnect signal handler for on-demand indexing, for efficiency
        # (index in bulk after an update, not one at a time)
        IndexableSignalHandler.disconnect()

Severity: Minor
Found in ppa/archive/management/commands/hathi_import.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 save has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring.
Open

    def save(self, *args, **kwargs):
        # if status has changed so that object is now suppressed,
        # do some cleanup
        if self.has_changed("status") and self.status == DigitizedWork.SUPPRESSED:
            # remove indexed page content from Solr using index id
Severity: Minor
Found in ppa/archive/models.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 route has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring.
Open

    def route(self, request, path_components):
        """Customize editorial page routing to serve editorial pages
        by year/month/slug."""

        # NOTE: might be able to use RoutablePageMixin for this,
Severity: Minor
Found in ppa/editorial/models.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 handle has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
Open

    def handle(self, *args, **kwargs):
        self.verbosity = kwargs.get("verbosity", self.v_normal)
        self.options = kwargs

        # use ids specified via command line when present
Severity: Minor
Found in ppa/archive/management/commands/hathi_rsync.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 set_choices_from_facets has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
Open

    def set_choices_from_facets(self, facets):
        """Set choices on field from a dictionary of facets"""

        # update collections multiselect based on facets

Severity: Minor
Found in ppa/archive/forms.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 handle has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
Open

    def handle(self, *args, **kwargs):
        data = self.load_csv(kwargs["csv"])

        self.verbosity = kwargs.get("verbosity", self.v_normal)
        self.script_user = User.objects.get(username=settings.SCRIPT_USERNAME)
Severity: Minor
Found in ppa/archive/management/commands/import_clusters.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 hathi_page_index_data has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
Open

    def hathi_page_index_data(cls, digwork):
        """Get page content for the specified digitized work from Hathi
        pairtree and return data to be indexed in solr."""

        # load mets record to pull metadata about the images
Severity: Minor
Found in ppa/archive/models.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 import_digitizedwork has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
Open

    def import_digitizedwork(
        self, gale_id, log_msg_src="", user=None, collections=None, **kwargs
    ):
        """Import a single work into the database.
        Retrieves bibliographic data from Gale API."""
Severity: Minor
Found in ppa/archive/import_util.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 handle has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
Open

    def handle(self, *args, **kwargs):
        self.verbosity = kwargs.get("verbosity", self.verbosity)
        source_ids = kwargs.get("source_ids", [])
        # page count does not affect solr indexing, so disconnect signal handler
        IndexableSignalHandler.disconnect()
Severity: Minor
Found in ppa/archive/management/commands/update_hathi_pagecounts.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

Severity
Category
Status
Source
Language