def _list_and_format_file_list( handler, title, subfolder, tab_name, links=False, upload=False, prefix=None, caption_if_empty='< none >', edit_url_template=None, merge_local_files=False, all_paths=None): """Walks files in folders and renders their names in a section.""" assets = [] can_upload = upload and handler.app_context.is_editable_fs() upload_url = 'dashboard?{}'.format(urllib.urlencode({ 'action': 'manage_asset', 'from_action': handler.request.get('action'), 'type': tab_name, 'key': subfolder})) # keep a list of files without merging unmerged_files = {} if merge_local_files: unmerged_files = dashboard_utils.list_files( handler.app_context, subfolder, all_paths=all_paths, merge_local_files=False) for filename in dashboard_utils.list_files( handler.app_context, subfolder, all_paths=all_paths, merge_local_files=merge_local_files): if prefix and not filename.startswith(prefix): continue overridden = (filename in unmerged_files) or (not merge_local_files) if edit_url_template and handler.app_context.fs.impl.is_read_write(): edit_url = edit_url_template % ( tab_name, urllib.quote(filename), handler.request.get('action')) else: edit_url = None assets.append(Asset(filename, overridden, edit_url)) overridden_assets = [asset for asset in assets if asset.overridden] inherited_assets = [asset for asset in assets if not asset.overridden] return safe_dom.Template( jinja_utils.get_template('asset_list.html', [TEMPLATE_DIR]), inherited_assets=inherited_assets, overridden_assets=overridden_assets, can_upload=can_upload, caption_if_empty=caption_if_empty, upload_url=upload_url, links=links)
def _get_about_course(handler): # Basic course info. template_values = {} course_info = [] course_actions = [] app_context = handler.app_context if not app_context.is_editable_fs(): course_info.append('The course is read-only.') currentCourse = courses.Course(handler) course_info.append('Schema Version: %s' % currentCourse.version) course_info.append('Context Path: %s' % app_context.get_slug()) course_info.append('Datastore Namespace: %s' % app_context.get_namespace_name()) # Course file system. fs = app_context.fs.impl course_info.append(('File System: %s' % fs.__class__.__name__)) if fs.__class__ == vfs.LocalReadOnlyFileSystem: course_info.append(('Home Folder: %s' % sites.abspath(app_context.get_home_folder(), '/'))) data_info = dashboard_utils.list_files(handler, '/data/') sections = [ { 'description': messages.ABOUT_THE_COURSE_DESCRIPTION, 'actions': course_actions, 'children': course_info }, ] if currentCourse.version == courses.COURSE_MODEL_VERSION_1_2: sections.append({ 'title': 'Data Files', 'description': messages.DATA_FILES_DESCRIPTION, 'children': data_info }) template_values['alerts'] = handler.get_alerts() template_values['sections'] = sections return template_values
def _get_about_course(handler): # Basic course info. template_values = {} course_info = [] course_actions = [] app_context = handler.app_context if not app_context.is_editable_fs(): course_info.append('The course is read-only.') currentCourse = courses.Course(handler) course_info.append('Schema Version: %s' % currentCourse.version) course_info.append('Context Path: %s' % app_context.get_slug()) course_info.append('Datastore Namespace: %s' % app_context.get_namespace_name()) # Course file system. fs = app_context.fs.impl course_info.append(('File System: %s' % fs.__class__.__name__)) if fs.__class__ == vfs.LocalReadOnlyFileSystem: course_info.append(('Home Folder: %s' % sites.abspath( app_context.get_home_folder(), '/'))) data_info = dashboard_utils.list_files(handler, '/data/') sections = [ { 'description': messages.ABOUT_THE_COURSE_DESCRIPTION, 'actions': course_actions, 'children': course_info},] if currentCourse.version == courses.COURSE_MODEL_VERSION_1_2: sections.append({ 'title': 'Data Files', 'description': messages.DATA_FILES_DESCRIPTION, 'children': data_info}) template_values['alerts'] = handler.get_alerts() template_values['sections'] = sections return template_values
def _list_and_format_file_list( handler, title, subfolder, tab_name, links=False, upload=False, prefix=None, caption_if_empty='< none >', edit_url_template=None, merge_local_files=False, sub_title=None, all_paths=None): """Walks files in folders and renders their names in a section.""" # keep a list of files without merging unmerged_files = {} if merge_local_files: unmerged_files = dashboard_utils.list_files( handler, subfolder, merge_local_files=False, all_paths=all_paths) items = safe_dom.NodeList() count = 0 for filename in dashboard_utils.list_files( handler, subfolder, merge_local_files=merge_local_files, all_paths=all_paths): if prefix and not filename.startswith(prefix): continue # make a <li> item li = safe_dom.Element('li') if links: url = urllib.quote(filename) li.add_child(safe_dom.Element( 'a', href=url).add_text(filename)) else: li.add_text(filename) # add actions if available if (edit_url_template and handler.app_context.fs.impl.is_read_write()): li.add_child(safe_dom.Entity(' ')) edit_url = edit_url_template % ( tab_name, urllib.quote(filename), handler.request.get('action')) # show [overridden] + edit button if override exists if (filename in unmerged_files) or (not merge_local_files): li.add_text('[Overridden]').add_child( dashboard_utils.create_edit_button(edit_url)) # show an [override] link otherwise else: li.add_child(safe_dom.A(edit_url).add_text('[Override]')) count += 1 items.append(li) output = safe_dom.NodeList() if handler.app_context.is_editable_fs() and upload: output.append( safe_dom.Element( 'a', className='gcb-button gcb-icon-button', href='dashboard?%s' % urllib.urlencode( {'action': 'manage_asset', 'from_action': handler.request.get('action'), 'type': tab_name, 'key': subfolder}), id='upload-button', ).append( safe_dom.Element('span', className='icon md-file-upload') ).append( safe_dom.Element('span').add_text(" Upload") ) ) if sub_title: output.append(safe_dom.Element( 'div', className='gcb-message').add_text(sub_title)) if items: output.append(safe_dom.Element('ol').add_children(items)) else: if caption_if_empty: output.append( safe_dom.Element( 'div', className='gcb-message').add_text(caption_if_empty)) return output
def list_files(app_context): return dashboard_utils.list_files(app_context, '/data/')
def _list_and_format_file_list( handler, title, subfolder, tab_name, links=False, upload=False, prefix=None, caption_if_empty='< none >', edit_url_template=None, merge_local_files=False, sub_title=None, all_paths=None): """Walks files in folders and renders their names in a section.""" # keep a list of files without merging unmerged_files = {} if merge_local_files: unmerged_files = dashboard_utils.list_files( handler, subfolder, merge_local_files=False, all_paths=all_paths) items = safe_dom.NodeList() count = 0 for filename in dashboard_utils.list_files( handler, subfolder, merge_local_files=merge_local_files, all_paths=all_paths): if prefix and not filename.startswith(prefix): continue # make a <li> item li = safe_dom.Element('li') if links: url = urllib.quote(filename) li.add_child(safe_dom.Element( 'a', href=url).add_text(filename)) else: li.add_text(filename) # add actions if available if (edit_url_template and handler.app_context.fs.impl.is_read_write()): li.add_child(safe_dom.Entity(' ')) edit_url = edit_url_template % ( tab_name, urllib.quote(filename)) # show [overridden] + edit button if override exists if (filename in unmerged_files) or (not merge_local_files): li.add_text('[Overridden]').add_child( dashboard_utils.create_edit_button(edit_url)) # show an [override] link otherwise else: li.add_child(safe_dom.A(edit_url).add_text('[Override]')) count += 1 items.append(li) output = safe_dom.NodeList() if handler.app_context.is_editable_fs() and upload: output.append( safe_dom.Element( 'a', className='gcb-button gcb-pull-right', href='dashboard?%s' % urllib.urlencode( {'action': 'manage_asset', 'tab': tab_name, 'key': subfolder}) ).add_text( 'Upload to ' + subfolder.lstrip('/').rstrip('/')) ).append( safe_dom.Element( 'div', style='clear: both; padding-top: 2px;' ) ) if title: h3 = safe_dom.Element('h3') if count: h3.add_text('%s (%s)' % (title, count)) else: h3.add_text(title) output.append(h3) if sub_title: output.append(safe_dom.Element('blockquote').add_text(sub_title)) if items: output.append(safe_dom.Element('ol').add_children(items)) else: if caption_if_empty: output.append( safe_dom.Element('blockquote').add_text(caption_if_empty)) return output
def _get_about_course(handler): # Basic course info. template_values = {} course_info = [] course_actions = [] app_context = handler.app_context if not app_context.is_editable_fs(): course_info.append('The course is read-only.') else: if app_context.now_available: if app_context.get_environ()['course']['browsable']: browsable = True course_browsability_caption = ( 'Hide Course From Unregistered Users') course_info.append('The course is is browsable by ' 'un-registered users') else: browsable = False course_browsability_caption = ( 'Allow Unregistered Users to Browse Course') course_info.append('The course is not visible to ' 'un-registered users.') course_actions.append({ 'id': 'course_browsability', 'caption': course_browsability_caption, 'action': handler.get_action_url('course_browsability'), 'xsrf_token': crypto.XsrfTokenManager.create_xsrf_token( 'course_browsability'), 'params': {'browsability': not browsable}, }) currentCourse = courses.Course(handler) course_info.append('Schema Version: %s' % currentCourse.version) course_info.append('Context Path: %s' % app_context.get_slug()) course_info.append('Datastore Namespace: %s' % app_context.get_namespace_name()) # Course file system. fs = app_context.fs.impl course_info.append(('File System: %s' % fs.__class__.__name__)) if fs.__class__ == vfs.LocalReadOnlyFileSystem: course_info.append(('Home Folder: %s' % sites.abspath( app_context.get_home_folder(), '/'))) data_info = dashboard_utils.list_files(handler, '/data/') sections = [ { 'title': 'About the Course', 'description': messages.ABOUT_THE_COURSE_DESCRIPTION, 'actions': course_actions, 'children': course_info},] if currentCourse.version == courses.COURSE_MODEL_VERSION_1_2: sections.append({ 'title': 'Data Files', 'description': messages.DATA_FILES_DESCRIPTION, 'children': data_info}) template_values['alerts'] = handler.get_alerts() template_values['sections'] = sections return template_values