From f2923e62b13ffaaace1adbfa3e51bfed17074a2b Mon Sep 17 00:00:00 2001 From: Pooja Kulkarni Date: Wed, 22 Jan 2025 14:27:21 -0500 Subject: [PATCH] fix: lint fixes --- openedx_certificates/admin.py | 3 --- openedx_certificates/compat.py | 1 + openedx_certificates/generators.py | 10 ++++++---- openedx_certificates/models.py | 6 ++++-- openedx_certificates/processors.py | 11 ++++------- openedx_certificates/settings/common.py | 1 + openedx_certificates/settings/production.py | 1 + openedx_certificates/urls.py | 1 + tests/test_models.py | 1 + tests/test_processors.py | 1 + 10 files changed, 20 insertions(+), 16 deletions(-) diff --git a/openedx_certificates/admin.py b/openedx_certificates/admin.py index 40b9cc4..d9f1d48 100644 --- a/openedx_certificates/admin.py +++ b/openedx_certificates/admin.py @@ -8,12 +8,9 @@ from django import forms from django.contrib import admin -from django.core.exceptions import ValidationError from django.utils.html import format_html from django_object_actions import DjangoObjectActions, action from django_reverse_admin import ReverseModelAdmin -from opaque_keys import InvalidKeyError -from opaque_keys.edx.keys import CourseKey from .models import ( ExternalCertificate, diff --git a/openedx_certificates/compat.py b/openedx_certificates/compat.py index 58c5620..5ca4281 100644 --- a/openedx_certificates/compat.py +++ b/openedx_certificates/compat.py @@ -4,6 +4,7 @@ This module moderates access to all edx-platform features allowing for cross-version compatibility code. It also simplifies running tests outside edx-platform's environment by stubbing these functions in unit tests. """ + from __future__ import annotations from contextlib import contextmanager diff --git a/openedx_certificates/generators.py b/openedx_certificates/generators.py index 1d583da..6998d60 100644 --- a/openedx_certificates/generators.py +++ b/openedx_certificates/generators.py @@ -31,9 +31,7 @@ if TYPE_CHECKING: # pragma: no cover from uuid import UUID - from django.contrib.auth.models import User - from opaque_keys.edx.keys import CourseKey def _get_user_name(user: User) -> str: @@ -59,7 +57,9 @@ def _register_font(options: dict[str, Any]) -> str: return font or 'Helvetica' -def _write_text_on_template(template: any, font: str, username: str, resource_name: str, options: dict[str, Any]) -> any: +def _write_text_on_template( + template: any, font: str, username: str, resource_name: str, options: dict[str, Any], +) -> any: """ Prepare a new canvas and write the user and resource name onto it. @@ -163,7 +163,9 @@ def _save_certificate(certificate: PdfWriter, certificate_uuid: UUID) -> str: return url -def generate_pdf_certificate(resource_id, resource_type, user: User, certificate_uuid: UUID, options: dict[str, Any]) -> str: +def generate_pdf_certificate( + resource_id, resource_type, user: User, certificate_uuid: UUID, options: dict[str, Any], +) -> str: """ Generate a PDF certificate. diff --git a/openedx_certificates/models.py b/openedx_certificates/models.py index af78d9c..80faa67 100644 --- a/openedx_certificates/models.py +++ b/openedx_certificates/models.py @@ -1,4 +1,5 @@ """Database models for openedx_certificates.""" + from __future__ import annotations import json @@ -12,7 +13,7 @@ from django.apps import apps from django.conf import settings from django.contrib.auth import get_user_model -from django.core.exceptions import ValidationError, ObjectDoesNotExist +from django.core.exceptions import ValidationError from django.db import models from django.db.models.signals import post_delete from django.dispatch import receiver @@ -20,7 +21,6 @@ from django_celery_beat.models import IntervalSchedule, PeriodicTask from edx_ace import Message, Recipient, ace from model_utils.models import TimeStampedModel -from opaque_keys.edx.django.models import CourseKeyField from openedx_certificates.compat import get_course_name from openedx_certificates.exceptions import AssetNotFoundError, CertificateGenerationError @@ -73,8 +73,10 @@ class ExternalCertificateConfiguration(TimeStampedModel): .. no_pii: """ + class ResourceTypes(models.TextChoices): """Types of resources for which certificates can be issued.""" + COURSE = 'course', _('Course') LEARNING_PATH = 'learning_path', _('Learning Path') diff --git a/openedx_certificates/processors.py b/openedx_certificates/processors.py index 4e7c25d..0b6379b 100644 --- a/openedx_certificates/processors.py +++ b/openedx_certificates/processors.py @@ -18,14 +18,13 @@ from rest_framework.request import Request from rest_framework.test import APIRequestFactory -from openedx_certificates.models import ExternalCertificateConfiguration - from openedx_certificates.compat import ( get_course_enrollments, get_course_grade_factory, get_course_grading_policy, prefetch_course_grades, ) +from openedx_certificates.models import ExternalCertificateConfiguration if TYPE_CHECKING: # pragma: no cover from django.contrib.auth.models import User @@ -226,10 +225,9 @@ def retrieve_course_completions(course_id: CourseKey, options: dict[str, Any]) - return list(get_user_model().objects.filter(username__in=completions).values_list('id', flat=True)) + def retrieve_learner_paths_eligible_users(lp_uuid, options: dict[str, Any]) -> list[int]: - """ - Retrieve eligible users for a Learning Path. - """ + """Retrieve eligible users for a Learning Path.""" eligible_users = None if not apps.is_installed('learning_paths'): @@ -246,8 +244,7 @@ def retrieve_learner_paths_eligible_users(lp_uuid, options: dict[str, Any]) -> l course_id = str(step.course_key) try: existing_config = ExternalCertificateConfiguration.objects.get( - resource_id=course_id, - resource_type=ExternalCertificateConfiguration.ResourceTypes.COURSE + resource_id=course_id, resource_type=ExternalCertificateConfiguration.ResourceTypes.COURSE, ) course_users = existing_config.get_eligible_user_ids() except ExternalCertificateConfiguration.DoesNotExist: diff --git a/openedx_certificates/settings/common.py b/openedx_certificates/settings/common.py index ec7424f..e352a65 100644 --- a/openedx_certificates/settings/common.py +++ b/openedx_certificates/settings/common.py @@ -1,4 +1,5 @@ """App-specific settings for all environments.""" + from django.conf import Settings diff --git a/openedx_certificates/settings/production.py b/openedx_certificates/settings/production.py index 430e6cf..340cec9 100644 --- a/openedx_certificates/settings/production.py +++ b/openedx_certificates/settings/production.py @@ -1,4 +1,5 @@ """App-specific settings for production environments.""" + from django.conf import Settings diff --git a/openedx_certificates/urls.py b/openedx_certificates/urls.py index 77c6601..7926135 100644 --- a/openedx_certificates/urls.py +++ b/openedx_certificates/urls.py @@ -1,4 +1,5 @@ """URLs for openedx_certificates.""" + # from django.urls import re_path # noqa: ERA001, RUF100 # from django.views.generic import TemplateView # noqa: ERA001, RUF100 diff --git a/tests/test_models.py b/tests/test_models.py index f07e58d..637e12a 100644 --- a/tests/test_models.py +++ b/tests/test_models.py @@ -1,4 +1,5 @@ """Tests for the `openedx-certificates` models.""" + from __future__ import annotations from typing import TYPE_CHECKING, Any diff --git a/tests/test_processors.py b/tests/test_processors.py index 4ab9068..f428c6d 100644 --- a/tests/test_processors.py +++ b/tests/test_processors.py @@ -1,4 +1,5 @@ """Tests for the certificate processors.""" + from __future__ import annotations from unittest.mock import Mock, call, patch