-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add new admin action that allows to create external certificates
- Loading branch information
1 parent
fd90b14
commit 6ccaa10
Showing
7 changed files
with
115 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
"""General admin module file. | ||
Register all the nelp admin models. | ||
""" | ||
from eox_nelp.admin.certificates import * # noqa: F401 | ||
from eox_nelp.admin.course_creators import * # noqa: F401 | ||
from eox_nelp.course_experience.admin import * # noqa: F401 | ||
from eox_nelp.notifications.admin import * # noqa: F401 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
"""Certificates admin file. | ||
Contains all the nelp admin models for certificates. | ||
Classes: | ||
NelpGeneratedCertificateAdmin: EoxNelp Certificates admin class. | ||
Functions: | ||
create_external_certificate_action: Allow to create external certificates. | ||
""" | ||
from django.contrib import admin | ||
from django.utils import timezone | ||
from eox_core.edxapp_wrapper.certificates import get_generated_certificate | ||
from openedx_events.learning.data import CertificateData, CourseData, UserData, UserPersonalData | ||
|
||
from eox_nelp.admin.register_admin_model import register_admin_model as register | ||
from eox_nelp.edxapp_wrapper.certificates import GeneratedCertificateAdmin | ||
from eox_nelp.signals.tasks import create_external_certificate | ||
from eox_nelp.signals.utils import _generate_external_certificate_data | ||
|
||
GeneratedCertificate = get_generated_certificate() | ||
|
||
|
||
@admin.action(description="Create external certificates") | ||
def create_external_certificate_action(modeladmin, request, queryset): # pylint: disable=unused-argument | ||
""" | ||
This creates CertificateData and runs the create_external_certificate task for every record | ||
in the queryset, to allow to create certificates in the external NELP service. | ||
Args: | ||
modeladmin: Instance of NelpGeneratedCertificateAdmin | ||
request: Current django request. | ||
queryset: Selected records. | ||
""" | ||
|
||
for certificate in queryset: | ||
certificate_data = CertificateData( | ||
user=UserData( | ||
pii=UserPersonalData( | ||
username=certificate.user.username, | ||
email=certificate.user.email, | ||
name=certificate.user.profile.name, | ||
), | ||
id=certificate.user.id, | ||
is_active=certificate.user.is_active, | ||
), | ||
course=CourseData( | ||
course_key=certificate.course_id, | ||
), | ||
mode=certificate.mode, | ||
grade=certificate.grade, | ||
current_status=certificate.status, | ||
download_url=certificate.download_url, | ||
name=certificate.name, | ||
) | ||
time = certificate.modified_date.astimezone(timezone.utc) | ||
|
||
create_external_certificate.delay( | ||
external_certificate_data=_generate_external_certificate_data( | ||
time=time, | ||
certificate_data=certificate_data, | ||
) | ||
) | ||
|
||
|
||
class NelpGeneratedCertificateAdmin(GeneratedCertificateAdmin): | ||
""" | ||
Nelp GeneratedCertificate admin class, this adds the NELP admin custom | ||
behavior, for the GeneratedCertificate model. | ||
""" | ||
actions = [create_external_certificate_action] | ||
|
||
|
||
register(GeneratedCertificate, NelpGeneratedCertificateAdmin) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
"""Backend for certificates module. | ||
This file contains all the necessary certificates dependencies from | ||
https://github.com/eduNEXT/edunext-platform/tree/master/lms/djangoapps/certificates | ||
""" | ||
from lms.djangoapps.certificates import admin # pylint: disable=import-error | ||
|
||
|
||
def get_generated_certificates_admin(): | ||
"""Allow to get the openedX GeneratedCertificateAdmin class. | ||
https://github.com/eduNEXT/edunext-platform/tree/master/lms/djangoapps/certificates/admin.py | ||
Returns: | ||
GeneratedCertificateAdmin class. | ||
""" | ||
return admin.GeneratedCertificateAdmin |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
"""Wrapper certificates module file. | ||
This contains all the required dependencies from certificates. | ||
Attributes: | ||
backend:Imported module by using the plugin settings. | ||
GeneratedCertificateAdmin: Wrapper GeneratedCertificateAdmin class. | ||
""" | ||
from importlib import import_module | ||
|
||
from django.conf import settings | ||
|
||
backend = import_module(settings.EOX_NELP_CERTIFICATES_BACKEND) | ||
|
||
GeneratedCertificateAdmin = backend.get_generated_certificates_admin() |
10 changes: 10 additions & 0 deletions
10
eox_nelp/edxapp_wrapper/test_backends/certificates_m_v1.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
"""Test backend for certificates module.""" | ||
from mock import Mock | ||
|
||
|
||
def get_generated_certificates_admin(): | ||
"""Return test admin class. | ||
Returns: | ||
Mock class. | ||
""" | ||
return Mock() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters