Merge pull request #20999 from edx/awais786/INCR-341

INCR-341
This commit is contained in:
Awais Qureshi
2019-07-15 12:05:31 +05:00
committed by GitHub
7 changed files with 42 additions and 28 deletions

View File

@@ -3,15 +3,18 @@ Utilities for export a course's XML into a git repository,
committing and pushing the changes.
"""
from __future__ import absolute_import
import logging
import os
import subprocess
from urlparse import urlparse
import six
from django.conf import settings
from django.contrib.auth.models import User
from django.utils import timezone
from django.utils.translation import ugettext_lazy as _
from six.moves.urllib.parse import urlparse # pylint: disable=import-error
from xmodule.contentstore.django import contentstore
from xmodule.modulestore.django import modulestore
@@ -32,7 +35,7 @@ class GitExportError(Exception):
def __init__(self, message):
# Force the lazy i18n values to turn into actual unicode objects
super(GitExportError, self).__init__(unicode(message))
super(GitExportError, self).__init__(six.text_type(message))
NO_EXPORT_DIR = _(u"GIT_REPO_EXPORT_DIR not set or path {0} doesn't exist, "
"please create it, or configure a different path with "

View File

@@ -2,16 +2,18 @@
"""
Utils related to the videos.
"""
import logging
from urlparse import urljoin
import requests
from __future__ import absolute_import
import logging
import requests
import six
from django.conf import settings
from django.core.files.images import get_image_dimensions
from django.core.files.uploadedfile import SimpleUploadedFile
from django.utils.translation import ugettext as _
from edxval.api import get_course_video_image_url, update_video_image
from six.moves.urllib.parse import urljoin # pylint: disable=import-error
# Youtube thumbnail sizes.
# https://img.youtube.com/vi/{youtube_id}/{thumbnail_quality}.jpg
@@ -40,9 +42,9 @@ def validate_video_image(image_file, skip_aspect_ratio=False):
if not all(hasattr(image_file, attr) for attr in ['name', 'content_type', 'size']):
error = _('The image must have name, content type, and size information.')
elif image_file.content_type not in settings.VIDEO_IMAGE_SUPPORTED_FILE_FORMATS.values():
elif image_file.content_type not in list(settings.VIDEO_IMAGE_SUPPORTED_FILE_FORMATS.values()):
error = _(u'This image file type is not supported. Supported file types are {supported_file_formats}.').format(
supported_file_formats=settings.VIDEO_IMAGE_SUPPORTED_FILE_FORMATS.keys()
supported_file_formats=list(settings.VIDEO_IMAGE_SUPPORTED_FILE_FORMATS.keys())
)
elif image_file.size > settings.VIDEO_IMAGE_SETTINGS['VIDEO_IMAGE_MAX_BYTES']:
error = _(u'This image file must be smaller than {image_max_size}.').format(
@@ -126,7 +128,7 @@ def scrape_youtube_thumbnail(course_id, edx_video_id, youtube_id):
# Scrape when course video image does not exist for edx_video_id.
if not get_course_video_image_url(course_id, edx_video_id):
thumbnail_content, thumbnail_content_type = download_youtube_video_thumbnail(youtube_id)
supported_content_types = {v: k for k, v in settings.VIDEO_IMAGE_SUPPORTED_FILE_FORMATS.iteritems()}
supported_content_types = {v: k for k, v in six.iteritems(settings.VIDEO_IMAGE_SUPPORTED_FILE_FORMATS)}
image_filename = '{youtube_id}{image_extention}'.format(
youtube_id=youtube_id,
image_extention=supported_content_types.get(

View File

@@ -1,10 +1,15 @@
"""Grading policy"""
from __future__ import absolute_import
import json
from base64 import b64encode
from datetime import timedelta
from hashlib import sha1
import json
import six
from eventtracking import tracker
from contentstore.signals.signals import GRADING_POLICY_CHANGED
from eventtracking import tracker
from track.event_transaction_utils import create_new_event_transaction_id
from xmodule.modulestore.django import modulestore
@@ -183,7 +188,7 @@ class CourseGradingModel(object):
descriptor = modulestore().get_item(location)
return {
"graderType": descriptor.format if descriptor.format is not None else 'notgraded',
"location": unicode(location),
"location": six.text_type(location),
}
@staticmethod
@@ -256,12 +261,12 @@ class CourseGradingModel(object):
def _grading_event_and_signal(course_key, user_id):
name = GRADING_POLICY_CHANGED_EVENT_TYPE
course = modulestore().get_course(course_key)
grading_policy_hash = unicode(hash_grading_policy(course.grading_policy))
grading_policy_hash = six.text_type(hash_grading_policy(course.grading_policy))
data = {
"course_id": unicode(course_key),
"user_id": unicode(user_id),
"course_id": six.text_type(course_key),
"user_id": six.text_type(user_id),
"grading_policy_hash": grading_policy_hash,
"event_transaction_id": unicode(create_new_event_transaction_id()),
"event_transaction_id": six.text_type(create_new_event_transaction_id()),
"event_transaction_type": GRADING_POLICY_CHANGED_EVENT_TYPE,
}
tracker.emit(name, data)

View File

@@ -1,18 +1,20 @@
"""
Django module for Course Metadata class -- manages advanced settings and related parameters
"""
from __future__ import absolute_import
import six
from crum import get_current_user
from django.conf import settings
from django.utils.translation import ugettext as _
from six import text_type
from xblock.fields import Scope
from crum import get_current_user
from cms.djangoapps.contentstore.config.waffle import ENABLE_PROCTORING_PROVIDER_OVERRIDES
from openedx.features.course_experience import COURSE_ENABLE_UNENROLLED_ACCESS_FLAG
from student.roles import GlobalStaff
from xblock_django.models import XBlockStudioConfigurationFlag
from xmodule.modulestore.django import modulestore
from student.roles import GlobalStaff
from openedx.features.course_experience import COURSE_ENABLE_UNENROLLED_ACCESS_FLAG
from cms.djangoapps.contentstore.config.waffle import ENABLE_PROCTORING_PROVIDER_OVERRIDES
class CourseMetadata(object):
@@ -151,7 +153,7 @@ class CourseMetadata(object):
metadata = cls.fetch_all(descriptor)
black_list_of_fields = cls.get_blacklist_of_fields(descriptor.id)
for key, value in metadata.iteritems():
for key, value in six.iteritems(metadata):
if key in black_list_of_fields:
continue
result[key] = value
@@ -195,7 +197,7 @@ class CourseMetadata(object):
# Validate the values before actually setting them.
key_values = {}
for key, model in jsondict.iteritems():
for key, model in six.iteritems(jsondict):
# should it be an error if one of the filtered list items is in the payload?
if key in blacklist_of_fields:
continue
@@ -228,13 +230,13 @@ class CourseMetadata(object):
if not filter_tabs:
blacklist_of_fields.remove("tabs")
filtered_dict = dict((k, v) for k, v in jsondict.iteritems() if k not in blacklist_of_fields)
filtered_dict = dict((k, v) for k, v in six.iteritems(jsondict) if k not in blacklist_of_fields)
did_validate = True
errors = []
key_values = {}
updated_data = None
for key, model in filtered_dict.iteritems():
for key, model in six.iteritems(filtered_dict):
try:
val = model['value']
if hasattr(descriptor, key) and getattr(descriptor, key) != val:
@@ -254,7 +256,7 @@ class CourseMetadata(object):
"""
Update metadata descriptor from key_values. Saves to modulestore if save is true.
"""
for key, value in key_values.iteritems():
for key, value in six.iteritems(key_values):
setattr(descriptor, key, value)
if save and key_values:

View File

@@ -1,6 +1,8 @@
"""
CourseSettingsEncoder
"""
from __future__ import absolute_import
import datetime
import json
from json.encoder import JSONEncoder

View File

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

View File

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