Skip to content

Commit

Permalink
fix: lint errors
Browse files Browse the repository at this point in the history
  • Loading branch information
pkulkark committed Mar 4, 2024
1 parent c76bb90 commit 5a849e5
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 28 deletions.
26 changes: 17 additions & 9 deletions learning_paths/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)


Expand All @@ -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)
Expand Down
5 changes: 1 addition & 4 deletions learning_paths/compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,4 @@
except ImportError:
CourseEnrollment = None

__all__ = [
"get_course_keys_with_outlines",
"CourseEnrollment"
]
__all__ = ["get_course_keys_with_outlines", "CourseEnrollment"]
17 changes: 8 additions & 9 deletions learning_paths/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down Expand Up @@ -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)
16 changes: 10 additions & 6 deletions learning_paths/signals.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -16,23 +21,22 @@ 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
LearningPathCourseEnrollment.objects.create(
learning_path_enrollment=learning_path_enrollment,
course_key=course_key,
status=LearningPathCourseEnrollment.ACTIVE,
course_enrollment=instance
course_enrollment=instance,
)

0 comments on commit 5a849e5

Please sign in to comment.