diff --git a/physionet-django/training/views.py b/physionet-django/training/views.py index 6ed60a575..3e75fea54 100644 --- a/physionet-django/training/views.py +++ b/physionet-django/training/views.py @@ -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) diff --git a/physionet-django/user/managers.py b/physionet-django/user/managers.py index 46b1ecd68..f86c4a682 100644 --- a/physionet-django/user/managers.py +++ b/physionet-django/user/managers.py @@ -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) @@ -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( @@ -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)