Skip to content

Commit

Permalink
added doctrings for Training Queryset Methods
Browse files Browse the repository at this point in the history
  • Loading branch information
Rutvikrj26 committed Oct 22, 2024
1 parent 0dfc8fa commit dfbfce7
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 11 deletions.
17 changes: 9 additions & 8 deletions physionet-django/training/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,15 @@ def get_course_and_module_progress(user, course, module_order):
slug = get_random_string(20)
while Training.objects.filter(slug=slug).exists():
slug = get_random_string(20)
training = Training()
training.slug = slug
training.training_type = course.training_type
training.user = user
training.course = course
training.process_datetime = timezone.now()
training.status = TrainingStatus.REVIEW
training.save()
training = Training.objects.create(
slug=slug,
training_type=course.training_type,
user=user,
course=course,
process_datetime=timezone.now(),
status=TrainingStatus.REVIEW
)


module = get_object_or_404(course.modules, order=module_order)
module_progress, _ = ModuleProgress.objects.get_or_create(course_progress=course_progress, module=module)
Expand Down
18 changes: 15 additions & 3 deletions physionet-django/user/managers.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,28 @@

class TrainingQuerySet(QuerySet):
def get_review(self):
"""
Get the document-based or URL-based training objects for the user, that are in the status REVIEW.
"""
return self.filter(
Q(status=TrainingStatus.REVIEW),
Q(training_type__required_field=RequiredField.DOCUMENT)
| Q(training_type__required_field=RequiredField.URL)
)

# adding a query to fetch the on-platform courses that are in the status REVIEW.
def in_progress(self):
"""
Get the on-platform training objects for the user, that are in the status REVIEW.
"""
return self.filter(
Q(status=TrainingStatus.REVIEW),
Q(training_type__required_field=RequiredField.PLATFORM)
)

def get_valid(self):

"""
Get all the training objects that are in the status ACCEPTED and have not expired.
"""
return self.filter(
Q(status=TrainingStatus.ACCEPTED),
Q(training_type__valid_duration__isnull=True)
Expand All @@ -39,7 +46,9 @@ def get_valid(self):
)

def get_expired(self):

"""
Get all the training objects that are in the status ACCEPTED and have expired
"""
return self.filter(
Q(status=TrainingStatus.ACCEPTED),
Q(process_datetime__lt=timezone.now() - Case(
Expand All @@ -56,4 +65,7 @@ def get_expired(self):
)

def get_rejected(self):
"""
Get all the training objects that are in the status REJECTED.
"""
return self.filter(status=TrainingStatus.REJECTED)

0 comments on commit dfbfce7

Please sign in to comment.