Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions events/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,15 @@
url(r'^training/view/training-completion/(?P<rid>\d+)/$', view_training_completion, name="view_training_completion"),

#url(r'^test/subscribe/(\d+)/(\d+)/$', test_student_subscribe', name='test_student_subscribe'),


url(
r'^test/(?P<test_id>\d+)/participants/download/$',
download_test_participants_csv,
name='download_test_participants_csv'
),


url(r'^test/(\d+)/participant/$', test_participant, name='test_participant'),
url(r'^test/participant/certificate/(\d+)/(\d+)/$', test_participant_ceritificate, name='test_participant_ceritificate'),
url(r'^test/participant/certificate/all/(\d+)/$', test_participant_ceritificate_all, name='test_participant_ceritificate_all'),
Expand Down
34 changes: 34 additions & 0 deletions events/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -2307,6 +2307,40 @@ def test_participant(request, tid=None):
# can_download_certificate = 1
context = {'collection' : test_mdlusers, 'test' : t, 'can_download_certificate':can_download_certificate}
return render(request, 'events/templates/test/test_participant.html', context)

@login_required
def download_test_participants_csv(request, test_id):
user = request.user
try:
test = Test.objects.get(id=test_id)
except Test.DoesNotExist:
raise PermissionDenied()
if not (user == test.organiser.user or user == test.invigilator.user or user.groups.filter( name__in=["Event Manager", "Resource Person"] ).exists()):
raise PermissionDenied()

if test.status == 4:
participants = TestAttendance.objects.filter(test_id=test.id,status__gte=2)
else:
participants = TestAttendance.objects.filter(test_id=test.id)
participants = participants.order_by('id')
response = HttpResponse(content_type='text/csv')
response['Content-Disposition'] = ('attachment; filename="{}_participants.csv"'.format(test.foss.foss))

writer = csv.writer(response)
writer.writerow(['First Name','Last Name','Email ID','Score (%)'])

for ta in participants:
firstname = ta.mdluser_firstname or ''
lastname = ta.mdluser_lastname or ''
mdluser = MdlUser.objects.filter(id=ta.mdluser_id).first()
email = mdluser.email if mdluser and mdluser.email else ''
grade = MdlQuizGrades.objects.filter(quiz=ta.mdlquiz_id,userid=ta.mdluser_id).first()
score = round(grade.grade, 2) if grade else 'NA'
writer.writerow([firstname,lastname,email,score])

return response



def test_participant_ceritificate(request, wid, participant_id):
#response = HttpResponse(content_type='application/pdf')
Expand Down
6 changes: 6 additions & 0 deletions static/events/templates/test/test_participant.html
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,12 @@
</div>
<div class="" id="pending">
{% if collection %}
<a
style="float:right; padding-right:20px;"
href="{% url 'events:download_test_participants_csv' test.id %}">
Download Participants Data (CSV)
</a>

<a style="float: right; padding-right: 9%;" href="{% url 'events:test_participant_ceritificate_all' test.id %}">Download all certificates</a>
<table class="table table-striped table-hover table-bordered">
<tr>
Expand Down