From 1b8a9f25b91875709c0f440ec73e8d2ef0c98ee9 Mon Sep 17 00:00:00 2001 From: rutvikrj26 Date: Tue, 16 Jul 2024 13:07:30 -0400 Subject: [PATCH] Updated the expiring functionality to archiving --- .../console/training_type/course_details.html | 9 +++------ physionet-django/console/urls.py | 2 +- physionet-django/training/models.py | 4 +--- physionet-django/training/views.py | 19 ++++--------------- 4 files changed, 9 insertions(+), 25 deletions(-) diff --git a/physionet-django/console/templates/console/training_type/course_details.html b/physionet-django/console/templates/console/training_type/course_details.html index 6a85a3ef77..4781d89445 100644 --- a/physionet-django/console/templates/console/training_type/course_details.html +++ b/physionet-django/console/templates/console/training_type/course_details.html @@ -79,19 +79,16 @@

Active Versions

class="fa fa-download"> Download -
+ {% csrf_token %} - - +
{% endfor %} -

Note: Users that have taken the particular version of the course that is getting expired, - will need to retake the course or else they will loose credentialing after the - date specified above while expiring the course.

+

Note: Users can no longer take the course if there are no active versions available.

Archived Versions

diff --git a/physionet-django/console/urls.py b/physionet-django/console/urls.py index 59f93f1692..6cb3c7e167 100644 --- a/physionet-django/console/urls.py +++ b/physionet-django/console/urls.py @@ -166,7 +166,7 @@ path('courses//download/', training_views.download_course, name='download_course_version'), path('courses//expire/', - training_views.expire_course, name='expire_course_version'), + training_views.archive_course, name='archive_course_version'), ] # Parameters for testing URLs (see physionet/test_urls.py) diff --git a/physionet-django/training/models.py b/physionet-django/training/models.py index 4aeb059620..833e63cc09 100644 --- a/physionet-django/training/models.py +++ b/physionet-django/training/models.py @@ -36,14 +36,12 @@ class Meta: ("can_view_course_guidelines", "Can view course guidelines"), ] - def expire_course_version(self, number_of_days): + def archive_course_version(self): """ This method expires the course by setting the is_active field to False and expires all the trainings associated with it. """ self.is_active = False - # reset the valid_duration to the number of days - self.valid_duration = timezone.timedelta(days=number_of_days) self.save() def __str__(self): diff --git a/physionet-django/training/views.py b/physionet-django/training/views.py index ea956fa217..77183a0716 100644 --- a/physionet-django/training/views.py +++ b/physionet-django/training/views.py @@ -183,28 +183,17 @@ def course_details(request, training_slug): @permission_required('training.change_course', raise_exception=True) @console_permission_required('training.change_course') -def expire_course(request, training_slug, version): +def archive_course(request, training_slug, version): """ This view takes a primary key and a version number as input parameters, - and expires the course with the specified primary key and version number. + and archives the course with the specified primary key and version number. """ course = Course.objects.filter(training_type__slug=training_slug, version=version).first() - expiry_date = request.POST.get('expiry_date') if not course: messages.error(request, 'Course not found') return redirect('courses') - if not expiry_date: - messages.error(request, 'Expiry Date is required') - return redirect('course_details', training_slug) - # Checking if the expiry date is greater than the current date - expiry_date_tz = timezone.make_aware(timezone.datetime.strptime(expiry_date, '%Y-%m-%d')) - if expiry_date_tz < timezone.now(): - messages.error(request, 'Expiry Date should be greater than the current date') - return redirect('course_details', training_slug) - # Calculating the number of days between the current date and the expiry date - number_of_days = (expiry_date_tz - timezone.now()).days - course.expire_course_version(int(number_of_days)) - messages.success(request, 'Course expired successfully.') + course.archive_course_version() + messages.success(request, 'Course archoived successfully.') return redirect('course_details', training_slug)