diff --git a/eox_nelp/admin/__init__.py b/eox_nelp/admin/__init__.py new file mode 100644 index 00000000..cc605756 --- /dev/null +++ b/eox_nelp/admin/__init__.py @@ -0,0 +1,4 @@ +"""General admin module file. +Register all the nelp admin models. +""" +from eox_nelp.admin.course_creators import * diff --git a/eox_nelp/admin/course_creators.py b/eox_nelp/admin/course_creators.py new file mode 100644 index 00000000..e2bf6ea4 --- /dev/null +++ b/eox_nelp/admin/course_creators.py @@ -0,0 +1,36 @@ +"""courseCreators admin file. +Contains all the nelped admin models for course_creators. +classes: + nelpCourseCreatorAdmin: EoxNelp CourseCreators admin class. +""" +from __future__ import absolute_import + +from django.contrib import admin + +from eox_nelp.admin.register_admin_model import register_admin_model as register +from eox_nelp.edxapp_wrapper.course_creators import ( + CourseCreator, + CourseCreatorAdmin, +) + + +class NelpCourseCreatorAdmin(CourseCreatorAdmin): + """EoxSupport CertificateTemplate admin class. + This adds searching fields and shows the organization name instead of the organization id. + """ + readonly_fields = ['state_changed'] + # Controls the order on the edit form (without this, read-only fields appear at the end). + fieldsets = () + add_fieldsets = ( + (None, { + 'fields': ['username', 'state', 'state_changed', 'note', 'all_organizations', 'organizations'] + }), + ) + + def has_add_permission(self, request): + return True + def has_delete_permission(self, request, obj=None): + return True + + +register(CourseCreator, NelpCourseCreatorAdmin) diff --git a/eox_nelp/admin/register_admin_model.py b/eox_nelp/admin/register_admin_model.py new file mode 100644 index 00000000..b23e2e45 --- /dev/null +++ b/eox_nelp/admin/register_admin_model.py @@ -0,0 +1,17 @@ +"""General method to register admin models. +methods: + register_admin_model: Force register admin model. +""" +from django.contrib import admin + + +def register_admin_model(model, admin_model): + """Associate a model with the given admin model. + Args: + model: Django model. + admin_class: Admin model. + """ + if admin.site.is_registered(model): + admin.site.unregister(model) + + admin.site.register(model, admin_model) diff --git a/eox_nelp/edxapp_wrapper/backends/course_creators_l_v1.py b/eox_nelp/edxapp_wrapper/backends/course_creators_l_v1.py new file mode 100644 index 00000000..78de726a --- /dev/null +++ b/eox_nelp/edxapp_wrapper/backends/course_creators_l_v1.py @@ -0,0 +1,23 @@ +"""Backend for course_creators module. +This file contains all the necessary course_creators dependencies from +https://github.com/eduNEXT/edunext-platform/tree/master/cms/djangoapps/course_creators +""" +from cms.djangoapps.course_creators import admin, models # pylint: disable=import-error + + +def get_course_creator_model(): + """Allow to get the model CourseCreator from + https://github.com/eduNEXT/edunext-platform/tree/master/cms/djangoapps/course_creators/models.py + Returns: + CourseCreator model. + """ + return models.CourseCreator + + +def get_course_creator_admin(): + """Allow to get the openedX CourseCreatorAdmin class. + https://github.com/eduNEXT/edunext-platform/tree/master/cms/djangoapps/course_creators/admin.py + Returns: + CourseCreatorAdmin class. + """ + return admin.CourseCreatorAdmin diff --git a/eox_nelp/edxapp_wrapper/course_creators.py b/eox_nelp/edxapp_wrapper/course_creators.py new file mode 100644 index 00000000..7b00d579 --- /dev/null +++ b/eox_nelp/edxapp_wrapper/course_creators.py @@ -0,0 +1,15 @@ +"""Wrapper course_creator module file. +This contains all the required dependencies from course_creators. +Attributes: + backend:Imported ccx module by using the plugin settings. + CourseCreator: Wrapper courseCreator model. + CourseCreatorAdmin: Wrapper CourseCreatorAdmin class. +""" +from importlib import import_module + +from django.conf import settings + +backend = import_module(settings.EOX_NELP_COURSE_CREATORS_BACKEND) + +CourseCreator = backend.get_course_creator_model() +CourseCreatorAdmin = backend.get_course_creator_admin() diff --git a/eox_nelp/settings/common.py b/eox_nelp/settings/common.py index e8794e3b..6d970388 100644 --- a/eox_nelp/settings/common.py +++ b/eox_nelp/settings/common.py @@ -20,52 +20,9 @@ def plugin_settings(settings): """ - Defines eox-core settings when app is used as a plugin to edx-platform. + Defines eox-nelp settings when app is used as a plugin to edx-platform. See: https://github.com/edx/edx-platform/blob/master/openedx/core/djangoapps/plugins/README.rst """ - - settings.eox_nelp_ENABLE_STATICFILES_STORAGE = False - settings.eox_nelp_STATICFILES_STORAGE = "eox_nelp.storage.ProductionStorage" - settings.eox_nelp_LOAD_PERMISSIONS = True - settings.DATA_API_DEF_PAGE_SIZE = 1000 - settings.DATA_API_MAX_PAGE_SIZE = 5000 - - settings.eox_nelp_COURSE_MANAGEMENT_REQUEST_TIMEOUT = 1000 - settings.eox_nelp_USER_ENABLE_MULTI_TENANCY = True - settings.eox_nelp_USER_ORIGIN_SITE_SOURCES = ['fetch_from_unfiltered_table', ] - settings.eox_nelp_APPEND_LMS_MIDDLEWARE_CLASSES = False - settings.eox_nelp_ENABLE_UPDATE_USERS = True - settings.eox_nelp_USER_UPDATE_SAFE_FIELDS = ["is_active", "password", "fullname", "mailing_address", "year_of_birth", "gender", "level_of_education", "city", "country", "goals", "bio", "phone_number"] - settings.eox_nelp_BEARER_AUTHENTICATION = 'eox_nelp.edxapp_wrapper.backends.bearer_authentication_j_v1' - settings.eox_nelp_ASYNC_TASKS = [] - settings.eox_nelp_THIRD_PARTY_AUTH_BACKEND = 'eox_nelp.edxapp_wrapper.backends.third_party_auth_l_v1' - - if settings.eox_nelp_USER_ENABLE_MULTI_TENANCY: - settings.eox_nelp_USER_ORIGIN_SITE_SOURCES = [ - 'fetch_from_created_on_site_prop', - 'fetch_from_user_signup_source', - ] - - # Sentry Integration - settings.eox_nelp_SENTRY_INTEGRATION_DSN = None - - # The setting eox_nelp_SENTRY_IGNORED_ERRORS is a list of rules that defines which exceptions to ignore. - # An example below: - # eox_nelp_SENTRY_IGNORED_ERRORS = [ - # { - # "exc_class": "openedx.core.djangoapps.user_authn.exceptions.AuthFailedError", - # "exc_text": ["AuthFailedError.*Email or password is incorrect"] - # }, - # ] - # Every rule support only 2 keys for now: - # - exc_class: the path to the exception class we want to ignore. It can only be one - # - exc_text: a list of regex expressions to search on the last traceback frame text of the exception - - # In this example we have only one rule. We are ignoring AuthFailedError exceptions whose traceback text - # has a match with the regex provided in the exc_text unique element. If exc_text contains more than one - # regex, the exception is ignored if any of the regex matches the traceback text. - settings.eox_nelp_SENTRY_IGNORED_ERRORS = [] - settings.eox_nelp_SENTRY_ENVIRONMENT = None - + settings.EOX_NELP_COURSE_CREATORS_BACKEND = 'eox_nelp.edxapp_wrapper.backends.course_creators_l_v1' if find_spec('eox_audit_model') and EOX_AUDIT_MODEL_APP not in settings.INSTALLED_APPS: settings.INSTALLED_APPS.append(EOX_AUDIT_MODEL_APP)