Skip to content

Commit

Permalink
Allow SGA blocks to be used in Libraries v2 context [FC-0076] (#363)
Browse files Browse the repository at this point in the history
* fix: use context_key instead of course_id

as it means the same thing (in the course context), and is provided as
part of xblock.core

* fix: work around errors preventing block preview in library context

* `start` attribute does not exist in library context
* catch errors for fields scoped outside "content" or "settings"

* chore: bump package version
  • Loading branch information
pomegranited authored Feb 21, 2025
1 parent 8b14d72 commit 1f0487e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
2 changes: 1 addition & 1 deletion edx_sga/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
Module for StaffGradedAssignmentXBlock.
"""

__version__ = "0.25.0"
__version__ = "0.25.1"
17 changes: 12 additions & 5 deletions edx_sga/sga.py
Original file line number Diff line number Diff line change
Expand Up @@ -644,8 +644,10 @@ def block_id(self):
def block_course_id(self):
"""
Return the course_id of the block.
Note: if this block is used in a Content Library, the returned ID will be the library's ID.
"""
return str(self.course_id)
return str(self.context_key)

def get_student_item_dict(self, student_id=None):
"""
Expand Down Expand Up @@ -698,13 +700,18 @@ def update_staff_debug_context(self, context):
"""
Add context info for the Staff Debug interface.
"""
published = self.start
published = getattr(self, 'start', None)
context["is_released"] = published and published < utcnow()
context["location"] = self.location
context["category"] = type(self).__name__
context["fields"] = [
(name, field.read_from(self)) for name, field in self.fields.items()
]
context["fields"] = []

for name, field in self.fields.items():
try:
context["fields"].append((name, field.read_from(self)))
# Library blocks only support the content and settings scopes
except NotImplementedError:
pass

def get_student_module(self, module_id):
"""
Expand Down

0 comments on commit 1f0487e

Please sign in to comment.