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

feat: Add moodle channel integrations #18

Merged
merged 1 commit into from
Feb 21, 2025
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
5 changes: 5 additions & 0 deletions channel_integrations/moodle/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
"""
The Moodle Integrated Channel package.
"""

__version__ = "0.1.0"

Check warning on line 5 in channel_integrations/moodle/__init__.py

View check run for this annotation

Codecov / codecov/patch

channel_integrations/moodle/__init__.py#L5

Added line #L5 was not covered by tests
110 changes: 110 additions & 0 deletions channel_integrations/moodle/admin/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
"""
Django admin integration for configuring moodle app to communicate with Moodle systems.
"""

from django_object_actions import DjangoObjectActions

Check warning on line 5 in channel_integrations/moodle/admin/__init__.py

View check run for this annotation

Codecov / codecov/patch

channel_integrations/moodle/admin/__init__.py#L5

Added line #L5 was not covered by tests

from django import forms
from django.contrib import admin, messages
from django.core.exceptions import ValidationError
from django.http import HttpResponseRedirect
from django.utils.translation import gettext_lazy as _

Check warning on line 11 in channel_integrations/moodle/admin/__init__.py

View check run for this annotation

Codecov / codecov/patch

channel_integrations/moodle/admin/__init__.py#L7-L11

Added lines #L7 - L11 were not covered by tests

from channel_integrations.integrated_channel.admin import BaseLearnerDataTransmissionAuditAdmin
from channel_integrations.moodle.models import MoodleEnterpriseCustomerConfiguration, MoodleLearnerDataTransmissionAudit

Check warning on line 14 in channel_integrations/moodle/admin/__init__.py

View check run for this annotation

Codecov / codecov/patch

channel_integrations/moodle/admin/__init__.py#L13-L14

Added lines #L13 - L14 were not covered by tests


class MoodleEnterpriseCustomerConfigurationForm(forms.ModelForm):

Check warning on line 17 in channel_integrations/moodle/admin/__init__.py

View check run for this annotation

Codecov / codecov/patch

channel_integrations/moodle/admin/__init__.py#L17

Added line #L17 was not covered by tests
"""
Django admin form for MoodleEnterpriseCustomerConfiguration.
"""
class Meta:
model = MoodleEnterpriseCustomerConfiguration
fields = '__all__'

Check warning on line 23 in channel_integrations/moodle/admin/__init__.py

View check run for this annotation

Codecov / codecov/patch

channel_integrations/moodle/admin/__init__.py#L21-L23

Added lines #L21 - L23 were not covered by tests

def clean(self):
cleaned_data = super().clean()
cleaned_username = cleaned_data.get('decrypted_username')
cleaned_password = cleaned_data.get('decrypted_password')
cleaned_token = cleaned_data.get('decrypted_token')

Check warning on line 29 in channel_integrations/moodle/admin/__init__.py

View check run for this annotation

Codecov / codecov/patch

channel_integrations/moodle/admin/__init__.py#L25-L29

Added lines #L25 - L29 were not covered by tests
if cleaned_token and (cleaned_username or cleaned_password):
raise ValidationError(_('Cannot set both a Username/Password and Token'))

Check warning on line 31 in channel_integrations/moodle/admin/__init__.py

View check run for this annotation

Codecov / codecov/patch

channel_integrations/moodle/admin/__init__.py#L31

Added line #L31 was not covered by tests
if (cleaned_username and not cleaned_password) or (cleaned_password and not cleaned_username):
raise ValidationError(_('Must set both a Username and Password, not just one'))

Check warning on line 33 in channel_integrations/moodle/admin/__init__.py

View check run for this annotation

Codecov / codecov/patch

channel_integrations/moodle/admin/__init__.py#L33

Added line #L33 was not covered by tests


@admin.register(MoodleEnterpriseCustomerConfiguration)
class MoodleEnterpriseCustomerConfigurationAdmin(DjangoObjectActions, admin.ModelAdmin):

Check warning on line 37 in channel_integrations/moodle/admin/__init__.py

View check run for this annotation

Codecov / codecov/patch

channel_integrations/moodle/admin/__init__.py#L36-L37

Added lines #L36 - L37 were not covered by tests
"""
Django admin model for MoodleEnterpriseCustomerConfiguration.
"""

raw_id_fields = (

Check warning on line 42 in channel_integrations/moodle/admin/__init__.py

View check run for this annotation

Codecov / codecov/patch

channel_integrations/moodle/admin/__init__.py#L42

Added line #L42 was not covered by tests
'enterprise_customer',
)

form = MoodleEnterpriseCustomerConfigurationForm
change_actions = ('force_content_metadata_transmission',)

Check warning on line 47 in channel_integrations/moodle/admin/__init__.py

View check run for this annotation

Codecov / codecov/patch

channel_integrations/moodle/admin/__init__.py#L46-L47

Added lines #L46 - L47 were not covered by tests

@admin.action(

Check warning on line 49 in channel_integrations/moodle/admin/__init__.py

View check run for this annotation

Codecov / codecov/patch

channel_integrations/moodle/admin/__init__.py#L49

Added line #L49 was not covered by tests
description="Force content metadata transmission for this Enterprise Customer"
)
def force_content_metadata_transmission(self, request, obj):

