def node(data, parent=None): new_node = None # Create topics if data['kind_id'] == "topic": new_node = cc.ContentNode(kind=topic(), parent=parent, title=data['title'], node_id=data['node_id']) new_node.save() for child in data['children']: child_node = node(child, parent=new_node) # Create videos elif data['kind_id'] == "video": new_node = cc.ContentNode(kind=video(), parent=parent, title=data['title'], node_id=data['node_id'], license=license_wtfpl()) new_node.save() video_file = fileobj_video(contents="Video File") video_file.contentnode = new_node video_file.preset_id = format_presets.VIDEO_HIGH_RES video_file.save() # Create exercises elif data['kind_id'] == "exercise": extra_fields = "{{\"mastery_model\":\"{}\",\"randomize\":true,\"m\":{},\"n\":{}}}".format( data['mastery_model'], data.get('m') or 0, data.get('n') or 0) new_node = cc.ContentNode(kind=exercise(), parent=parent, title=data['title'], node_id=data['node_id'], license=license_wtfpl(), extra_fields=extra_fields) new_node.save() for assessment_item in data['assessment_items']: mixer.blend(cc.AssessmentItem, contentnode=new_node, assessment_id=assessment_item['assessment_id'], question=assessment_item['question'], type=assessment_item['type'], answers=json.dumps(assessment_item['answers'])) return new_node
def setUp(self): super(NodeSettingTestCase, self).setUp() # Set up ricecooker trees self.channel.staging_tree = cc.ContentNode(kind_id=content_kinds.TOPIC, title="test", node_id="aaa") self.channel.staging_tree.save() self.channel.previous_tree = cc.ContentNode( kind_id=content_kinds.TOPIC, title="test", node_id="bbb") self.channel.previous_tree.save() self.channel.chef_tree = cc.ContentNode(kind_id=content_kinds.TOPIC, title="test", node_id="ccc") self.channel.chef_tree.save() self.channel.save() self.contentnode = cc.ContentNode.objects.create(kind_id="video")
def setUp(self): super(NodeSettingTestCase, self).setUp() # Set up ricecooker trees self.channel.staging_tree = cc.ContentNode(kind_id=content_kinds.TOPIC, title="test", node_id="aaa") self.channel.staging_tree.save() self.channel.previous_tree = cc.ContentNode( kind_id=content_kinds.TOPIC, title="test", node_id="bbb") self.channel.previous_tree.save() self.channel.chef_tree = cc.ContentNode(kind_id=content_kinds.TOPIC, title="test", node_id="ccc") self.channel.chef_tree.save() self.channel.save() request = self.create_post_request( reverse_lazy('file_create'), {'file': SimpleUploadedFile("file.pdf", b"contents")}) self.file_response = file_create(request)
def node(data, parent=None): new_node = None # Create topics if data['kind_id'] == "topic": new_node = cc.ContentNode( kind=topic(), parent=parent, title=data['title'], node_id=data['node_id'], content_id=data.get('content_id') or data['node_id'], sort_order=data.get('sort_order', 1), ) new_node.save() for child in data['children']: node(child, parent=new_node) # Create videos elif data['kind_id'] == "video": new_node = cc.ContentNode( kind=video(), parent=parent, title=data['title'], node_id=data['node_id'], license=license_wtfpl(), content_id=data.get('content_id') or data['node_id'], sort_order=data.get('sort_order', 1), ) new_node.save() video_file = fileobj_video(contents="Video File") video_file.contentnode = new_node video_file.preset_id = format_presets.VIDEO_HIGH_RES video_file.save() # Create exercises elif data['kind_id'] == "exercise": extra_fields = { 'mastery_model': data['mastery_model'], 'randomize': True, 'm': data.get('m') or 0, 'n': data.get('n') or 0 } new_node = cc.ContentNode( kind=exercise(), parent=parent, title=data['title'], node_id=data['node_id'], license=license_wtfpl(), extra_fields=extra_fields, content_id=data.get('content_id') or data['node_id'], sort_order=data.get('sort_order', 1), ) new_node.save() for assessment_item in data['assessment_items']: ai = cc.AssessmentItem( contentnode=new_node, assessment_id=assessment_item['assessment_id'], question=assessment_item['question'], type=assessment_item['type'], answers=json.dumps(assessment_item['answers']), hints=json.dumps(assessment_item.get('hints') or []) ) ai.save() if data.get('tags'): for tag in data['tags']: t = cc.ContentTag(tag_name=tag['tag_name']) t.save() new_node.tags.add(t) new_node.save() return new_node