def test_serializer_content__menui_api_context__children(self): folder_without_child = Content() folder_without_child.type = ContentType.Folder res = Context(CTX.MENU_API).toDict(folder_without_child) eq_(False, res['children']) folder_with_child = Content() folder_with_child.type = ContentType.Folder folder_without_child.parent = folder_with_child DBSession.add(folder_with_child) DBSession.add(folder_without_child) DBSession.flush() res = Context(CTX.MENU_API).toDict(folder_with_child) eq_(True, res['children']) for curtype in ContentType.all(): if curtype not in (ContentType.Folder, ContentType.Comment): item = Content() item.type = curtype fake_child = Content() fake_child.type = curtype fake_child.parent = item DBSession.add(item) DBSession.add(fake_child) DBSession.flush() res = Context(CTX.MENU_API).toDict(item) eq_(False, res['children'])
def create(self, content_type: str, workspace: Workspace, parent: Content = None, label: str = '', do_save=False, is_temporary: bool = False) -> Content: assert content_type in ContentType.allowed_types() if content_type == ContentType.Folder and not label: label = self.generate_folder_label(workspace, parent) content = Content() content.owner = self._user content.parent = parent content.workspace = workspace content.type = content_type content.label = label content.is_temporary = is_temporary content.revision_type = ActionDescription.CREATION if content.type in ( ContentType.Page, ContentType.Thread, ): content.file_extension = '.html' if do_save: DBSession.add(content) self.save(content, ActionDescription.CREATION) return content
def create(self, content_type: str, workspace: Workspace, parent: Content=None, label:str ='', do_save=False, is_temporary: bool=False) -> Content: assert content_type in ContentType.allowed_types() if content_type == ContentType.Folder and not label: label = self.generate_folder_label(workspace, parent) content = Content() content.owner = self._user content.parent = parent content.workspace = workspace content.type = content_type content.label = label content.is_temporary = is_temporary content.revision_type = ActionDescription.CREATION if content.type in ( ContentType.Page, ContentType.Thread, ): content.file_extension = '.html' if do_save: DBSession.add(content) self.save(content, ActionDescription.CREATION) return content
def test_serialize_Content_comment_THREAD(self): wor = Workspace() wor.workspace_id = 4 fol = Content() fol.type = ContentType.Folder fol.content_id = 72 fol.workspace = wor par = Content() par.type = ContentType.Thread par.content_id = 37 par.parent = fol par.workspace = wor par.created = datetime.now() obj = Content() obj.type = ContentType.Comment obj.content_id = 132 obj.label = 'some label' obj.description = 'Some Description' obj.parent = par obj.created = datetime.now() print('LANGUAGES #2 ARE', tg.i18n.get_lang()) res = Context(CTX.THREAD).toDict(obj) eq_(res.__class__, DictLikeClass, res) ok_('label' in res.keys()) eq_(obj.label, res.label, res) ok_('content' in res.keys()) eq_(obj.description, res.content, res) ok_('created' in res.keys()) ok_('icon' in res.keys()) eq_(ContentType.get_icon(obj.type), res.icon, res) ok_('delete' in res.urls.keys()) eq_(10, len(res.keys()), len(res.keys()))
def create_comment(self, workspace: Workspace=None, parent: Content=None, content:str ='', do_save=False) -> Content: assert parent and parent.type!=ContentType.Folder item = Content() item.owner = self._user item.parent = parent item.workspace = workspace item.type = ContentType.Comment item.description = content item.label = '' item.revision_type = ActionDescription.COMMENT if do_save: self.save(item, ActionDescription.COMMENT) return item
def create(self, content_type: str, workspace: Workspace, parent: Content=None, label:str ='', do_save=False) -> Content: assert content_type in ContentType.allowed_types() content = Content() content.owner = self._user content.parent = parent content.workspace = workspace content.type = content_type content.label = label content.revision_type = ActionDescription.CREATION if do_save: DBSession.add(content) self.save(content, ActionDescription.CREATION) return content
def test_serializer_content__menui_api_context__children(self): folder_without_child = Content() folder_without_child.type = ContentType.Folder folder_without_child.label = 'folder_without_child' res = Context(CTX.MENU_API).toDict(folder_without_child) eq_(False, res['children']) folder_with_child = Content() folder_with_child.type = ContentType.Folder folder_with_child.label = 'folder_with_child' folder_without_child.parent = folder_with_child DBSession.add(folder_with_child) DBSession.add(folder_without_child) DBSession.flush() res = Context(CTX.MENU_API).toDict(folder_with_child) eq_(True, res['children']) for curtype in ContentType.all(): if curtype not in (ContentType.Folder, ContentType.Comment, ContentType.Event): item = Content() item.type = curtype item.label = 'item' fake_child = Content() fake_child.type = curtype fake_child.label = 'fake_child' fake_child.parent = item DBSession.add(item) DBSession.add(fake_child) DBSession.flush() res = Context(CTX.MENU_API).toDict(item) eq_(False, res['children'])
def move(self, item: Content, new_parent: Content, must_stay_in_same_workspace:bool=True, new_workspace:Workspace=None): if must_stay_in_same_workspace: if new_parent and new_parent.workspace_id != item.workspace_id: raise ValueError('the item should stay in the same workspace') item.parent = new_parent if new_parent: item.workspace = new_parent.workspace elif new_workspace: item.workspace = new_workspace item.revision_type = ActionDescription.MOVE
def create(self, content_type: str, workspace: Workspace, parent: Content = None, label: str = '', is_temporary: bool = False, do_save=False) -> Content: assert content_type in ContentType.allowed_types() content = Content() content.owner = self._user content.parent = parent content.workspace = workspace content.type = content_type content.label = label content.is_temporary = is_temporary content.revision_type = ActionDescription.CREATION if do_save: DBSession.add(content) self.save(content, ActionDescription.CREATION) return content