Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Jlc/add cms support for admin and course creator #2

Merged
merged 5 commits into from
Aug 22, 2022
Merged
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
4 changes: 4 additions & 0 deletions eox_nelp/admin/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
"""General admin module file.
Register all the nelp admin models.
"""
from eox_nelp.admin.course_creators import *
36 changes: 36 additions & 0 deletions eox_nelp/admin/course_creators.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
"""CourseCreators admin file.
Contains all the nelped admin models for course_creators.
classes:
NelpCourseCreatorAdmin: EoxNelp CourseCreators admin class.
"""

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):
"""Nelp CourseCreatorAdmin 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)
17 changes: 17 additions & 0 deletions eox_nelp/admin/register_admin_model.py
Original file line number Diff line number Diff line change
@@ -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)
27 changes: 20 additions & 7 deletions eox_nelp/apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from django.apps import AppConfig


class eoxNelpConfig(AppConfig):
class EoxNelpConfig(AppConfig):
"""
Nelp plugin for custom development. configuration.
"""
Expand All @@ -20,11 +20,6 @@ class eoxNelpConfig(AppConfig):
'regex': r'^eox-nelp/',
'relative_path': 'urls',
},
'cms.djangoapp': {
'namespace': 'eox-nelp',
'regex': r'^eox-nelp/',
'relative_path': 'urls',
}
},
'settings_config': {
'lms.djangoapp': {
Expand All @@ -33,9 +28,27 @@ class eoxNelpConfig(AppConfig):
'production': {'relative_path': 'settings.production'},
'devstack': {'relative_path': 'settings.devstack'},
},
}
}


class EoxNelpCMSConfig(AppConfig):
"""App configuration"""
name = 'eox_nelp'
verbose_name = "Nelp Openedx Extensions"

plugin_app = {
'url_config': {
'cms.djangoapp': {
'namespace': 'eox-nelp',
'regex': r'^eox-nelp/',
'relative_path': 'urls',
}
},
'settings_config': {
'cms.djangoapp': {
'common': {'relative_path': 'settings.common'},
'test': {'relative_path': 'settings.test'},
'common': {'relative_path': 'settings.common'},
'production': {'relative_path': 'settings.production'},
'devstack': {'relative_path': 'settings.devstack'},
},
Expand Down
23 changes: 23 additions & 0 deletions eox_nelp/edxapp_wrapper/backends/course_creators_k_v1.py
Original file line number Diff line number Diff line change
@@ -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
15 changes: 15 additions & 0 deletions eox_nelp/edxapp_wrapper/course_creators.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
"""Wrapper course_creator module file.
This contains all the required dependencies from course_creators.
Attributes:
backend:Imported 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()
51 changes: 5 additions & 46 deletions eox_nelp/settings/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,56 +16,15 @@
'django_countries',
)
EOX_AUDIT_MODEL_APP = 'eox_audit_model.apps.EoxAuditModelConfig'

COURSE_CREATOR_APP = 'cms.djangoapps.course_creators'

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_k_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)
if COURSE_CREATOR_APP not in settings.INSTALLED_APPS:
settings.INSTALLED_APPS.append(COURSE_CREATOR_APP)
2 changes: 0 additions & 2 deletions eox_nelp/settings/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
Settings for eox-nelp
"""

from __future__ import absolute_import, unicode_literals

from .common import * # pylint: disable=wildcard-import, unused-wildcard-import


Expand Down
2 changes: 0 additions & 2 deletions manage.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
Django administration utility.
"""

from __future__ import absolute_import, unicode_literals

import os
import sys

Expand Down
6 changes: 3 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,10 @@ def get_version(*file_paths):
zip_safe=False,
entry_points={
"lms.djangoapp": [
'eox_nelp = eox_nelp.apps:eoxNelpConfig',
'eox_nelp = eox_nelp.apps:EoxNelpConfig',
],
"cms.djangoapp": [
'eox_nelp = eox_nelp.apps:eoxNelpConfig',
],
'eox_nelp = eox_nelp.apps:EoxNelpCMSConfig',
],
},
)