From 5a849e5abcf8c961443442c0807a6affad71f490 Mon Sep 17 00:00:00 2001 From: Pooja Kulkarni Date: Mon, 4 Mar 2024 11:32:51 -0500 Subject: [PATCH] fix: lint errors --- learning_paths/admin.py | 26 +++++++++++++++++--------- learning_paths/compat.py | 5 +---- learning_paths/models.py | 17 ++++++++--------- learning_paths/signals.py | 16 ++++++++++------ 4 files changed, 36 insertions(+), 28 deletions(-) diff --git a/learning_paths/admin.py b/learning_paths/admin.py index 590d235..dcb4425 100644 --- a/learning_paths/admin.py +++ b/learning_paths/admin.py @@ -122,20 +122,26 @@ class LearningPathAdmin(admin.ModelAdmin): def save_related(self, request, form, formsets, change): """Save related objects and enroll users in the learning path.""" super().save_related(request, form, formsets, change) - enroll_all_in_courses = form.cleaned_data.get('enroll_all_in_courses', False) + enroll_all_in_courses = form.cleaned_data.get("enroll_all_in_courses", False) with transaction.atomic(): for user in form.cleaned_data["usernames"]: - learning_path_enrollment, created = LearningPathEnrollment.objects.get_or_create( - user=user, learning_path=form.instance + learning_path_enrollment, created = ( + LearningPathEnrollment.objects.get_or_create( + user=user, learning_path=form.instance + ) ) if enroll_all_in_courses: - courses = LearningPathStep.objects.filter(learning_path=form.instance).values_list('course_key', flat=True) + courses = LearningPathStep.objects.filter( + learning_path=form.instance + ).values_list("course_key", flat=True) for course_key in courses: LearningPathCourseEnrollment.objects.create( course_key=course_key, learning_path_enrollment=learning_path_enrollment, - course_enrollment=CourseEnrollment.objects.get_or_create(user=user, course_id=course_key)[0], - status=LearningPathCourseEnrollment.ACTIVE + course_enrollment=CourseEnrollment.objects.get_or_create( + user=user, course_id=course_key + )[0], + status=LearningPathCourseEnrollment.ACTIVE, ) @@ -159,10 +165,12 @@ class EnrolledUsersAdmin(admin.ModelAdmin): ] class LearningPathCourseEnrollmentAdmin(admin.ModelAdmin): - """ Admin for Learning Path Course enrollments.""" + """Admin for Learning Path Course enrollments.""" + model = LearningPathCourseEnrollment - list_display = ['learning_path_enrollment', 'course_key', 'status'] - list_filter = ['status'] + list_display = ["learning_path_enrollment", "course_key", "status"] + list_filter = ["status"] + admin.site.register(LearningPath, LearningPathAdmin) admin.site.register(Skill, SkillAdmin) diff --git a/learning_paths/compat.py b/learning_paths/compat.py index 609c833..9e28e2c 100644 --- a/learning_paths/compat.py +++ b/learning_paths/compat.py @@ -15,7 +15,4 @@ except ImportError: CourseEnrollment = None -__all__ = [ - "get_course_keys_with_outlines", - "CourseEnrollment" -] +__all__ = ["get_course_keys_with_outlines", "CourseEnrollment"] diff --git a/learning_paths/models.py b/learning_paths/models.py index 21354b6..3cd08f1 100644 --- a/learning_paths/models.py +++ b/learning_paths/models.py @@ -11,7 +11,6 @@ from model_utils.models import TimeStampedModel from opaque_keys.edx.django.models import CourseKeyField from .compat import CourseEnrollment -# from common.djangoapps.student.models import CourseEnrollment User = auth.get_user_model() @@ -193,18 +192,18 @@ class LearningPathCourseEnrollment(TimeStampedModel): """ Model to track course enrollments that are part of a learning path """ - ACTIVE = 'active' - INACTIVE = 'inactive' - STATUS_CHOICES = ( - (ACTIVE, 'Active'), - (INACTIVE, 'Inactive') - ) + ACTIVE = "active" + INACTIVE = "inactive" + STATUS_CHOICES = ((ACTIVE, "Active"),(INACTIVE, "Inactive")) + class Meta: """Model options.""" - unique_together = ('learning_path_enrollment', 'course_key') + unique_together = ("learning_path_enrollment", "course_key") - learning_path_enrollment = models.ForeignKey(LearningPathEnrollment, on_delete=models.CASCADE) + learning_path_enrollment = models.ForeignKey( + LearningPathEnrollment, on_delete=models.CASCADE + ) course_key = CourseKeyField(max_length=255) status = models.CharField(max_length=9, choices=STATUS_CHOICES) course_enrollment = models.ForeignKey(CourseEnrollment, on_delete=models.CASCADE) diff --git a/learning_paths/signals.py b/learning_paths/signals.py index 8e13fd1..da86fbb 100644 --- a/learning_paths/signals.py +++ b/learning_paths/signals.py @@ -3,10 +3,15 @@ from django.db.models.signals import post_save from django.dispatch import receiver from .compat import CourseEnrollment -from .models import LearningPathCourseEnrollment, LearningPathStep, LearningPathEnrollment +from .models import ( + LearningPathCourseEnrollment, + LearningPathStep, + LearningPathEnrollment, +) logger = logging.getLogger(__name__) + @receiver(post_save, sender=CourseEnrollment) def create_learningpath_course_enrollment(sender, instance, created, **kwargs): if created: # Only react to new enrollments @@ -16,17 +21,16 @@ def create_learningpath_course_enrollment(sender, instance, created, **kwargs): try: learning_path_step = LearningPathStep.objects.get(course_key=course_key) except LearningPathStep.DoesNotExist: - logger.info('Course is not part of any Learning Path. Ignoring.') + logger.info("Course is not part of any Learning Path. Ignoring.") return # Find the associated LearningPathEnrollment try: learning_path_enrollment = LearningPathEnrollment.objects.get( - learning_path=learning_path_step.learning_path, - user=instance.user + learning_path=learning_path_step.learning_path, user=instance.user ) except LearningPathEnrollment.DoesNotExist: - logger.warning('User is not enrolled in the relevant Learning Path.') + logger.warning("User is not enrolled in the relevant Learning Path.") return # Create the LearningPathCourseEnrollment object @@ -34,5 +38,5 @@ def create_learningpath_course_enrollment(sender, instance, created, **kwargs): learning_path_enrollment=learning_path_enrollment, course_key=course_key, status=LearningPathCourseEnrollment.ACTIVE, - course_enrollment=instance + course_enrollment=instance, )