INCR-236 (#20502)
* INCR-236 * Run python-modernize on openedx/features/course_duration_limits and verify that the change makes sense and tests does not break * Remove redundant import and update docstring style
This commit is contained in:
@@ -3,13 +3,15 @@
|
||||
Contains code related to computing content gating course duration limits
|
||||
and course access based on these limits.
|
||||
"""
|
||||
from __future__ import absolute_import
|
||||
|
||||
from datetime import timedelta
|
||||
|
||||
import six
|
||||
from django.utils import timezone
|
||||
from django.utils.translation import get_language, ugettext as _
|
||||
|
||||
from student.models import CourseEnrollment
|
||||
from util.date_utils import strftime_localized
|
||||
from django.utils.translation import get_language
|
||||
from django.utils.translation import ugettext as _
|
||||
from web_fragments.fragment import Fragment
|
||||
|
||||
from course_modes.models import CourseMode
|
||||
from lms.djangoapps.courseware.access_response import AccessError
|
||||
@@ -20,7 +22,8 @@ from openedx.core.djangoapps.catalog.utils import get_course_run_details
|
||||
from openedx.core.djangoapps.content.course_overviews.models import CourseOverview
|
||||
from openedx.core.djangolib.markup import HTML
|
||||
from openedx.features.course_duration_limits.models import CourseDurationLimitConfig
|
||||
from web_fragments.fragment import Fragment
|
||||
from student.models import CourseEnrollment
|
||||
from util.date_utils import strftime_localized
|
||||
|
||||
MIN_DURATION = timedelta(weeks=4)
|
||||
MAX_DURATION = timedelta(weeks=18)
|
||||
@@ -34,7 +37,6 @@ class AuditExpiredError(AccessError):
|
||||
def __init__(self, user, course, expiration_date):
|
||||
error_code = "audit_expired"
|
||||
developer_message = u"User {} had access to {} until {}".format(user, course, expiration_date)
|
||||
language = get_language()
|
||||
expiration_date = strftime_localized(expiration_date, EXPIRATION_DATE_FORMAT_STR)
|
||||
user_message = _(u"Access expired on {expiration_date}").format(expiration_date=expiration_date)
|
||||
try:
|
||||
@@ -229,7 +231,7 @@ def course_expiration_wrapper(user, block, view, frag, context): # pylint: disa
|
||||
# Course content must be escaped to render correctly due to the way the
|
||||
# way the XBlock rendering works. Transforming the safe markup to unicode
|
||||
# escapes correctly.
|
||||
course_expiration_fragment.content = unicode(course_expiration_fragment.content)
|
||||
course_expiration_fragment.content = six.text_type(course_expiration_fragment.content)
|
||||
|
||||
course_expiration_fragment.add_content(frag.content)
|
||||
course_expiration_fragment.add_fragment_resources(frag)
|
||||
|
||||
@@ -3,16 +3,20 @@
|
||||
Django Admin pages for CourseDurationLimitConfig.
|
||||
"""
|
||||
|
||||
from __future__ import unicode_literals
|
||||
from __future__ import absolute_import, unicode_literals
|
||||
|
||||
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,
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
Course duration limits application configuration
|
||||
"""
|
||||
# -*- coding: utf-8 -*-
|
||||
from __future__ import unicode_literals
|
||||
from __future__ import absolute_import, unicode_literals
|
||||
|
||||
from django.apps import AppConfig
|
||||
|
||||
|
||||
@@ -1,15 +1,6 @@
|
||||
"""
|
||||
Content type gating waffle flag
|
||||
"""
|
||||
import random
|
||||
|
||||
from django.dispatch import receiver
|
||||
from django.db import IntegrityError
|
||||
|
||||
from experiments.models import ExperimentData, ExperimentKeyValue
|
||||
from student.models import EnrollStatusChange
|
||||
from student.signals import ENROLL_STATUS_CHANGE
|
||||
|
||||
|
||||
EXPERIMENT_ID = 11
|
||||
EXPERIMENT_DATA_HOLDBACK_KEY = 'holdback'
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
"""
|
||||
Message types used for ACE communication by the course_duration_limits app.
|
||||
"""
|
||||
from __future__ import absolute_import
|
||||
|
||||
import logging
|
||||
|
||||
from openedx.core.djangoapps.ace_common.message import BaseMessageType
|
||||
|
||||
@@ -3,14 +3,14 @@ Course Duration Limit Configuration Models
|
||||
"""
|
||||
|
||||
# -*- coding: utf-8 -*-
|
||||
from __future__ import unicode_literals
|
||||
from __future__ import absolute_import, unicode_literals
|
||||
|
||||
from django.conf import settings
|
||||
from django.core.exceptions import ValidationError
|
||||
from django.db import models
|
||||
from django.utils import timezone
|
||||
from django.utils.encoding import python_2_unicode_compatible
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
from django.utils import timezone
|
||||
|
||||
from course_modes.models import CourseMode
|
||||
from lms.djangoapps.courseware.masquerade import (
|
||||
|
||||
@@ -2,23 +2,25 @@
|
||||
Resolvers used to find users for course_duration_limit message
|
||||
"""
|
||||
|
||||
from __future__ import absolute_import
|
||||
|
||||
import logging
|
||||
from datetime import datetime, timedelta
|
||||
|
||||
from course_modes.models import CourseMode
|
||||
from django.contrib.staticfiles.templatetags.staticfiles import static
|
||||
from django.db.models import Q
|
||||
from django.utils.timesince import timeuntil
|
||||
from django.utils.translation import ugettext as _
|
||||
from eventtracking import tracker
|
||||
|
||||
from course_modes.models import CourseMode
|
||||
from courseware.date_summary import verified_upgrade_deadline_link
|
||||
from lms.djangoapps.experiments.utils import stable_bucketing_hash_group
|
||||
from openedx.core.djangoapps.catalog.utils import get_course_run_details
|
||||
from courseware.date_summary import verified_upgrade_deadline_link, verified_upgrade_link_is_valid
|
||||
|
||||
from openedx.core.djangoapps.schedules.resolvers import (
|
||||
BinnedSchedulesBaseResolver,
|
||||
InvalidContextError,
|
||||
_get_trackable_course_home_url,
|
||||
_get_trackable_course_home_url
|
||||
)
|
||||
from track import segment
|
||||
|
||||
|
||||
@@ -2,9 +2,12 @@
|
||||
Tasks requiring asynchronous handling for course_duration_limits
|
||||
"""
|
||||
|
||||
from __future__ import absolute_import
|
||||
|
||||
import datetime
|
||||
import logging
|
||||
|
||||
import six
|
||||
import waffle
|
||||
from celery import task
|
||||
from celery_utils.logged_task import LoggedTask
|
||||
@@ -16,11 +19,9 @@ from edx_ace.message import Message
|
||||
from edx_ace.utils.date import deserialize, serialize
|
||||
from edx_django_utils.monitoring import set_custom_metric
|
||||
from opaque_keys.edx.keys import CourseKey
|
||||
from openedx.core.djangoapps.schedules.tasks import (
|
||||
_annonate_send_task_for_monitoring,
|
||||
_track_message_sent
|
||||
)
|
||||
|
||||
from openedx.core.djangoapps.schedules.resolvers import _get_datetime_beginning_of_day
|
||||
from openedx.core.djangoapps.schedules.tasks import _annonate_send_task_for_monitoring, _track_message_sent
|
||||
from openedx.core.lib.celery.task_utils import emulate_http_request
|
||||
|
||||
from . import message_types, resolvers
|
||||
@@ -77,7 +78,7 @@ class CourseDurationLimitMessageBaseTask(LoggedTask):
|
||||
target_date = current_date + datetime.timedelta(days=day_offset)
|
||||
task_args = (
|
||||
site.id,
|
||||
unicode(course_key),
|
||||
six.text_type(course_key),
|
||||
serialize(target_date),
|
||||
day_offset,
|
||||
override_recipient_email,
|
||||
|
||||
@@ -18,7 +18,6 @@ from course_modes.tests.factories import CourseModeFactory
|
||||
from openedx.core.djangoapps.config_model_utils.models import Provenance
|
||||
from openedx.core.djangoapps.content.course_overviews.tests.factories import CourseOverviewFactory
|
||||
from openedx.core.djangoapps.site_configuration.tests.factories import SiteConfigurationFactory
|
||||
from openedx.core.djangoapps.waffle_utils.testutils import override_waffle_flag
|
||||
from openedx.core.djangolib.testing.utils import CacheIsolationTestCase
|
||||
from openedx.features.course_duration_limits.models import CourseDurationLimitConfig
|
||||
from student.tests.factories import CourseEnrollmentFactory, UserFactory
|
||||
|
||||
Reference in New Issue
Block a user