Check warning on line 52 in channel_integrations/moodle/admin/__init__.py

View check run for this annotation

Codecov / codecov/patch

channel_integrations/moodle/admin/__init__.py#L52

Added line #L52 was not covered by tests
"""
Updates the modified time of the customer record to retransmit courses metadata
and redirects to configuration view with success or error message.
"""
try:
obj.enterprise_customer.save()
messages.success(

Check warning on line 59 in channel_integrations/moodle/admin/__init__.py

View check run for this annotation

Codecov / codecov/patch

channel_integrations/moodle/admin/__init__.py#L57-L59

Added lines #L57 - L59 were not covered by tests
request,
f'''The moodle enterprise customer content metadata
“<MoodleEnterpriseCustomerConfiguration for Enterprise
{obj.enterprise_customer.name}>” was updated successfully.''',
)
except ValidationError:
messages.error(

Check warning on line 66 in channel_integrations/moodle/admin/__init__.py

View check run for this annotation

Codecov / codecov/patch

channel_integrations/moodle/admin/__init__.py#L65-L66

Added lines #L65 - L66 were not covered by tests
request,
f'''The moodle enterprise customer content metadata
“<MoodleEnterpriseCustomerConfiguration for Enterprise
{obj.enterprise_customer.name}>” was not updated successfully.''',
)
return HttpResponseRedirect(

Check warning on line 72 in channel_integrations/moodle/admin/__init__.py

View check run for this annotation

Codecov / codecov/patch

channel_integrations/moodle/admin/__init__.py#L72

Added line #L72 was not covered by tests
"/admin/moodle/moodleenterprisecustomerconfiguration"
)
force_content_metadata_transmission.label = "Force content metadata transmission"

Check warning on line 75 in channel_integrations/moodle/admin/__init__.py

View check run for this annotation

Codecov / codecov/patch

channel_integrations/moodle/admin/__init__.py#L75

Added line #L75 was not covered by tests


@admin.register(MoodleLearnerDataTransmissionAudit)
class MoodleLearnerDataTransmissionAuditAdmin(BaseLearnerDataTransmissionAuditAdmin):

Check warning on line 79 in channel_integrations/moodle/admin/__init__.py

View check run for this annotation

Codecov / codecov/patch

channel_integrations/moodle/admin/__init__.py#L78-L79

Added lines #L78 - L79 were not covered by tests
"""
Django admin model for MoodleLearnerDataTransmissionAudit.
"""
list_display = (

Check warning on line 83 in channel_integrations/moodle/admin/__init__.py

View check run for this annotation

Codecov / codecov/patch

channel_integrations/moodle/admin/__init__.py#L83

Added line #L83 was not covered by tests
"enterprise_course_enrollment_id",
"course_id",
"status",
"modified",
)

readonly_fields = (

Check warning on line 90 in channel_integrations/moodle/admin/__init__.py

View check run for this annotation

Codecov / codecov/patch

channel_integrations/moodle/admin/__init__.py#L90

Added line #L90 was not covered by tests
"moodle_user_email",
"progress_status",
"content_title",
"enterprise_customer_name",
"friendly_status_message",
"api_record",
)

search_fields = (

Check warning on line 99 in channel_integrations/moodle/admin/__init__.py

View check run for this annotation

Codecov / codecov/patch

channel_integrations/moodle/admin/__init__.py#L99

Added line #L99 was not covered by tests
"moodle_user_email",
"enterprise_course_enrollment_id",
"course_id",
"content_title",
"friendly_status_message"
)

list_per_page = 1000

Check warning on line 107 in channel_integrations/moodle/admin/__init__.py

View check run for this annotation

Codecov / codecov/patch

channel_integrations/moodle/admin/__init__.py#L107

Added line #L107 was not covered by tests

class Meta:
model = MoodleLearnerDataTransmissionAudit

Check warning on line 110 in channel_integrations/moodle/admin/__init__.py

View check run for this annotation

Codecov / codecov/patch

channel_integrations/moodle/admin/__init__.py#L109-L110

Added lines #L109 - L110 were not covered by tests
14 changes: 14 additions & 0 deletions channel_integrations/moodle/apps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
"""
Enterprise Integrated Channel Moodle Django application initialization.
"""

from django.apps import AppConfig

Check warning on line 5 in channel_integrations/moodle/apps.py

View check run for this annotation

Codecov / codecov/patch

channel_integrations/moodle/apps.py#L5

Added line #L5 was not covered by tests


class MoodleConfig(AppConfig):

Check warning on line 8 in channel_integrations/moodle/apps.py

View check run for this annotation

Codecov / codecov/patch

channel_integrations/moodle/apps.py#L8

Added line #L8 was not covered by tests
"""
Configuration for the Enterprise Integrated Channel Moodle Django application.
"""
name = 'channel_integrations.moodle'
verbose_name = 'Enterprise Moodle Integration'
label = 'moodle_channel'

Check warning on line 14 in channel_integrations/moodle/apps.py

View check run for this annotation

Codecov / codecov/patch

channel_integrations/moodle/apps.py#L12-L14

Added lines #L12 - L14 were not covered by tests
Loading
Loading