Skip to content
Snippets Groups Projects
Commit 8b7bb776 authored by Stuart Young's avatar Stuart Young
Browse files

run python modernize

parent a6fce121
No related branches found
No related tags found
No related merge requests found
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from __future__ import absolute_import
from django.db import migrations, models
from django.conf import settings
from opaque_keys.edx.django.models import CourseKeyField, UsageKeyField
......
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from __future__ import absolute_import
from django.db import migrations, models
......
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from __future__ import absolute_import
import logging
from ccx_keys.locator import CCXLocator
......@@ -12,6 +13,7 @@ from lms.djangoapps.ccx.utils import (
add_master_course_staff_to_ccx,
remove_master_course_staff_from_ccx,
)
import six
log = logging.getLogger("edx.ccx")
......@@ -31,7 +33,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 +65,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(
......
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from __future__ import absolute_import
import logging
from ccx_keys.locator import CCXLocator
......@@ -12,6 +13,7 @@ from openedx.core.djangoapps.django_comment_common.models import FORUM_ROLE_ADMI
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
import six
log = logging.getLogger("edx.ccx")
......@@ -44,7 +46,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)
......
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from __future__ import absolute_import
import logging
from django.contrib.auth.models import User
......@@ -9,6 +10,7 @@ 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
import six
log = logging.getLogger("edx.ccx")
......@@ -31,18 +33,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 +63,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):
......
......@@ -2,6 +2,7 @@
# Generated by Django 1.11.15 on 2018-08-31 18:13
from __future__ import unicode_literals
from __future__ import absolute_import
from django.db import migrations
from django.http import Http404
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment