Commit 131f136d by Zia Fazal

improved code quality

parent 290ccc52
...@@ -511,8 +511,8 @@ def _save_xblock(user, xblock, data=None, children_strings=None, metadata=None, ...@@ -511,8 +511,8 @@ def _save_xblock(user, xblock, data=None, children_strings=None, metadata=None,
if grader_type is not None: if grader_type is not None:
result.update(CourseGradingModel.update_section_grader_type(xblock, grader_type, user)) result.update(CourseGradingModel.update_section_grader_type(xblock, grader_type, user))
# If publish is set to 'republish' and this item is not in direct only categories
# If publish is set to 'republish' and this item is not in direct only categories and has previously been published, # and has previously been published,
# then this item should be republished. This is used by staff locking to ensure that changing the draft # then this item should be republished. This is used by staff locking to ensure that changing the draft
# value of the staff lock will also update the published version, but only at the unit level. # value of the staff lock will also update the published version, but only at the unit level.
if publish == 'republish' and xblock.category not in DIRECT_ONLY_CATEGORIES: if publish == 'republish' and xblock.category not in DIRECT_ONLY_CATEGORIES:
......
...@@ -63,7 +63,7 @@ BROKER_HEARTBEAT_CHECKRATE = 2 ...@@ -63,7 +63,7 @@ BROKER_HEARTBEAT_CHECKRATE = 2
# Each worker should only fetch one message at a time # Each worker should only fetch one message at a time
CELERYD_PREFETCH_MULTIPLIER = 1 CELERYD_PREFETCH_MULTIPLIER = 1
if not 'SOUTH_MIGRATION_MODULES' in vars() and not 'SOUTH_MIGRATION_MODULES' in globals(): if 'SOUTH_MIGRATION_MODULES' not in vars() and 'SOUTH_MIGRATION_MODULES' not in globals():
SOUTH_MIGRATION_MODULES = {} SOUTH_MIGRATION_MODULES = {}
# Skip djcelery migrations, since we don't use the database as the broker # Skip djcelery migrations, since we don't use the database as the broker
......
...@@ -897,7 +897,7 @@ NOTIFICATION_STORE_PROVIDER = { ...@@ -897,7 +897,7 @@ NOTIFICATION_STORE_PROVIDER = {
} }
} }
if not 'SOUTH_MIGRATION_MODULES' in vars() and not 'SOUTH_MIGRATION_MODULES' in globals(): if 'SOUTH_MIGRATION_MODULES' not in vars() and 'SOUTH_MIGRATION_MODULES' not in globals():
SOUTH_MIGRATION_MODULES = {} SOUTH_MIGRATION_MODULES = {}
SOUTH_MIGRATION_MODULES.update({ SOUTH_MIGRATION_MODULES.update({
......
...@@ -23,7 +23,7 @@ from util.testing import UrlResetMixin ...@@ -23,7 +23,7 @@ from util.testing import UrlResetMixin
from xmodule.modulestore.tests.factories import CourseFactory from xmodule.modulestore.tests.factories import CourseFactory
from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase
from openedx.core.djangoapps.course_groups.cohorts import is_commentable_cohorted, add_cohort, add_user_to_cohort, is_user_in_cohort from openedx.core.djangoapps.course_groups.cohorts import is_commentable_cohorted, add_cohort, add_user_to_cohort
from edx_notifications.lib.consumer import get_notifications_for_user, get_notifications_count_for_user from edx_notifications.lib.consumer import get_notifications_for_user, get_notifications_count_for_user
from edx_notifications.startup import initialize as initialize_notifications from edx_notifications.startup import initialize as initialize_notifications
......
from django.core.management.base import BaseCommand, CommandError """
Django management command to Revert the multiple cohorts feature.
"""
from django.core.management.base import BaseCommand
from django.core.exceptions import MultipleObjectsReturned from django.core.exceptions import MultipleObjectsReturned
from optparse import make_option from optparse import make_option
...@@ -8,7 +11,6 @@ from xmodule.modulestore.django import modulestore ...@@ -8,7 +11,6 @@ from xmodule.modulestore.django import modulestore
from xmodule.course_module import CourseDescriptor from xmodule.course_module import CourseDescriptor
from openedx.core.djangoapps.course_groups.models import CourseUserGroup from openedx.core.djangoapps.course_groups.models import CourseUserGroup
from openedx.core.djangoapps.course_groups.cohorts import ( from openedx.core.djangoapps.course_groups.cohorts import (
get_cohort,
get_cohort_by_name, get_cohort_by_name,
add_cohort, add_cohort,
add_user_to_cohort, add_user_to_cohort,
...@@ -18,12 +20,17 @@ from student.models import CourseEnrollment ...@@ -18,12 +20,17 @@ from student.models import CourseEnrollment
class Command(BaseCommand): class Command(BaseCommand):
"""
Command to revert multiple cohorts feature
"""
option_list = BaseCommand.option_list + ( option_list = BaseCommand.option_list + (
make_option('--fix', make_option(
'--fix',
action='store_true', action='store_true',
dest='fix', dest='fix',
default=False, default=False,
help='Apply possible fixes automatically'), help='Apply possible fixes automatically'
),
) )
help = 'Revert the multiple cohorts feature.' help = 'Revert the multiple cohorts feature.'
...@@ -70,8 +77,10 @@ class Command(BaseCommand): ...@@ -70,8 +77,10 @@ class Command(BaseCommand):
default_cohort = get_cohort_by_name(course.id, CourseUserGroup.default_cohort_name) default_cohort = get_cohort_by_name(course.id, CourseUserGroup.default_cohort_name)
except CourseUserGroup.DoesNotExist: except CourseUserGroup.DoesNotExist:
default_cohort = add_cohort(course.id, CourseUserGroup.default_cohort_name) default_cohort = add_cohort(course.id, CourseUserGroup.default_cohort_name)
self.stdout.write('Default cohort "{}" created for course "{}"'.format( self.stdout.write(
default_cohort.name, course.display_name) 'Default cohort "{}" created for course "{}"'.format(
default_cohort.name, course.display_name
)
) )
add_user_to_cohort(default_cohort, user.username) add_user_to_cohort(default_cohort, user.username)
self.stdout.write( self.stdout.write(
...@@ -92,13 +101,13 @@ class Command(BaseCommand): ...@@ -92,13 +101,13 @@ class Command(BaseCommand):
if options['fix']: if options['fix']:
user_cohorts = CourseUserGroup.objects.filter(course_id=course.id, user_cohorts = CourseUserGroup.objects.filter(course_id=course.id,
users__id=user.id).all() users__id=user.id).all()
user_cohort = user_cohorts[0]
for cohort in user_cohorts[1:]: for cohort in user_cohorts[1:]:
remove_user_from_cohort(cohort, user.username) remove_user_from_cohort(cohort, user.username)
self.stdout.write("User '{}' has been removed from cohort '{}' in course '{}'.\n".format( self.stdout.write(
user.username, cohort.name, course.display_name) "User '{}' has been removed from cohort '{}' in course '{}'.\n".format(
user.username, cohort.name, course.display_name
)
) )
self.stdout.write("User '{}' is now only in cohort '{}' in course '{}'.\n".format( self.stdout.write("User '{}' is now only in cohort '{}' in course '{}'.\n".format(
user.username, cohort.name, course.display_name) user.username, cohort.name, course.display_name)
) )
......
...@@ -5,7 +5,7 @@ This file contains celery tasks for student course enrollment ...@@ -5,7 +5,7 @@ This file contains celery tasks for student course enrollment
from celery.task import task from celery.task import task
from .models import CourseUserGroup from .models import CourseUserGroup
from edx_notifications.lib.publisher import bulk_publish_notification_to_users from edx_notifications.lib.publisher import bulk_publish_notification_to_users
from student.models import CourseEnrollment
import logging import logging
log = logging.getLogger(__name__) log = logging.getLogger(__name__)
...@@ -25,7 +25,7 @@ def publish_course_group_notification_task(course_group_id, notification_msg, ex ...@@ -25,7 +25,7 @@ def publish_course_group_notification_task(course_group_id, notification_msg, ex
try: try:
bulk_publish_notification_to_users(user_ids, notification_msg, exclude_user_ids=exclude_user_ids) bulk_publish_notification_to_users(user_ids, notification_msg, exclude_user_ids=exclude_user_ids)
except Exception, ex: except Exception, ex: # pylint: disable=broad-except
# Notifications are never critical, so we don't want to disrupt any # Notifications are never critical, so we don't want to disrupt any
# other logic processing. So log and continue. # other logic processing. So log and continue.
log.exception(ex) log.exception(ex)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment