Merge pull request #20616 from edx/estute/INCR-309

INCR-309 Run python-modernize on lms/djangoapps/ccx/migrations
This commit is contained in:
Christie Rice
2019-05-15 14:30:58 -04:00
committed by GitHub
6 changed files with 38 additions and 31 deletions

View File

@@ -1,8 +1,8 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from __future__ import absolute_import, unicode_literals
from django.db import migrations, models
from django.conf import settings
from django.db import migrations, models
from opaque_keys.edx.django.models import CourseKeyField, UsageKeyField

View File

@@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from __future__ import absolute_import, unicode_literals
from django.db import migrations, models

View File

@@ -1,17 +1,15 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from __future__ import absolute_import, unicode_literals
import logging
import six
from ccx_keys.locator import CCXLocator
from courseware.courses import get_course_by_id
from django.db import migrations
from django.http import Http404
from lms.djangoapps.ccx.utils import (
add_master_course_staff_to_ccx,
remove_master_course_staff_from_ccx,
)
from courseware.courses import get_course_by_id
from lms.djangoapps.ccx.utils import add_master_course_staff_to_ccx, remove_master_course_staff_from_ccx
log = logging.getLogger("edx.ccx")
@@ -31,7 +29,7 @@ def add_master_course_staff_to_ccx_for_existing_ccx(apps, schema_editor):
if not ccx.course_id or ccx.course_id.deprecated:
# prevent migration for deprecated course ids or invalid ids.
continue
ccx_locator = CCXLocator.from_course_locator(ccx.course_id, unicode(ccx.id))
ccx_locator = CCXLocator.from_course_locator(ccx.course_id, six.text_type(ccx.id))
try:
course = get_course_by_id(ccx.course_id)
add_master_course_staff_to_ccx(
@@ -63,7 +61,7 @@ def remove_master_course_staff_from_ccx_for_existing_ccx(apps, schema_editor):
if not ccx.course_id or ccx.course_id.deprecated:
# prevent migration for deprecated course ids or invalid ids.
continue
ccx_locator = CCXLocator.from_course_locator(ccx.course_id, unicode(ccx.id))
ccx_locator = CCXLocator.from_course_locator(ccx.course_id, six.text_type(ccx.id))
try:
course = get_course_by_id(ccx.course_id)
remove_master_course_staff_from_ccx(

View File

@@ -1,17 +1,25 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from __future__ import absolute_import, unicode_literals
import logging
import six
from ccx_keys.locator import CCXLocator
from courseware.courses import get_course_by_id
from django.db import migrations
from django.http import Http404
from openedx.core.djangoapps.django_comment_common.models import FORUM_ROLE_ADMINISTRATOR, FORUM_ROLE_MODERATOR, \
FORUM_ROLE_COMMUNITY_TA, FORUM_ROLE_STUDENT
from openedx.core.djangoapps.django_comment_common.utils import STUDENT_ROLE_PERMISSIONS, MODERATOR_ROLE_PERMISSIONS, \
ADMINISTRATOR_ROLE_PERMISSIONS
from courseware.courses import get_course_by_id
from openedx.core.djangoapps.django_comment_common.models import (
FORUM_ROLE_ADMINISTRATOR,
FORUM_ROLE_COMMUNITY_TA,
FORUM_ROLE_MODERATOR,
FORUM_ROLE_STUDENT
)
from openedx.core.djangoapps.django_comment_common.utils import (
ADMINISTRATOR_ROLE_PERMISSIONS,
MODERATOR_ROLE_PERMISSIONS,
STUDENT_ROLE_PERMISSIONS
)
log = logging.getLogger("edx.ccx")
@@ -44,7 +52,7 @@ def seed_forum_roles_for_existing_ccx(apps, schema_editor):
)
continue
ccx_locator = CCXLocator.from_course_locator(ccx.course_id, unicode(ccx.id))
ccx_locator = CCXLocator.from_course_locator(ccx.course_id, six.text_type(ccx.id))
# Create forum roles.
admin_role, _ = Role.objects.get_or_create(name=FORUM_ROLE_ADMINISTRATOR, course_id=ccx_locator)

View File

@@ -1,16 +1,17 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from __future__ import absolute_import, unicode_literals
import logging
import six
from ccx_keys.locator import CCXLocator
from django.contrib.auth.models import User
from django.db import migrations
from django.http import Http404
from ccx_keys.locator import CCXLocator
from courseware.courses import get_course_by_id
from instructor.access import allow_access, revoke_access
log = logging.getLogger("edx.ccx")
def change_existing_ccx_coaches_to_staff(apps, schema_editor):
@@ -31,18 +32,18 @@ def change_existing_ccx_coaches_to_staff(apps, schema_editor):
return
list_ccx = CustomCourseForEdX.objects.using(db_alias).all()
for ccx in list_ccx:
ccx_locator = CCXLocator.from_course_locator(ccx.course_id, unicode(ccx.id))
ccx_locator = CCXLocator.from_course_locator(ccx.course_id, six.text_type(ccx.id))
try:
course = get_course_by_id(ccx_locator)
except Http404:
log.error('Could not migrate access for CCX course: %s', unicode(ccx_locator))
log.error('Could not migrate access for CCX course: %s', six.text_type(ccx_locator))
else:
coach = User.objects.get(id=ccx.coach.id)
allow_access(course, coach, 'staff', send_email=False)
revoke_access(course, coach, 'ccx_coach', send_email=False)
log.info(
'The CCX coach of CCX %s has been switched from "CCX Coach" to "Staff".',
unicode(ccx_locator)
six.text_type(ccx_locator)
)
def revert_ccx_staff_to_coaches(apps, schema_editor):
@@ -61,18 +62,18 @@ def revert_ccx_staff_to_coaches(apps, schema_editor):
return
list_ccx = CustomCourseForEdX.objects.using(db_alias).all()
for ccx in list_ccx:
ccx_locator = CCXLocator.from_course_locator(ccx.course_id, unicode(ccx.id))
ccx_locator = CCXLocator.from_course_locator(ccx.course_id, six.text_type(ccx.id))
try:
course = get_course_by_id(ccx_locator)
except Http404:
log.error('Could not migrate access for CCX course: %s', unicode(ccx_locator))
log.error('Could not migrate access for CCX course: %s', six.text_type(ccx_locator))
else:
coach = User.objects.get(id=ccx.coach.id)
allow_access(course, coach, 'ccx_coach', send_email=False)
revoke_access(course, coach, 'staff', send_email=False)
log.info(
'The CCX coach of CCX %s has been switched from "Staff" to "CCX Coach".',
unicode(ccx_locator)
six.text_type(ccx_locator)
)
class Migration(migrations.Migration):

View File

@@ -1,14 +1,14 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.11.15 on 2018-08-31 18:13
from __future__ import unicode_literals
from django.db import migrations
from django.http import Http404
from __future__ import absolute_import, unicode_literals
import json
import logging
from ccx_keys.locator import CCXLocator
from django.db import migrations
from django.http import Http404
from courseware.courses import get_course_by_id
log = logging.getLogger(__name__)