Skip to content

Commit

Permalink
Updated the UI & forms to show active courses, and only showup when t…
Browse files Browse the repository at this point in the history
…here are active courses on the platform
  • Loading branch information
Rutvikrj26 committed Apr 21, 2024
1 parent facd8ed commit ea93dd5
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 10 deletions.
12 changes: 8 additions & 4 deletions physionet-django/training/forms.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from django import forms
from django.db.models import Max, F
from django.db.models import Max, F, OuterRef

from training.models import Course
from user.models import TrainingType
Expand All @@ -16,10 +16,14 @@ class Meta:
def __init__(self, *args, **kwargs):
training_id = kwargs.pop('training_type', None)
super().__init__(*args, **kwargs)

self.fields['training_type'].queryset = self.fields['training_type'].queryset.annotate(
max_version=Max('courses__version')).filter(
courses__version=F('max_version')).filter(
required_field=RequiredField.PLATFORM)
max_version=Max('courses__version')
).filter(
courses__version=F('max_version'),
required_field=RequiredField.PLATFORM,
courses__is_active=True
)

self.training_type = TrainingType.objects.filter(id=training_id).first()

Expand Down
7 changes: 3 additions & 4 deletions physionet-django/user/templates/user/edit_training.html
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,10 @@ <h5 class="modal-title">Submit Training</h5>
</div>
</form>

<hr>
<h4>Complete training course on Platform</h4>
<br>

{% if take_course_form %}
<h4>Complete training course on Platform</h4>
<form action="{% url 'start_training' %}" method="POST" id="on_platform_training">
{% include "descriptive_inline_form_snippet.html" with form=take_course_form %}
<button type="button" class="btn btn-primary btn-rsp" data-toggle="modal" data-target="#start-training">Start Training</button>
Expand All @@ -70,8 +71,6 @@ <h5 class="modal-title">Start Training</h5>
</div>
</div>
</form>
{% else %}
<p>N/A</p>
{% endif %}


Expand Down
15 changes: 13 additions & 2 deletions physionet-django/user/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
from physionet.settings.base import StorageTypes
from project.models import Author, DUASignature, DUA, PublishedProject
from training.forms import CourseForm
from training.models import Course
from requests_oauthlib import OAuth2Session
from user import forms, validators
from user.models import (
Expand All @@ -60,6 +61,7 @@
TrainingType,
)
from user.userfiles import UserFiles
from user.enums import RequiredField
from physionet.models import StaticPage
from django.db.models import F

Expand Down Expand Up @@ -767,14 +769,23 @@ def edit_training(request):

else:
training_type = request.GET.get("trainingType")
take_course_form = None
if training_type:
training_form = forms.TrainingForm(
user=request.user, training_type=training_type
)
take_course_form = CourseForm(training_type=training_type, auto_id="op_%s")
if Course.objects.filter(
training_type__required_field=RequiredField.PLATFORM,
is_active=True
).exists():
take_course_form = CourseForm(training_type=training_type, auto_id="op_%s")
else:
training_form = forms.TrainingForm(user=request.user)
take_course_form = CourseForm(auto_id="op_%s")
if Course.objects.filter(
training_type__required_field=RequiredField.PLATFORM,
is_active=True
).exists():
take_course_form = CourseForm(auto_id="op_%s")

expiring_trainings = Training.objects.filter(
user=request.user,
Expand Down

0 comments on commit ea93dd5

Please sign in to comment.