Commit 3e65a688 by Chris Dodge

auto generate the discussion id on create. Also add 'discussion_id' to the list…

auto generate the discussion id on create. Also add 'discussion_id' to the list of 'system-metadata' so that end users cannot edit it
parent b54ebb34
...@@ -9,6 +9,7 @@ from fs.osfs import OSFS ...@@ -9,6 +9,7 @@ from fs.osfs import OSFS
from itertools import repeat from itertools import repeat
from path import path from path import path
from datetime import datetime, timedelta from datetime import datetime, timedelta
from uuid import uuid4
from importlib import import_module from importlib import import_module
from xmodule.errortracker import null_error_tracker, exc_info_to_str from xmodule.errortracker import null_error_tracker, exc_info_to_str
...@@ -496,6 +497,12 @@ class MongoModuleStore(ModuleStoreBase): ...@@ -496,6 +497,12 @@ class MongoModuleStore(ModuleStoreBase):
""" """
try: try:
source_item = self.collection.find_one(location_to_query(source)) source_item = self.collection.find_one(location_to_query(source))
# allow for some programmatically generated substitutions in metadata, e.g. Discussion_id's should be auto-generated
for key in source_item['metadata'].keys():
if source_item['metadata'][key] == '$$GUID$$':
source_item['metadata'][key] = uuid4().hex
source_item['_id'] = Location(location).dict() source_item['_id'] = Location(location).dict()
self.collection.insert(source_item) self.collection.insert(source_item)
item = self._load_items([source_item])[0] item = self._load_items([source_item])[0]
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
metadata: metadata:
display_name: Discussion Tag display_name: Discussion Tag
for: Topic-Level Student-Visible Label for: Topic-Level Student-Visible Label
id: 6002x_group_discussion_by_this id: $$GUID$$
discussion_category: Week 1 discussion_category: Week 1
data: | data: |
<discussion /> <discussion />
......
...@@ -340,7 +340,7 @@ class XModuleDescriptor(XModuleFields, HTMLSnippet, ResourceTemplates, XBlock): ...@@ -340,7 +340,7 @@ class XModuleDescriptor(XModuleFields, HTMLSnippet, ResourceTemplates, XBlock):
# cdodge: this is a list of metadata names which are 'system' metadata # cdodge: this is a list of metadata names which are 'system' metadata
# and should not be edited by an end-user # and should not be edited by an end-user
system_metadata_fields = ['data_dir', 'published_date', 'published_by', 'is_draft'] system_metadata_fields = ['data_dir', 'published_date', 'published_by', 'is_draft', 'discussion_id']
# A list of descriptor attributes that must be equal for the descriptors to # A list of descriptor attributes that must be equal for the descriptors to
# be equal # be equal
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment