refactor: Moved ProgramDiscussion/Live Configuration Models to program's app (#29871)

refactor: Moved ProgramDiscussion/Live Configuration Models to program's app
This commit is contained in:
Ahtisham Shahid
2022-02-09 15:43:22 +05:00
committed by GitHub
parent 93d8a123d3
commit 75d8448ef5
9 changed files with 249 additions and 109 deletions

View File

@@ -7,8 +7,7 @@ from simple_history.admin import SimpleHistoryAdmin
from openedx.core.djangoapps.config_model_utils.admin import StackedConfigModelAdmin
from .forms import ProgramDiscussionsConfigurationForm, ProgramLiveConfigurationForm
from .models import DiscussionsConfiguration, ProgramDiscussionsConfiguration, ProgramLiveConfiguration
from .models import DiscussionsConfiguration
from .models import ProviderFilter
@@ -28,30 +27,6 @@ class DiscussionsConfigurationAdmin(SimpleHistoryAdmin):
)
class ProgramDiscussionsConfigurationAdmin(SimpleHistoryAdmin):
"""
Customize the admin interface for the program discussions configuration
"""
form = ProgramDiscussionsConfigurationForm
fieldsets = (
(None, {
'fields': ('program_uuid', 'enabled', 'lti_configuration', 'pii_share_username', 'pii_share_email',
'provider_type'),
}),
)
search_fields = (
'program_uuid',
'enabled',
'provider_type',
)
list_filter = (
'enabled',
'provider_type',
)
class AllowListFilter(SimpleListFilter):
"""
Customize the admin interface for the AllowList
@@ -111,32 +86,5 @@ class ProviderFilterAdmin(StackedConfigModelAdmin):
DenyListFilter,
)
class ProgramLiveConfigurationAdmin(SimpleHistoryAdmin):
"""
Customize the admin interface for the program live configuration
"""
form = ProgramLiveConfigurationForm
fieldsets = (
(None, {
'fields': ('program_uuid', 'enabled', 'lti_configuration', 'pii_share_username', 'pii_share_email',
'provider_type'),
}),
)
search_fields = (
'program_uuid',
'enabled',
'provider_type',
)
list_filter = (
'enabled',
'provider_type',
)
admin.site.register(DiscussionsConfiguration, DiscussionsConfigurationAdmin)
admin.site.register(ProgramDiscussionsConfiguration, ProgramDiscussionsConfigurationAdmin)
admin.site.register(ProgramLiveConfiguration, ProgramLiveConfigurationAdmin)
admin.site.register(ProviderFilter, ProviderFilterAdmin)

View File

@@ -0,0 +1,41 @@
# Generated by Django 3.2.11 on 2022-02-03 21:34
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
('discussions', '0009_discussiontopiclink_ordering'),
]
operations = [
migrations.RemoveField(
model_name='historicalprogramliveconfiguration',
name='history_user',
),
migrations.RemoveField(
model_name='historicalprogramliveconfiguration',
name='lti_configuration',
),
migrations.RemoveField(
model_name='programdiscussionsconfiguration',
name='lti_configuration',
),
migrations.RemoveField(
model_name='programliveconfiguration',
name='lti_configuration',
),
migrations.DeleteModel(
name='HistoricalProgramDiscussionsConfiguration',
),
migrations.DeleteModel(
name='HistoricalProgramLiveConfiguration',
),
migrations.DeleteModel(
name='ProgramDiscussionsConfiguration',
),
migrations.DeleteModel(
name='ProgramLiveConfiguration',
),
]

View File

@@ -522,50 +522,6 @@ class DiscussionsConfiguration(TimeStampedModel):
)
class AbstractProgramLTIConfiguration(TimeStampedModel):
"""
Associates a program with a LTI provider and configuration
"""
class Meta:
abstract = True
program_uuid = models.CharField(
primary_key=True,
db_index=True,
max_length=50,
verbose_name=_("Program UUID"),
)
enabled = models.BooleanField(
default=True,
help_text=_("If disabled, the LTI in the associated program will be disabled.")
)
lti_configuration = models.ForeignKey(
LtiConfiguration,
on_delete=models.SET_NULL,
blank=True,
null=True,
help_text=_("The LTI configuration data for this program/provider."),
)
provider_type = models.CharField(
blank=False,
max_length=50,
verbose_name=_("LTI provider"),
help_text=_("The LTI provider's id"),
)
def __str__(self):
return f"Configuration(uuid='{self.program_uuid}', provider='{self.provider_type}', enabled={self.enabled})"
@classmethod
def get(cls, program_uuid):
"""
Lookup a program discussion configuration by program uuid.
"""
return cls.objects.filter(
program_uuid=program_uuid
).first()
class DiscussionTopicLink(models.Model):
"""
A model linking discussion topics ids to the part of a course they are linked to.
@@ -623,11 +579,3 @@ class DiscussionTopicLink(models.Model):
f'enabled_in_context={self.enabled_in_context}'
f')'
)
class ProgramLiveConfiguration(AbstractProgramLTIConfiguration):
history = HistoricalRecords()
class ProgramDiscussionsConfiguration(AbstractProgramLTIConfiguration):
history = HistoricalRecords()

