天天看點

edx 屬性的擷取

1. 擷取目前使用者

self.runtime.get_real_user(self.runtime.anonymous_student_id)
           

例子:擷取目前使用者的郵箱,使用者名和使用者角色

student = self.runtime.get_real_user(self.runtime.anonymous_student_id)
              studentEmail = student.email
              studentUsername = student.username
              studentIsStaff = student.is_staff //使用者角色
           

2. 擷取使用者id

def get_user_id(self):
        user_id = self.runtime.anonymous_student_id
        assert user_id is not None
        return unicode(urllib.quote(user_id))
           

3. 擷取目前使用者角色

self.runtime.get_user_role()
           

可獲得使用者角色:'instructor', 'staff',"student"

4. 擷取目前課程id

self.runtime.course_id
           

5.獲得xblock的唯一id

self.scope_ids.usage_id
           

6. 獲得指定xblock的child

Return the child identified by usage_id.

get_child(usage_id)
           

//Return instantiated XBlocks for each of this blocks 

children

.

get_children(usage_id_filter=None)
           

7.獲得目前xblock的parent

//Return the parent block of this block, or None if there isn’t one.

get_parent()
           

8. 清除child 緩存

//Clear out any cached instantiated children.

self.clear_child_cache()
           

9. 獲得xblock的資源url

//Gets the resource directory for this XBlock.

get_resources_dir()
           

參考連結:

XBLOCK API:http://edx.readthedocs.io/projects/xblock/en/latest/xblock.html

https://searchcode.com/codesearch/view/91455944/

一些屬性的調用:https://github.com/edx/edx-platform/blob/master/common/lib/xmodule/xmodule/textannotation_module.py

edx-platform-API

http://edx.readthedocs.io/projects/edx-platform-api/en/latest/courses/overview.html#courses-api-overview

繼續閱讀