Skip to content

Commit

Permalink
fix: lint fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
pkulkark committed Jan 22, 2025
1 parent 143e729 commit f2923e6
Show file tree
Hide file tree
Showing 10 changed files with 20 additions and 16 deletions.
3 changes: 0 additions & 3 deletions openedx_certificates/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
1 change: 1 addition & 0 deletions openedx_certificates/compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 6 additions & 4 deletions openedx_certificates/generators.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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.
Expand Down Expand Up @@ -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.
Expand Down
6 changes: 4 additions & 2 deletions openedx_certificates/models.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Database models for openedx_certificates."""

from __future__ import annotations

import json
Expand All @@ -12,15 +13,14 @@
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
from django.utils.translation import gettext_lazy as _
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
Expand Down Expand Up @@ -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')

Expand Down
11 changes: 4 additions & 7 deletions openedx_certificates/processors.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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'):
Expand All @@ -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:
Expand Down
1 change: 1 addition & 0 deletions openedx_certificates/settings/common.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""App-specific settings for all environments."""

from django.conf import Settings


Expand Down
1 change: 1 addition & 0 deletions openedx_certificates/settings/production.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""App-specific settings for production environments."""

from django.conf import Settings


Expand Down
1 change: 1 addition & 0 deletions openedx_certificates/urls.py
Original file line number Diff line number Diff line change
@@ -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

Expand Down
1 change: 1 addition & 0 deletions tests/test_models.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Tests for the `openedx-certificates` models."""

from __future__ import annotations

from typing import TYPE_CHECKING, Any
Expand Down
1 change: 1 addition & 0 deletions tests/test_processors.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Tests for the certificate processors."""

from __future__ import annotations

from unittest.mock import Mock, call, patch
Expand Down

0 comments on commit f2923e6

Please sign in to comment.