View File

@@ -5,12 +5,65 @@ django admin pages for program support models
from config_models.admin import ConfigurationModelAdmin
from django.contrib import admin
from simple_history.admin import SimpleHistoryAdmin
from openedx.core.djangoapps.programs.models import ProgramsApiConfig
from openedx.core.djangoapps.programs.forms import ProgramDiscussionsConfigurationForm, ProgramLiveConfigurationForm
from openedx.core.djangoapps.programs.models import ProgramsApiConfig, ProgramDiscussionsConfiguration, \
ProgramLiveConfiguration
class ProgramsApiConfigAdmin(ConfigurationModelAdmin):
pass
class ProgramDiscussionsConfigurationAdmin(SimpleHistoryAdmin):
"""
Customize the admin interface for the program discussions configuration
"""
form = ProgramDiscussionsConfigurationForm
fieldsets = (
(None, {
'fields': ('program_uuid', 'enabled', 'lti_configuration', 'pii_share_username', 'pii_share_email',
'provider_type'),
}),
)
search_fields = (
'program_uuid',
'enabled',
'provider_type',
)
list_filter = (
'enabled',
'provider_type',
)
class ProgramLiveConfigurationAdmin(SimpleHistoryAdmin):
"""
Customize the admin interface for the program live configuration
"""
form = ProgramLiveConfigurationForm
fieldsets = (
(None, {
'fields': ('program_uuid', 'enabled', 'lti_configuration', 'pii_share_username', 'pii_share_email',
'provider_type'),
}),
)
search_fields = (
'program_uuid',
'enabled',
'provider_type',
)
list_filter = (
'enabled',
'provider_type',
)
admin.site.register(ProgramsApiConfig, ProgramsApiConfigAdmin)
admin.site.register(ProgramDiscussionsConfiguration, ProgramDiscussionsConfigurationAdmin)
admin.site.register(ProgramLiveConfiguration, ProgramLiveConfigurationAdmin)

View File

