From 8cafadc03b274a448c87e2e0b16dae2ddb1dece0 Mon Sep 17 00:00:00 2001 From: ichuang Date: Sat, 6 Apr 2013 23:59:51 +0000 Subject: [PATCH 1/4] make "edit" links work - fixes giturl (was broken by xblocks migration) Conflicts: lms/templates/staff_problem_info.html lms/xmodule_namespace.py --- common/djangoapps/xmodule_modifiers.py | 19 +++++++++++++++++++ .../xmodule/modulestore/inheritance.py | 3 ++- common/lib/xmodule/xmodule/xml_module.py | 3 +++ lms/templates/staff_problem_info.html | 14 +++++++++++--- lms/xmodule_namespace.py | 3 ++- 5 files changed, 37 insertions(+), 5 deletions(-) diff --git a/common/djangoapps/xmodule_modifiers.py b/common/djangoapps/xmodule_modifiers.py index d398dfef0d..86cdec6cb7 100644 --- a/common/djangoapps/xmodule_modifiers.py +++ b/common/djangoapps/xmodule_modifiers.py @@ -108,6 +108,22 @@ def add_histogram(get_html, module, user): histogram = grade_histogram(module_id) render_histogram = len(histogram) > 0 + if settings.MITX_FEATURES.get('ENABLE_LMS_MIGRATION'): + [filepath, filename] = module.descriptor.xml_attributes.get('filename', ['', None]) + osfs = module.system.filestore + if filename is not None and osfs.exists(filename): + # if original, unmangled filename exists then use it (github + # doesn't like symlinks) + filepath = filename + data_dir = osfs.root_path.rsplit('/')[-1] + giturl = getattr(module.lms, 'giturl', 'https://github.com/MITx') + edit_link = "%s/%s/tree/master/%s" % (giturl, data_dir, filepath) + else: + edit_link = False + # Need to define all the variables that are about to be used + giturl = "" + data_dir = "" + source_file = module.lms.source_file # source used to generate the problem XML, eg latex or word # useful to indicate to staff if problem has been released or not @@ -121,12 +137,15 @@ def add_histogram(get_html, module, user): staff_context = {'fields': [(field.name, getattr(module, field.name)) for field in module.fields], 'lms_fields': [(field.name, getattr(module.lms, field.name)) for field in module.lms.fields], + 'xml_attributes' : module.descriptor.xml_attributes, 'location': module.location, 'xqa_key': module.lms.xqa_key, 'source_file': source_file, + 'source_url': '%s/%s/tree/master/%s' % (giturl, data_dir, source_file), 'category': str(module.__class__.__name__), # Template uses element_id in js function names, so can't allow dashes 'element_id': module.location.html_id().replace('-', '_'), + 'edit_link': edit_link, 'user': user, 'xqa_server': settings.MITX_FEATURES.get('USE_XQA_SERVER', 'http://xqa:server@content-qa.mitx.mit.edu/xqa'), 'histogram': json.dumps(histogram), diff --git a/common/lib/xmodule/xmodule/modulestore/inheritance.py b/common/lib/xmodule/xmodule/modulestore/inheritance.py index d819abe367..927f01d543 100644 --- a/common/lib/xmodule/xmodule/modulestore/inheritance.py +++ b/common/lib/xmodule/xmodule/modulestore/inheritance.py @@ -8,7 +8,8 @@ INHERITABLE_METADATA = ( # How many days early to show a course element to beta testers (float) # intended to be set per-course, but can be overridden in for specific # elements. Can be a float. - 'days_early_for_beta' + 'days_early_for_beta', + 'giturl' # for git edit link ) def compute_inherited_metadata(descriptor): diff --git a/common/lib/xmodule/xmodule/xml_module.py b/common/lib/xmodule/xmodule/xml_module.py index e5c1708ac4..c8a1ac009c 100644 --- a/common/lib/xmodule/xmodule/xml_module.py +++ b/common/lib/xmodule/xmodule/xml_module.py @@ -102,6 +102,7 @@ class XmlDescriptor(XModuleDescriptor): 'start', 'due', 'graded', 'display_name', 'url_name', 'hide_from_toc', 'ispublic', # if True, then course is listed for all users; see 'xqa_key', # for xqaa server access + 'giturl', # url of git server for origin of file # information about testcenter exams is a dict (of dicts), not a string, # so it cannot be easily exportable as a course element's attribute. 'testcenter_info', @@ -222,6 +223,7 @@ class XmlDescriptor(XModuleDescriptor): definition, children = cls.definition_from_xml(definition_xml, system) if definition_metadata: definition['definition_metadata'] = definition_metadata + definition['filename'] = [ filepath, filename ] return definition, children @@ -315,6 +317,7 @@ class XmlDescriptor(XModuleDescriptor): model_data['children'] = children model_data['xml_attributes'] = {} + model_data['xml_attributes']['filename'] = definition.get('filename', ['', None]) # for git link for key, value in metadata.items(): if key not in set(f.name for f in cls.fields + cls.lms.fields): model_data['xml_attributes'][key] = value diff --git a/lms/templates/staff_problem_info.html b/lms/templates/staff_problem_info.html index 807182b059..7b4abf13fd 100644 --- a/lms/templates/staff_problem_info.html +++ b/lms/templates/staff_problem_info.html @@ -1,15 +1,17 @@ ## The JS for this is defined in xqa_interface.html ${module_content} -%if location.category in ['problem','video','html']: +%if location.category in ['problem','video','html','combinedopenended']: % if edit_link:
- Edit / - Edit + % if xqa_key: + / QA + % endif
% endif
Staff Debug Info
@@ -61,6 +63,12 @@ location = ${location | h} ${name}
${field | h}
%endfor + + + %for name, field in xml_attributes.items(): + + %endfor +
XML attributes
${name}
${field | h}
category = ${category | h} %if render_histogram: diff --git a/lms/xmodule_namespace.py b/lms/xmodule_namespace.py index 3ff1ed3971..14a6049186 100644 --- a/lms/xmodule_namespace.py +++ b/lms/xmodule_namespace.py @@ -52,7 +52,8 @@ class LmsNamespace(Namespace): start = Date(help="Start time when this module is visible", scope=Scope.settings) due = Date(help="Date that this problem is due by", scope=Scope.settings) - source_file = String(help="DO NOT USE", scope=Scope.settings) + source_file = String(help="source file name (eg for latex)", scope=Scope.settings) + giturl = String(help="url root for course data git repository", scope=Scope.settings) xqa_key = String(help="DO NOT USE", scope=Scope.settings) ispublic = Boolean(help="Whether this course is open to the public, or only to admins", scope=Scope.settings) graceperiod = Timedelta( From d2768c644e3c96975fa0b745e5d868999b0baa2e Mon Sep 17 00:00:00 2001 From: ichuang Date: Sun, 7 Apr 2013 00:18:53 +0000 Subject: [PATCH 2/4] not all modules have xml_attributes ; be careful about this in xmodule_modifier --- common/djangoapps/xmodule_modifiers.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/common/djangoapps/xmodule_modifiers.py b/common/djangoapps/xmodule_modifiers.py index 86cdec6cb7..7d22648f52 100644 --- a/common/djangoapps/xmodule_modifiers.py +++ b/common/djangoapps/xmodule_modifiers.py @@ -109,7 +109,7 @@ def add_histogram(get_html, module, user): render_histogram = len(histogram) > 0 if settings.MITX_FEATURES.get('ENABLE_LMS_MIGRATION'): - [filepath, filename] = module.descriptor.xml_attributes.get('filename', ['', None]) + [filepath, filename] = getattr(module.descriptor, 'xml_attributes', {}).get('filename', ['', None]) osfs = module.system.filestore if filename is not None and osfs.exists(filename): # if original, unmangled filename exists then use it (github @@ -137,7 +137,7 @@ def add_histogram(get_html, module, user): staff_context = {'fields': [(field.name, getattr(module, field.name)) for field in module.fields], 'lms_fields': [(field.name, getattr(module.lms, field.name)) for field in module.lms.fields], - 'xml_attributes' : module.descriptor.xml_attributes, + 'xml_attributes' : getattr(module.descriptor, 'xml_attributes', {}), 'location': module.location, 'xqa_key': module.lms.xqa_key, 'source_file': source_file, From f88b5794e4ef79b0248b715688b74dedf49bb326 Mon Sep 17 00:00:00 2001 From: ichuang Date: Sun, 7 Apr 2013 00:48:32 +0000 Subject: [PATCH 3/4] fix default giturl link --- common/djangoapps/xmodule_modifiers.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/common/djangoapps/xmodule_modifiers.py b/common/djangoapps/xmodule_modifiers.py index 7d22648f52..3f6db354d6 100644 --- a/common/djangoapps/xmodule_modifiers.py +++ b/common/djangoapps/xmodule_modifiers.py @@ -116,7 +116,7 @@ def add_histogram(get_html, module, user): # doesn't like symlinks) filepath = filename data_dir = osfs.root_path.rsplit('/')[-1] - giturl = getattr(module.lms, 'giturl', 'https://github.com/MITx') + giturl = getattr(module.lms, 'giturl', '') or 'https://github.com/MITx' edit_link = "%s/%s/tree/master/%s" % (giturl, data_dir, filepath) else: edit_link = False From 0949754cd4c004b6cf1379db537b857439c1988a Mon Sep 17 00:00:00 2001 From: Chris Dodge Date: Mon, 8 Apr 2013 10:56:40 -0400 Subject: [PATCH 4/4] xblock changed attribute names from 'student' to 'user'. Need to update consumers --- lms/djangoapps/instructor/views.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lms/djangoapps/instructor/views.py b/lms/djangoapps/instructor/views.py index 00e5810800..9d5620b365 100644 --- a/lms/djangoapps/instructor/views.py +++ b/lms/djangoapps/instructor/views.py @@ -93,13 +93,13 @@ def instructor_dashboard(request, course_id): data += compute_course_stats(course).items() if request.user.is_staff: for field in course.fields: - if getattr(field.scope, 'student', False): + if getattr(field.scope, 'user', False): continue data.append([field.name, json.dumps(field.read_json(course))]) for namespace in course.namespaces: for field in getattr(course, namespace).fields: - if getattr(field.scope, 'student', False): + if getattr(field.scope, 'user', False): continue data.append(["{}.{}".format(namespace, field.name), json.dumps(field.read_json(course))])