Skip to content

Commit

Permalink
feat: add discussion reference to comments and responses
Browse files Browse the repository at this point in the history
It also adds the thread title to the thread events definition
  • Loading branch information
Ian2012 committed May 16, 2024
1 parent a09e875 commit f01286e
Show file tree
Hide file tree
Showing 8 changed files with 50 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ def get_object(self):
object_id = self.get_data('data.id', True)
object_path = self.get_data('context.path', True).rstrip('/').replace(object_id, '').rstrip('/')

kwargs = {}

if self.get_data('data.title'):
kwargs['name'] = LanguageMap({constants.EN: self.get_data('data.title')})

return Activity(
id='{lms_root_url}{object_path}/{object_id}'.format(
lms_root_url=settings.LMS_ROOT_URL,
Expand All @@ -35,9 +40,31 @@ def get_object(self):
),
definition=ActivityDefinition(
type=constants.XAPI_ACTIVITY_DISCUSSION,
**kwargs
)
)

def get_context_activities(self):
context_activities = super().get_context_activities()

discussion = self.get_data('data.discussion.id')
if not discussion:
return context_activities

context_activities.grouping = [
Activity(
id='{lms_root_url}/api/discussion/v1/threads/{discussion_id}'.format(
lms_root_url=settings.LMS_ROOT_URL,
discussion_id=discussion
),
definition=ActivityDefinition(
type=constants.XAPI_ACTIVITY_DISCUSSION,
)
)
]

return context_activities


@XApiTransformersRegistry.register('edx.forum.thread.created')
class ThreadCreatedTransformer(BaseForumThreadTransformer):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,15 @@
"type": "http://adlnet.gov/expapi/activities/course"
}
}
],
"grouping": [
{
"id": "http://localhost:18000/api/discussion/v1/threads/64d1df0887e82a002b35a6f7",
"objectType": "Activity",
"definition": {
"type": "http://id.tincanapi.com/activitytype/discussion"
}
}
]
},
"extensions": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,15 @@
"type": "http://adlnet.gov/expapi/activities/course"
}
}
],
"grouping": [
{
"id": "http://localhost:18000/api/discussion/v1/threads/64b7b2bee68f35003369092d",
"objectType": "Activity",
"definition": {
"type": "http://id.tincanapi.com/activitytype/discussion"
}
}
]
},
"extensions": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
},
"object": {
"definition": {
"name": {"en": "Another thread in test topic"},
"type": "http://id.tincanapi.com/activitytype/discussion"
},
"id": "http://localhost:18000/api/discussion/v1/threads/64abcdfee68f35002fd013c6",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
},
"object": {
"definition": {
"name": {"en": "Another thread in test topic"},
"type": "http://id.tincanapi.com/activitytype/discussion"
},
"id": "http://localhost:18000/api/discussion/v1/threads/64abcdfee68f35002fd013c6",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
},
"object": {
"definition": {
"name": {"en": "title of post"},
"type": "http://id.tincanapi.com/activitytype/discussion"
},
"id": "http://localhost:18000/api/discussion/v1/threads/64b7b2bee68f35003369092d",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
},
"object": {
"definition": {
"name": {"en": "title of post"},
"type": "http://id.tincanapi.com/activitytype/discussion"
},
"id": "http://localhost:18000/api/discussion/v1/threads/64b7b2bee68f35003369092d",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
},
"object": {
"definition": {
"name": {"en": "This is first post"},
"type": "http://id.tincanapi.com/activitytype/discussion"
},
"id": "http://localhost:18000/api/discussion/v1/comments/64a817fce68f35002fd013c3",
Expand Down

0 comments on commit f01286e

Please sign in to comment.