def get_tab_by_locator(tab_list, usage_key_string): """ Look for a tab with the specified locator. Returns the first matching tab. """ tab_location = UsageKey.from_string(usage_key_string) item = modulestore().get_item(tab_location) static_tab = StaticTab(name=item.display_name, url_slug=item.location.name) return CourseTabList.get_tab_by_id(tab_list, static_tab.tab_id)
def get_tab_by_tab_id_locator(tab_list, tab_id_locator): """ Look for a tab with the specified tab_id or locator. Returns the first matching tab. """ if 'tab_id' in tab_id_locator: tab = CourseTabList.get_tab_by_id(tab_list, tab_id_locator['tab_id']) elif 'tab_locator' in tab_id_locator: tab = get_tab_by_locator(tab_list, tab_id_locator['tab_locator']) return tab
def get_tab_by_locator(tab_list, usage_key_string): """ Look for a tab with the specified locator. Returns the first matching tab. """ tab_location = UsageKey.from_string(usage_key_string) item = modulestore().get_item(tab_location) static_tab = StaticTab( name=item.display_name, url_slug=item.location.name, ) return CourseTabList.get_tab_by_id(tab_list, static_tab.tab_id)
def get_tab_by_locator(tab_list, tab_locator): """ Look for a tab with the specified locator. Returns the first matching tab. """ tab_location = loc_mapper().translate_locator_to_location(BlockUsageLocator(tab_locator)) item = modulestore('direct').get_item(tab_location) static_tab = StaticTab( name=item.display_name, url_slug=item.location.name, ) return CourseTabList.get_tab_by_id(tab_list, static_tab.tab_id)
def get_tab_by_tab_id_locator( tab_list: List[CourseTab], tab_id_locator: Dict[str, str]) -> Optional[CourseTab]: """ Look for a tab with the specified tab_id or locator. Returns the first matching tab. """ tab = None if "tab_id" in tab_id_locator: tab = CourseTabList.get_tab_by_id(tab_list, tab_id_locator["tab_id"]) elif "tab_locator" in tab_id_locator: tab = get_tab_by_locator(tab_list, tab_id_locator["tab_locator"]) return tab
def get_tab_by_locator(tab_list, tab_locator): """ Look for a tab with the specified locator. Returns the first matching tab. """ tab_location = loc_mapper().translate_locator_to_location( BlockUsageLocator(tab_locator)) item = modulestore('direct').get_item(tab_location) static_tab = StaticTab( name=item.display_name, url_slug=item.location.name, ) return CourseTabList.get_tab_by_id(tab_list, static_tab.tab_id)
def get_tab_by_locator( tab_list: List[CourseTab], tab_location: Union[str, UsageKey]) -> Optional[CourseTab]: """ Look for a tab with the specified locator. Returns the first matching tab. """ if isinstance(tab_location, str): tab_location = UsageKey.from_string(tab_location) item = modulestore().get_item(tab_location) static_tab = StaticTab( name=item.display_name, url_slug=item.location.name, ) return CourseTabList.get_tab_by_id(tab_list, static_tab.tab_id)
def set_enabled(cls, course_key: CourseKey, enabled: bool, user: '******') -> bool: """ Enable/disable edxnotes in the modulestore. """ course = get_course_by_id(course_key) course.edxnotes = enabled if enabled: notes_tab = CourseTabList.get_tab_by_id(course.tabs, 'edxnotes') if notes_tab is None: # If the course doesn't already have the notes tab, add it. notes_tab = CourseTab.load("edxnotes") course.tabs.append(notes_tab) modulestore().update_item(course, user.id) return enabled
def set_enabled(cls, course_key: CourseKey, enabled: bool, user: '******') -> bool: """ Enabled/disables the wiki tab in the course. """ course = get_course_by_id(course_key) wiki_tab = CourseTabList.get_tab_by_id(course.tabs, 'wiki') if wiki_tab is None: if not enabled: return False # If the course doesn't already have the wiki tab, add it. wiki_tab = CourseTab.load("wiki") course.tabs.append(wiki_tab) wiki_tab.is_hidden = not enabled modulestore().update_item(course, user.id) return enabled
def calendar_edit(request, course_id): url = request.POST.get('url', '') message = request.POST.get('message', '') course_key = CourseKey.from_string(course_id) course = get_course_with_access(request.user, "load", course_key) # Find the given tab in the course tab = CourseTabList.get_tab_by_id(course.tabs, "calendar_tab") if tab is None or not bool(has_access(request.user, 'staff', course)): raise Http404("Tab with id_locator calendar_tab does not exist.") data = {'url': url, 'message': message} tab.data = json.dumps(data) modulestore().update_item(course, request.user.id) return redirect('calendar_dashboard', course_id=course.id)
def calendar_dashboard(request, course_id): course_key = CourseKey.from_string(course_id) course = get_course_with_access(request.user, "load", course_key) add_lookup('main', os.path.join(os.path.dirname(os.path.dirname(__file__)), 'calendar_tab/templates')) csrf_token = csrf(request)['csrf_token'] tab = CourseTabList.get_tab_by_id(course.tabs, "calendar_tab") is_staff = bool(has_access(request.user, 'staff', course)) try: data = json.loads(tab.data) except (TypeError, ValueError): data = {} context = { "course": course, "csrf_token": csrf_token, 'url': data.get('url', '#'), 'message': data.get('message', _('Open calendar')), 'is_staff': is_staff } return render_to_response("calendar_tab/calendar_tab.html", context)
def calendar_dashboard(request, course_id): course_key = CourseKey.from_string(course_id) course = get_course_with_access(request.user, "load", course_key) add_lookup( 'main', os.path.join(os.path.dirname(os.path.dirname(__file__)), 'calendar_tab/templates')) csrf_token = csrf(request)['csrf_token'] tab = CourseTabList.get_tab_by_id(course.tabs, "calendar_tab") is_staff = bool(has_access(request.user, 'staff', course)) try: data = json.loads(tab.data) except (TypeError, ValueError): data = {} context = { "course": course, "csrf_token": csrf_token, 'url': data.get('url', '#'), 'message': data.get('message', _('Open calendar')), 'is_staff': is_staff } return render_to_response("calendar_tab/calendar_tab.html", context)