Remove NewAssets config model & create migration file
This commit is contained in:
@@ -2,30 +2,11 @@
|
||||
Admin site bindings for contentstore
|
||||
"""
|
||||
|
||||
from config_models.admin import ConfigurationModelAdmin, KeyedConfigurationModelAdmin
|
||||
from config_models.admin import ConfigurationModelAdmin
|
||||
from django.contrib import admin
|
||||
|
||||
from contentstore.config.forms import CourseNewAssetsPageAdminForm
|
||||
from contentstore.config.models import NewAssetsPageFlag, CourseNewAssetsPageFlag
|
||||
from contentstore.models import PushNotificationConfig, VideoUploadConfig
|
||||
|
||||
|
||||
class CourseNewAssetsPageAdmin(KeyedConfigurationModelAdmin):
|
||||
"""
|
||||
Admin for enabling new asset page on a course-by-course basis.
|
||||
Allows searching by course id.
|
||||
"""
|
||||
form = CourseNewAssetsPageAdminForm
|
||||
search_fields = ['course_id']
|
||||
fieldsets = (
|
||||
(None, {
|
||||
'fields': ('course_id', 'enabled'),
|
||||
'description': 'Enter a valid course id. If it is invalid, an error message will display.'
|
||||
}),
|
||||
)
|
||||
|
||||
admin.site.register(NewAssetsPageFlag, ConfigurationModelAdmin)
|
||||
admin.site.register(CourseNewAssetsPageFlag, CourseNewAssetsPageAdmin)
|
||||
|
||||
admin.site.register(VideoUploadConfig, ConfigurationModelAdmin)
|
||||
admin.site.register(PushNotificationConfig, ConfigurationModelAdmin)
|
||||
|
||||
@@ -1,29 +0,0 @@
|
||||
"""
|
||||
Defines a form for providing validation.
|
||||
"""
|
||||
import logging
|
||||
|
||||
from django import forms
|
||||
from opaque_keys import InvalidKeyError
|
||||
from opaque_keys.edx.locator import CourseLocator
|
||||
from six import text_type
|
||||
|
||||
from contentstore.config.models import CourseNewAssetsPageFlag
|
||||
from openedx.core.lib.courses import clean_course_id
|
||||
from xmodule.modulestore.django import modulestore
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class CourseNewAssetsPageAdminForm(forms.ModelForm):
|
||||
"""Input form for new asset page enablement, allowing us to verify user input."""
|
||||
|
||||
class Meta(object):
|
||||
model = CourseNewAssetsPageFlag
|
||||
fields = '__all__'
|
||||
|
||||
def clean_course_id(self):
|
||||
"""
|
||||
Validate the course id
|
||||
"""
|
||||
return clean_course_id(self)
|
||||
@@ -1,78 +0,0 @@
|
||||
"""
|
||||
Models for configuration of the feature flags
|
||||
controlling the new assets page.
|
||||
"""
|
||||
from config_models.models import ConfigurationModel
|
||||
from django.db.models import BooleanField
|
||||
from opaque_keys.edx.django.models import CourseKeyField
|
||||
from six import text_type
|
||||
|
||||
|
||||
class NewAssetsPageFlag(ConfigurationModel):
|
||||
"""
|
||||
Enables the in-development new assets page from studio-frontend.
|
||||
|
||||
Defaults to False platform-wide, but can be overriden via a course-specific
|
||||
flag. The idea is that we can use this to do a gradual rollout, and remove
|
||||
the flag entirely once generally released to everyone.
|
||||
"""
|
||||
# this field overrides course-specific settings to enable the feature for all courses
|
||||
enabled_for_all_courses = BooleanField(default=False)
|
||||
|
||||
@classmethod
|
||||
def feature_enabled(cls, course_id=None):
|
||||
"""
|
||||
Looks at the currently active configuration model to determine whether
|
||||
the new assets page feature is available.
|
||||
|
||||
There are 2 booleans to be concerned with - enabled_for_all_courses,
|
||||
and the implicit is_enabled(). They interact in the following ways:
|
||||
- is_enabled(): False, enabled_for_all_courses: True or False
|
||||
- no one can use the feature.
|
||||
- is_enabled(): True, enabled_for_all_courses: False
|
||||
- check for a CourseNewAssetsPageFlag, use that value (default False)
|
||||
- if no course_id provided, return False
|
||||
- is_enabled(): True, enabled_for_all_courses: True
|
||||
- everyone can use the feature
|
||||
"""
|
||||
if not NewAssetsPageFlag.is_enabled():
|
||||
return False
|
||||
elif not NewAssetsPageFlag.current().enabled_for_all_courses:
|
||||
if course_id:
|
||||
effective = CourseNewAssetsPageFlag.objects.filter(course_id=course_id).order_by('-change_date').first()
|
||||
return effective.enabled if effective is not None else False
|
||||
else:
|
||||
return False
|
||||
else:
|
||||
return True
|
||||
|
||||
class Meta(object):
|
||||
app_label = "contentstore"
|
||||
|
||||
def __unicode__(self):
|
||||
current_model = NewAssetsPageFlag.current()
|
||||
return u"NewAssetsPageFlag: enabled {}".format(
|
||||
current_model.is_enabled()
|
||||
)
|
||||
|
||||
|
||||
class CourseNewAssetsPageFlag(ConfigurationModel):
|
||||
"""
|
||||
Enables new assets page for a specific
|
||||
course. Only has an effect if the general
|
||||
flag above is set to True.
|
||||
"""
|
||||
KEY_FIELDS = ('course_id',)
|
||||
|
||||
class Meta(object):
|
||||
app_label = "contentstore"
|
||||
|
||||
# The course that these features are attached to.
|
||||
course_id = CourseKeyField(max_length=255, db_index=True)
|
||||
|
||||
def __unicode__(self):
|
||||
not_en = "Not "
|
||||
if self.enabled:
|
||||
not_en = ""
|
||||
# pylint: disable=no-member
|
||||
return u"Course '{}': New assets page {}Enabled".format(text_type(self.course_id), not_en)
|
||||
@@ -0,0 +1,28 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('contentstore', '0002_add_assets_page_flag'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.RemoveField(
|
||||
model_name='coursenewassetspageflag',
|
||||
name='changed_by',
|
||||
),
|
||||
migrations.RemoveField(
|
||||
model_name='newassetspageflag',
|
||||
name='changed_by',
|
||||
),
|
||||
migrations.DeleteModel(
|
||||
name='CourseNewAssetsPageFlag',
|
||||
),
|
||||
migrations.DeleteModel(
|
||||
name='NewAssetsPageFlag',
|
||||
),
|
||||
]
|
||||
Reference in New Issue
Block a user