Skip to content

Commit

Permalink
Updated the expiring functionality to archiving
Browse files Browse the repository at this point in the history
  • Loading branch information
Rutvikrj26 committed Jul 16, 2024
1 parent 8460138 commit 1b8a9f2
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -79,19 +79,16 @@ <h3 class="card-title text-center">Active Versions</h3>
class="fa fa-download"></i> Download</a>
</td>
<td>
<form action="{% url 'expire_course_version' training_type.slug course.version %}" method="POST">
<form action="{% url 'archive_course_version' training_type.slug course.version %}" method="POST">
{% csrf_token %}
<input type="date" name="expiry_date">
<button class="btn btn-sm btn-danger" type="submit"> Expire</button>
<button class="btn btn-sm btn-danger" type="submit"> Archive</button>
</form>
</td>
</tr>
{% endfor %}
</tbody>
</table>
<p><b>Note:</b> 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. </p>
<p><b>Note:</b> Users can no longer take the course if there are no active versions available.</p>
</div>
<h3 class="card-title text-center">Archived Versions</h3>
<div class="card-body">
Expand Down
2 changes: 1 addition & 1 deletion physionet-django/console/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@
path('courses/<training_slug>/download/<str:version>',
training_views.download_course, name='download_course_version'),
path('courses/<training_slug>/expire/<str:version>',
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)
Expand Down
4 changes: 1 addition & 3 deletions physionet-django/training/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
19 changes: 4 additions & 15 deletions physionet-django/training/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)


Expand Down

0 comments on commit 1b8a9f2

Please sign in to comment.