openedx / XBlock

Framework for building custom learning components that run in the Open edX LMS!
https://docs.openedx.org/projects/xblock/en/latest/xblock-tutorial/index.html
Apache License 2.0
451 stars 216 forks source link

Unique Id for Block #218

Open cpennington opened 10 years ago

cpennington commented 10 years ago

Reported by @pmitros: "To construct useful XBlocks, I need access to a unique ID per element. Cale mentioned this is available in self.scope_ids.usage_id. This is good and useful, but entirely undocumented."

@nedbat: "Yes, let's add this to the list of useful factoids that can be retrieved from the information service, along with student name, course name, etc."

cpennington commented 10 years ago

I'm not sure it makes sense to have general "information service". I'd rather be more specific/selective, and have services for info about the course, about the current user, and perhaps about the block. Although, simply exposing self.scope_ids.usage_id (or a function of that) as a known unique id (without getting a service involved) seems reasonable to me as well. In particular, the fact that that id is unique is a property of the general XBlock structure, rather than optional functionality that only some runtimes might provide.

pmitros commented 10 years ago

I'd tend to agree with cpennington. This feels core. I'd rather have this available in the XBlock than in an external service. It's not really clear how to write a lot of the client-side code clearly, in particular, without having unique IDs if there are multiple of the same type of XBlock on the same page.

My personal preference would be towards something like self.usage or self.id. This would (1) be concise and readable to use (2) developers learning the framework could find it through introspection (.dict), rather than introspection on class members or looking for services (3) we wouldn't be exposing the scope_ids data structure (4) it could easilt be exposed in the string representation of the XBlock on the console when printing it, for debugging.

taniwallach commented 3 years ago

This issue is quite old, but in case someone finds it, the Fields API allows initializing a field with default = xblock.fields.UNIQUE_ID which sets a "scope" suitable UID.

See:

@cpennington, @pmitros - I assume that due to code from https://github.com/edx/XBlock/pull/249 this issue should be closed.

pmitros commented 3 years ago

@taniwallach I believe @cpennington is now at Reify Health (and sports an awesome beard). I'm also no longer actively involved in Open edX development (and don't appear to have commit access anymore).