Extract common configuration/documentation into the base StackedConfigModelAdmin class
This commit is contained in:
@@ -5,7 +5,9 @@ Convenience classes for defining StackedConfigModel Admin pages.
|
||||
|
||||
from config_models.admin import ConfigurationModelAdmin
|
||||
from django import forms
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
from opaque_keys.edx.keys import CourseKey
|
||||
from openedx.core.djangolib.markup import HTML, Text
|
||||
|
||||
|
||||
class CourseOverviewField(forms.ModelChoiceField):
|
||||
@@ -28,9 +30,48 @@ class StackedConfigModelAdmin(ConfigurationModelAdmin):
|
||||
"""
|
||||
form = StackedConfigModelAdminForm
|
||||
|
||||
def get_fields(self, request, obj=None):
|
||||
raw_id_fields = ('course',)
|
||||
|
||||
def get_fieldsets(self, request, obj=None):
|
||||
return (
|
||||
('Context', {
|
||||
'fields': self.key_fields,
|
||||
'description': Text(_(
|
||||
'These define the context to enable this configuration on. '
|
||||
'If no values are set, then the configuration applies globally. '
|
||||
'If a single value is set, then the configuration applies to all courses '
|
||||
'within that context. At most one value can be set at a time.{br}'
|
||||
'If multiple contexts apply to a course (for example, if configuration '
|
||||
'is specified for the course specifically, and for the org that the course '
|
||||
'is in, then the more specific context overrides the more general context.'
|
||||
)).format(br=HTML('<br>')),
|
||||
}),
|
||||
('Configuration', {
|
||||
'fields': self.stackable_fields,
|
||||
'description': _(
|
||||
'If any of these values are left empty or "Unknown", then their value '
|
||||
'at runtime will be retrieved from the next most specific context that applies. '
|
||||
'For example, if "Enabled" is left as "Unknown" in the course context, then that '
|
||||
'course will be Enabled only if the org that it is in is Enabled.'
|
||||
),
|
||||
})
|
||||
)
|
||||
|
||||
@property
|
||||
def key_fields(self):
|
||||
return list(self.model.KEY_FIELDS)
|
||||
|
||||
@property
|
||||
def stackable_fields(self):
|
||||
return list(self.model.STACKABLE_FIELDS)
|
||||
|
||||
@property
|
||||
def config_fields(self):
|
||||
fields = super(StackedConfigModelAdmin, self).get_fields(request, obj)
|
||||
return list(self.model.KEY_FIELDS) + [field for field in fields if field not in self.model.KEY_FIELDS]
|
||||
return [field for field in fields if field not in self.key_fields]
|
||||
|
||||
def get_fields(self, request, obj=None):
|
||||
return self.key_fields + self.config_fields
|
||||
|
||||
def get_displayable_field_names(self):
|
||||
"""
|
||||
|
||||
@@ -5,40 +5,10 @@ Django Admin pages for SelfPacedRelativeDatesConfig.
|
||||
|
||||
|
||||
from django.contrib import admin
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
|
||||
from openedx.core.djangoapps.config_model_utils.admin import StackedConfigModelAdmin
|
||||
|
||||
from .models import SelfPacedRelativeDatesConfig
|
||||
|
||||
|
||||
class SelfPacedRelativeDatesConfigAdmin(StackedConfigModelAdmin):
|
||||
"""
|
||||
Admin for course duration limit
|
||||
"""
|
||||
fieldsets = (
|
||||
('Context', {
|
||||
'fields': SelfPacedRelativeDatesConfig.KEY_FIELDS,
|
||||
'description': _(
|
||||
'These define the context to enable course duration limits on. '
|
||||
'If no values are set, then the configuration applies globally. '
|
||||
'If a single value is set, then the configuration applies to all courses '
|
||||
'within that context. At most one value can be set at a time.<br>'
|
||||
'If multiple contexts apply to a course (for example, if configuration '
|
||||
'is specified for the course specifically, and for the org that the course '
|
||||
'is in, then the more specific context overrides the more general context.'
|
||||
),
|
||||
}),
|
||||
('Configuration', {
|
||||
'fields': ('enabled',),
|
||||
'description': _(
|
||||
'If any of these values is left empty or "Unknown", then their value '
|
||||
'at runtime will be retrieved from the next most specific context that applies. '
|
||||
'For example, if "Enabled" is left as "Unknown" in the course context, then that '
|
||||
'course will be Enabled only if the org that it is in is Enabled.'
|
||||
),
|
||||
})
|
||||
)
|
||||
raw_id_fields = ('course',)
|
||||
|
||||
admin.site.register(SelfPacedRelativeDatesConfig, SelfPacedRelativeDatesConfigAdmin)
|
||||
admin.site.register(SelfPacedRelativeDatesConfig, StackedConfigModelAdmin)
|
||||
|
||||
@@ -5,37 +5,10 @@ Django Admin pages for ContentTypeGatingConfig.
|
||||
|
||||
|
||||
from django.contrib import admin
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
|
||||
from openedx.core.djangoapps.config_model_utils.admin import StackedConfigModelAdmin
|
||||
|
||||
from .models import ContentTypeGatingConfig
|
||||
|
||||
|
||||
class ContentTypeGatingConfigAdmin(StackedConfigModelAdmin):
|
||||
fieldsets = (
|
||||
('Context', {
|
||||
'fields': ContentTypeGatingConfig.KEY_FIELDS,
|
||||
'description': _(
|
||||
'These define the context to enable course duration limits on. '
|
||||
'If no values are set, then the configuration applies globally. '
|
||||
'If a single value is set, then the configuration applies to all courses '
|
||||
'within that context. At most one value can be set at a time.<br>'
|
||||
'If multiple contexts apply to a course (for example, if configuration '
|
||||
'is specified for the course specifically, and for the org that the course '
|
||||
'is in, then the more specific context overrides the more general context.'
|
||||
),
|
||||
}),
|
||||
('Configuration', {
|
||||
'fields': ('enabled', 'enabled_as_of', 'studio_override_enabled'),
|
||||
'description': _(
|
||||
'If any of these values is left empty or "Unknown", then their value '
|
||||
'at runtime will be retrieved from the next most specific context that applies. '
|
||||
'For example, if "Enabled" is left as "Unknown" in the course context, then that '
|
||||
'course will be Enabled only if the org that it is in is Enabled.'
|
||||
),
|
||||
})
|
||||
)
|
||||
raw_id_fields = ('course',)
|
||||
|
||||
admin.site.register(ContentTypeGatingConfig, ContentTypeGatingConfigAdmin)
|
||||
admin.site.register(ContentTypeGatingConfig, StackedConfigModelAdmin)
|
||||
|
||||
@@ -5,40 +5,9 @@ Django Admin pages for CourseDurationLimitConfig.
|
||||
|
||||
|
||||
from django.contrib import admin
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
|
||||
from openedx.core.djangoapps.config_model_utils.admin import StackedConfigModelAdmin
|
||||
|
||||
from .models import CourseDurationLimitConfig
|
||||
|
||||
|
||||
class CourseDurationLimitConfigAdmin(StackedConfigModelAdmin):
|
||||
"""
|
||||
Admin for course duration limit
|
||||
"""
|
||||
fieldsets = (
|
||||
('Context', {
|
||||
'fields': CourseDurationLimitConfig.KEY_FIELDS,
|
||||
'description': _(
|
||||
'These define the context to enable course duration limits on. '
|
||||
'If no values are set, then the configuration applies globally. '
|
||||
'If a single value is set, then the configuration applies to all courses '
|
||||
'within that context. At most one value can be set at a time.<br>'
|
||||
'If multiple contexts apply to a course (for example, if configuration '
|
||||
'is specified for the course specifically, and for the org that the course '
|
||||
'is in, then the more specific context overrides the more general context.'
|
||||
),
|
||||
}),
|
||||
('Configuration', {
|
||||
'fields': ('enabled', 'enabled_as_of'),
|
||||
'description': _(
|
||||
'If any of these values is left empty or "Unknown", then their value '
|
||||
'at runtime will be retrieved from the next most specific context that applies. '
|
||||
'For example, if "Enabled" is left as "Unknown" in the course context, then that '
|
||||
'course will be Enabled only if the org that it is in is Enabled.'
|
||||
),
|
||||
})
|
||||
)
|
||||
raw_id_fields = ('course',)
|
||||
|
||||
admin.site.register(CourseDurationLimitConfig, CourseDurationLimitConfigAdmin)
|
||||
admin.site.register(CourseDurationLimitConfig, StackedConfigModelAdmin)
|
||||
|
||||
Reference in New Issue
Block a user