How can I generated graded certificates?

I would like to allow students to generate their own certificates such that the certificate also includes their grade.

How can I do this?

Is one way to achieve this by amending webview.ppy

This file is already importing in the certficates api - so how can I just pull the grade?

1 Like

Maybe I can ask the question in a different way -
How can I just print the numerical grade i.e. the % on the certificate?

Problem update:

I tried adding the following to webviews.py

from courseware.models import StudentModule

Then I added below: " # Translators: The format of the date includes the full name of the month"

    all_fields = StudentModule._meta.get_field('grade')
    print(all_fields)
    context['allfields'] = all_fields

HTML ammendments to lms/templates/certificates/_accomplishment-rendering.html

I pasted this under (line 8(
<p>${allfields}</p>

The following error keeps occuring when I try to preview the certificate:
Nov 20 10:14:05 ip-172-31-21-194 [service_variant=lms][util.views][env:sandbox] ERROR [ip-172-31-21-194 2670] [views.py:154] - Error in django view.
Traceback (most recent call last):
File “/edx/app/edxapp/edx-platform/common/djangoapps/util/views.py”, line 145, in inner
return func(request, *args, **kwargs)
File “/edx/app/edxapp/edx-platform/lms/djangoapps/certificates/views/webview.py”, line 614, in render_html_view

  File "/edx/app/edxapp/edx-platform/lms/djangoapps/certificates/views/webview.py", line 680, in _render_valid_certificate
    def _render_valid_certificate(request, context, custom_template=None):
  File "/edx/app/edxapp/edx-platform/common/djangoapps/edxmako/shortcuts.py", line 169, in render_to_response
    return HttpResponse(render_to_string(template_name, dictionary, namespace, request), **kwargs)
  File "/edx/app/edxapp/edx-platform/common/djangoapps/edxmako/shortcuts.py", line 159, in render_to_string
    return template.render(dictionary, request)
  File "/edx/app/edxapp/edx-platform/common/djangoapps/edxmako/template.py", line 59, in render
    return self.mako_template.render_unicode(**context_dictionary)
  File "/edx/app/edxapp/venvs/edxapp/local/lib/python2.7/site-packages/mako/template.py", line 454, in render_unicode
    as_unicode=True)
  File "/edx/app/edxapp/venvs/edxapp/local/lib/python2.7/site-packages/mako/runtime.py", line 829, in _render
    **_kwargs_for_callable(callable_, data))
  File "/edx/app/edxapp/venvs/edxapp/local/lib/python2.7/site-packages/mako/runtime.py", line 864, in _render_context
    _exec_template(inherit, lclcontext, args=args, kwargs=kwargs)
  File "/edx/app/edxapp/venvs/edxapp/local/lib/python2.7/site-packages/mako/runtime.py", line 890, in _exec_template
    callable_(context, *args, **kwargs)
  File "/tmp/mako_lms/e925696d8b14fbe9ce4148f457a131c3/custom-theme/lms/templates/certificates/accomplishment-base.html.py", line 77, in render_body
    __M_writer(filters.html_escape(filters.decode.utf8(self.body())))
  File "/tmp/mako_lms/e925696d8b14fbe9ce4148f457a131c3/custom-theme/lms/templates/certificates/valid.html.py", line 45, in render_body
    runtime._include_file(context, u'_accomplishment-rendering.html', _template_uri)
  File "/edx/app/edxapp/venvs/edxapp/local/lib/python2.7/site-packages/mako/runtime.py", line 752, in _include_file
    callable_(ctx, **_kwargs_for_include(callable_, context._data, **kwargs))
  File "/tmp/mako_lms/e925696d8b14fbe9ce4148f457a131c3/custom-theme/lms/templates/certificates/_accomplishment-rendering.html.py", line 63, in render_body
    __M_writer(filters.html_escape(filters.decode.utf8(allfields)))
  File "/edx/app/edxapp/venvs/edxapp/local/lib/python2.7/site-packages/mako/filters.py", line 78, in decode
    return decode(str(x))
  File "/edx/app/edxapp/venvs/edxapp/local/lib/python2.7/site-packages/mako/runtime.py", line 226, in __str__
    raise NameError("Undefined")
NameError: Undefined

Any idea on how i can solve this?

Ok I have come up with a solution to this - it is far from an elegant solution - but it does work.

STEP 1

Paste the code below into the function “def _update_social_context” [line 260] which is located in the file
/edx/app/edxapp/edx-platform/lms/djangoapps/certificates/views/webview.py

course_target=unicode(str(course.id),"utf-8")
targetuser=user.username 

user_info=get_certificates_for_user(targetuser)

for i in range(len(user_info)):
   if (str(user_info[i]['course_key'])==course_target):
           target_row=i

context['studentgradeearned']=user_info[target_row]['grade']  

STEP 2
Paste this html command below into the file titled “_accomplishment-rendering.html” which is located in:
/edx/app/edxapp/edx-platform/themes/yourtheme/yourcustomtheme/lms/templates/certificates

<span class="accomplishment-summary copy copy-lead">exam mark: ${"{0:.0f}%".format(float(studentgradeearned)*100)}</span>

It might “break” the certificate in preview mode when in studio but it will render a certificate on the student side with the grade (as I said it isn’t an elegant solution)

Hope it helps

2 Likes