@@ -0,0 +1,92 @@
# Generated by Django 3.2.11 on 2022-02-03 21:34
from django.conf import settings
from django.db import migrations, models
import django.db.models.deletion
import django.utils.timezone
import model_utils.fields
import simple_history.models
class Migration(migrations.Migration):
dependencies = [
('lti_consumer', '0013_auto_20210712_1352'),
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
('programs', '0014_delete_customprogramsconfig'),
]
operations = [
migrations.CreateModel(
name='ProgramLiveConfiguration',
fields=[
('created', model_utils.fields.AutoCreatedField(default=django.utils.timezone.now, editable=False, verbose_name='created')),
('modified', model_utils.fields.AutoLastModifiedField(default=django.utils.timezone.now, editable=False, verbose_name='modified')),
('program_uuid', models.CharField(db_index=True, max_length=50, primary_key=True, serialize=False, verbose_name='Program UUID')),
('enabled', models.BooleanField(default=True, help_text='If disabled, the LTI in the associated program will be disabled.')),
('provider_type', models.CharField(help_text="The LTI provider's id", max_length=50, verbose_name='LTI provider')),
('lti_configuration', models.ForeignKey(blank=True, help_text='The LTI configuration data for this program/provider.', null=True, on_delete=django.db.models.deletion.SET_NULL, to='lti_consumer.lticonfiguration')),
],
options={
'abstract': False,
},
),
migrations.CreateModel(
name='ProgramDiscussionsConfiguration',
fields=[
('created', model_utils.fields.AutoCreatedField(default=django.utils.timezone.now, editable=False, verbose_name='created')),
('modified', model_utils.fields.AutoLastModifiedField(default=django.utils.timezone.now, editable=False, verbose_name='modified')),
('program_uuid', models.CharField(db_index=True, max_length=50, primary_key=True, serialize=False, verbose_name='Program UUID')),
('enabled', models.BooleanField(default=True, help_text='If disabled, the LTI in the associated program will be disabled.')),
('provider_type', models.CharField(help_text="The LTI provider's id", max_length=50, verbose_name='LTI provider')),
('lti_configuration', models.ForeignKey(blank=True, help_text='The LTI configuration data for this program/provider.', null=True, on_delete=django.db.models.deletion.SET_NULL, to='lti_consumer.lticonfiguration')),
],
options={
'abstract': False,
},
),
migrations.CreateModel(
name='HistoricalProgramLiveConfiguration',
fields=[
('created', model_utils.fields.AutoCreatedField(default=django.utils.timezone.now, editable=False, verbose_name='created')),
('modified', model_utils.fields.AutoLastModifiedField(default=django.utils.timezone.now, editable=False, verbose_name='modified')),
('program_uuid', models.CharField(db_index=True, max_length=50, verbose_name='Program UUID')),
('enabled', models.BooleanField(default=True, help_text='If disabled, the LTI in the associated program will be disabled.')),
('provider_type', models.CharField(help_text="The LTI provider's id", max_length=50, verbose_name='LTI provider')),
('history_id', models.AutoField(primary_key=True, serialize=False)),
('history_date', models.DateTimeField()),
('history_change_reason', models.CharField(max_length=100, null=True)),
('history_type', models.CharField(choices=[('+', 'Created'), ('~', 'Changed'), ('-', 'Deleted')], max_length=1)),
('history_user', models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='+', to=settings.AUTH_USER_MODEL)),
('lti_configuration', models.ForeignKey(blank=True, db_constraint=False, help_text='The LTI configuration data for this program/provider.', null=True, on_delete=django.db.models.deletion.DO_NOTHING, related_name='+', to='lti_consumer.lticonfiguration')),
],
options={
'verbose_name': 'historical program live configuration',
'ordering': ('-history_date', '-history_id'),
'get_latest_by': 'history_date',
},
bases=(simple_history.models.HistoricalChanges, models.Model),
),
migrations.CreateModel(
name='HistoricalProgramDiscussionsConfiguration',
fields=[
('created', model_utils.fields.AutoCreatedField(default=django.utils.timezone.now, editable=False, verbose_name='created')),
('modified', model_utils.fields.AutoLastModifiedField(default=django.utils.timezone.now, editable=False, verbose_name='modified')),
('program_uuid', models.CharField(db_index=True, max_length=50, verbose_name='Program UUID')),
('enabled', models.BooleanField(default=True, help_text='If disabled, the LTI in the associated program will be disabled.')),
('provider_type', models.CharField(help_text="The LTI provider's id", max_length=50, verbose_name='LTI provider')),
('history_id', models.AutoField(primary_key=True, serialize=False)),
('history_date', models.DateTimeField()),
('history_change_reason', models.CharField(max_length=100, null=True)),
('history_type', models.CharField(choices=[('+', 'Created'), ('~', 'Changed'), ('-', 'Deleted')], max_length=1)),
('history_user', models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='+', to=settings.AUTH_USER_MODEL)),
('lti_configuration', models.ForeignKey(blank=True, db_constraint=False, help_text='The LTI configuration data for this program/provider.', null=True, on_delete=django.db.models.deletion.DO_NOTHING, related_name='+', to='lti_consumer.lticonfiguration')),
],
options={
'verbose_name': 'historical program discussions configuration',
'ordering': ('-history_date', '-history_id'),
'get_latest_by': 'history_date',
},
bases=(simple_history.models.HistoricalChanges, models.Model),
),
]

View File

@@ -2,6 +2,9 @@
from config_models.models import ConfigurationModel
from django.db import models
from django.utils.translation import gettext_lazy as _
from simple_history.models import HistoricalRecords
from lti_consumer.models import LtiConfiguration
from model_utils.models import TimeStampedModel
class ProgramsApiConfig(ConfigurationModel):
@@ -22,3 +25,55 @@ class ProgramsApiConfig(ConfigurationModel):
'Path used to construct URLs to programs marketing pages (e.g., "/foo").'
)
)
class AbstractProgramLTIConfiguration(TimeStampedModel):
"""
Associates a program with a LTI provider and configuration
"""
class Meta:
abstract = True
program_uuid = models.CharField(
primary_key=True,
db_index=True,
max_length=50,
verbose_name=_("Program UUID"),
)
enabled = models.BooleanField(
default=True,
help_text=_("If disabled, the LTI in the associated program will be disabled.")
)
lti_configuration = models.ForeignKey(
LtiConfiguration,
on_delete=models.SET_NULL,
blank=True,
null=True,
help_text=_("The LTI configuration data for this program/provider."),
)
provider_type = models.CharField(
blank=False,
max_length=50,
verbose_name=_("LTI provider"),
help_text=_("The LTI provider's id"),
)
def __str__(self):
return f"Configuration(uuid='{self.program_uuid}', provider='{self.provider_type}', enabled={self.enabled})"
@classmethod
def get(cls, program_uuid):
"""
Lookup a program discussion configuration by program uuid.
"""
return cls.objects.filter(
program_uuid=program_uuid
).first()
class ProgramLiveConfiguration(AbstractProgramLTIConfiguration):
history = HistoricalRecords()
class ProgramDiscussionsConfiguration(AbstractProgramLTIConfiguration):
history = HistoricalRecords()