def get_one(self, workspace_id): user = tmpl_context.current_user current_user_content = Context(CTX.CURRENT_USER).toDict(user) current_user_content.roles.sort(key=lambda role: role.workspace.name) workspace_api = WorkspaceApi(user) workspace = workspace_api.get_one(workspace_id) dictified_current_user = Context(CTX.CURRENT_USER).toDict(user) dictified_folders = self.folders.get_all_fake(workspace).result fake_api = DictLikeClass( current_user=dictified_current_user, current_workspace_folders=dictified_folders, current_user_workspace_role=workspace.get_user_role(user) ) fake_api.sub_items = Context(CTX.FOLDER_CONTENT_LIST).toDict( # TODO BS 20161209: Is the correct way to grab folders? No use API? workspace.get_valid_children(ContentApi.DISPLAYABLE_CONTENTS) ) dictified_workspace = Context(CTX.WORKSPACE).toDict(workspace, 'workspace') webdav_url = CFG.get_instance().WSGIDAV_CLIENT_BASE_URL return DictLikeClass( result=dictified_workspace, fake_api=fake_api, webdav_url=webdav_url, )
def put(self, id, name, description, calendar_enabled: str = 'off'): user = tmpl_context.current_user workspace_api_controller = WorkspaceApi(user) calendar_enabled = on_off_to_boolean(calendar_enabled) workspace = workspace_api_controller.get_one(id) # Display error page to user if chosen label is in conflict if name != workspace.label and \ not self._path_validation.workspace_label_is_free(name): return render_invalid_integrity_chosen_path(name) workspace.label = name workspace.description = description workspace.calendar_enabled = calendar_enabled workspace_api_controller.save(workspace) if calendar_enabled: workspace_api_controller.ensure_calendar_exist(workspace) else: workspace_api_controller.disable_calendar(workspace) tg.flash( _('{} workspace updated.').format(workspace.label), CST.STATUS_OK) tg.redirect(self.url(workspace.workspace_id)) return
def edit(self, id): user = tmpl_context.current_user workspace_api_controller = WorkspaceApi(user) workspace = workspace_api_controller.get_one(id) dictified_workspace = Context(CTX.ADMIN_WORKSPACE).toDict(workspace, 'workspace') return DictLikeClass(result = dictified_workspace)
def edit(self, id): user = tmpl_context.current_user workspace_api_controller = WorkspaceApi(user) workspace = workspace_api_controller.get_one(id) dictified_workspace = Context(CTX.ADMIN_WORKSPACE).toDict(workspace, 'workspace') return DictLikeClass(result = dictified_workspace)
def disable_notifications(self, workspace_id, next_url=None): workspace_id = int(workspace_id) api = WorkspaceApi(tg.tmpl_context.current_user) workspace = api.get_one(workspace_id) api.disable_notifications(tg.tmpl_context.current_user, workspace) tg.flash(_('Notification disabled for workspace {}').format(workspace.label)) if next_url: tg.redirect(tg.url(next_url)) tg.redirect(self.parent_controller.url(None, 'me'))
def mark_read(self, workspace_id, **kwargs): user = tmpl_context.current_user workspace_api = WorkspaceApi(user) workspace = workspace_api.get_one(workspace_id) content_api = ContentApi(user) content_api.mark_read__workspace(workspace) tg.redirect('/workspaces/{}'.format(workspace_id)) return DictLikeClass(fake_api=fake_api)
def disable_notifications(self, workspace_id, next_url=None): workspace_id = int(workspace_id) api = WorkspaceApi(tg.tmpl_context.current_user) workspace = api.get_one(workspace_id) api.disable_notifications(tg.tmpl_context.current_user, workspace) tg.flash(_('Notification disabled for workspace {}').format(workspace.label)) if next_url: tg.redirect(tg.url(next_url)) tg.redirect(self.parent_controller.url(None, 'me'))
def post_delete(self, workspace_id): workspace_id = int(workspace_id) api = WorkspaceApi(tg.tmpl_context.current_user) workspace = api.get_one(workspace_id) api.delete_one(workspace_id) workspace_label = workspace.label undo_url = self.url(workspace_id, self.restore.__name__) tg.flash(_('{} workspace deleted. In case of error, you can <a class="alert-link" href="{}">restore it</a>.').format(workspace_label, undo_url), CST.STATUS_OK, no_escape=True) tg.redirect(self.url())
def current_workspace(cls) -> Workspace: """ To be used by other conrtollers in order to setup workspace instance in the context """ workspace_api = WorkspaceApi(tg.tmpl_context.current_user) workspace_id = int(tg.request.controller_state.routing_args.get('workspace_id')) workspace = workspace_api.get_one(workspace_id) tg.tmpl_context.workspace_id = workspace_id tg.tmpl_context.workspace = workspace return workspace
def get_one(self, workspace_id, **kwargs): """ :param workspace_id: Displayed workspace id :param kwargs: * show_deleted: bool: Display deleted contents or hide them if False * show_archived: bool: Display archived contents or hide them if False """ show_deleted = str_as_bool(kwargs.get('show_deleted', False)) show_archived = str_as_bool(kwargs.get('show_archived', '')) user = tmpl_context.current_user workspace_api = WorkspaceApi(user) workspace = workspace_api.get_one(workspace_id) unread_contents = ContentApi(user).get_last_unread(None, ContentType.Any, workspace=workspace) current_user_content = Context(CTX.CURRENT_USER).toDict(user) current_user_content.roles.sort(key=lambda role: role.workspace.name) dictified_current_user = Context(CTX.CURRENT_USER).toDict(user) dictified_folders = self.folders.get_all_fake(workspace).result fake_api = DictLikeClass( last_unread=Context(CTX.CONTENT_LIST).toDict(unread_contents, 'contents', 'nb'), current_user=dictified_current_user, current_workspace_folders=dictified_folders, current_user_workspace_role=workspace.get_user_role(user) ) fake_api.sub_items = Context(CTX.FOLDER_CONTENT_LIST).toDict( # TODO BS 20161209: Is the correct way to grab folders? No use API? workspace.get_valid_children( ContentApi.DISPLAYABLE_CONTENTS, show_deleted=show_deleted, show_archived=show_archived, ) ) dictified_workspace = Context(CTX.WORKSPACE).toDict(workspace, 'workspace') webdav_url = CFG.get_instance().WSGIDAV_CLIENT_BASE_URL return DictLikeClass( result=dictified_workspace, fake_api=fake_api, webdav_url=webdav_url, show_deleted=show_deleted, show_archived=show_archived, )
def current_workspace(cls) -> Workspace: """ To be used by other conrtollers in order to setup workspace instance in the context """ workspace_api = WorkspaceApi(tg.tmpl_context.current_user) workspace_id = int(tg.request.controller_state.routing_args.get('workspace_id')) workspace = workspace_api.get_one(workspace_id) tg.tmpl_context.workspace_id = workspace_id tg.tmpl_context.workspace = workspace return workspace
def post_delete(self, workspace_id): workspace_id = int(workspace_id) api = WorkspaceApi(tg.tmpl_context.current_user) workspace = api.get_one(workspace_id) api.delete_one(workspace_id) workspace_label = workspace.label undo_url = self.url(workspace_id, self.restore.__name__) tg.flash(_('{} workspace deleted. In case of error, you can <a class="alert-link" href="{}">restore it</a>.').format(workspace_label, undo_url), CST.STATUS_OK, no_escape=True) tg.redirect(self.url())
def put(self, id, name, description): user = tmpl_context.current_user workspace_api_controller = WorkspaceApi(user) workspace = workspace_api_controller.get_one(id) workspace.label = name workspace.description = description workspace_api_controller.save(workspace) tg.flash(_('{} workspace updated.').format(workspace.label), CST.STATUS_OK) tg.redirect(self.url(workspace.workspace_id)) return
def _before(self, *args, **kw): """ Instantiate the current workspace in tg.tmpl_context :param args: :param kw: :return: """ super(self.__class__, self)._before(args, kw) workspace_api = WorkspaceApi(tg.tmpl_context.current_user) workspace_id = tg.request.controller_state.routing_args.get('workspace_id') workspace = workspace_api.get_one(workspace_id) tg.tmpl_context.workspace_id = workspace_id tg.tmpl_context.workspace = workspace
def put(self, id, name, description, calendar_enabled: str='off'): user = tmpl_context.current_user workspace_api_controller = WorkspaceApi(user) calendar_enabled = on_off_to_boolean(calendar_enabled) workspace = workspace_api_controller.get_one(id) workspace.label = name workspace.description = description workspace.calendar_enabled = calendar_enabled workspace_api_controller.save(workspace) tg.flash(_('{} workspace updated.').format(workspace.label), CST.STATUS_OK) tg.redirect(self.url(workspace.workspace_id)) return
def _before(self, *args, **kw): """ Instantiate the current workspace in tg.tmpl_context :param args: :param kw: :return: """ super(self.__class__, self)._before(args, kw) workspace_api = WorkspaceApi(tg.tmpl_context.current_user) workspace_id = tg.request.controller_state.routing_args.get('workspace_id') workspace = workspace_api.get_one(workspace_id) tg.tmpl_context.workspace_id = workspace_id tg.tmpl_context.workspace = workspace
def put(self, id, name, description, calendar_enabled: str = 'off'): user = tmpl_context.current_user workspace_api_controller = WorkspaceApi(user) calendar_enabled = on_off_to_boolean(calendar_enabled) workspace = workspace_api_controller.get_one(id) workspace.label = name workspace.description = description workspace.calendar_enabled = calendar_enabled workspace_api_controller.save(workspace) tg.flash( _('{} workspace updated.').format(workspace.label), CST.STATUS_OK) tg.redirect(self.url(workspace.workspace_id)) return
def get_one(self, workspace_id): user = tmpl_context.current_user workspace_api_controller = WorkspaceApi(user) role_api = RoleApi(tg.tmpl_context.current_user) user_api = UserApi(tg.tmpl_context.current_user) workspace = workspace_api_controller.get_one(workspace_id) role_list = role_api.get_roles_for_select_field() user_list = user_api.get_all() current_user_content = Context(CTX.CURRENT_USER).toDict(user) dictified_workspace = Context(CTX.ADMIN_WORKSPACE).toDict(workspace, 'workspace') fake_api_content = DictLikeClass(role_types=role_list, users=user_list, current_user=current_user_content) fake_api = Context(CTX.ADMIN_WORKSPACE).toDict(fake_api_content) return dict(result = dictified_workspace, fake_api = fake_api)
def get_one(self, workspace_id): user = tmpl_context.current_user workspace_api_controller = WorkspaceApi(user) role_api = RoleApi(tg.tmpl_context.current_user) user_api = UserApi(tg.tmpl_context.current_user) workspace = workspace_api_controller.get_one(workspace_id) role_list = role_api.get_roles_for_select_field() user_list = user_api.get_all() current_user_content = Context(CTX.CURRENT_USER).toDict(user) dictified_workspace = Context(CTX.ADMIN_WORKSPACE).toDict(workspace, 'workspace') fake_api_content = DictLikeClass(role_types=role_list, users=user_list, current_user=current_user_content) fake_api = Context(CTX.ADMIN_WORKSPACE).toDict(fake_api_content) return dict(result = dictified_workspace, fake_api = fake_api)
def get_one(self, workspace_id): user = tmpl_context.current_user current_user_content = Context(CTX.CURRENT_USER).toDict(user) current_user_content.roles.sort(key=lambda role: role.workspace.name) workspace_api = WorkspaceApi(user) workspace = workspace_api.get_one(workspace_id) dictified_current_user = Context(CTX.CURRENT_USER).toDict(user) dictified_folders = self.folders.get_all_fake(workspace).result fake_api = DictLikeClass(current_user=dictified_current_user, current_workspace_folders=dictified_folders)\ # , # sub_items=Context(CTX.FOLDER_CONTENT_LIST).toDict(dictified_folders)) fake_api.sub_items = Context(CTX.FOLDER_CONTENT_LIST).toDict(workspace.get_valid_children()) dictified_workspace = Context(CTX.WORKSPACE).toDict(workspace, 'workspace') return DictLikeClass(result = dictified_workspace, fake_api=fake_api)
def put(self, id, name, description, calendar_enabled: str='off'): user = tmpl_context.current_user workspace_api_controller = WorkspaceApi(user) calendar_enabled = on_off_to_boolean(calendar_enabled) workspace = workspace_api_controller.get_one(id) # Display error page to user if chosen label is in conflict if name != workspace.label and \ not self._path_validation.workspace_label_is_free(name): return render_invalid_integrity_chosen_path(name) workspace.label = name workspace.description = description workspace.calendar_enabled = calendar_enabled workspace_api_controller.save(workspace) if calendar_enabled: workspace_api_controller.ensure_calendar_exist(workspace) tg.flash(_('{} workspace updated.').format(workspace.label), CST.STATUS_OK) tg.redirect(self.url(workspace.workspace_id)) return
def get_one(self, workspace_id): user = tmpl_context.current_user current_user_content = Context(CTX.CURRENT_USER).toDict(user) current_user_content.roles.sort(key=lambda role: role.workspace.name) workspace_api = WorkspaceApi(user) workspace = workspace_api.get_one(workspace_id) dictified_current_user = Context(CTX.CURRENT_USER).toDict(user) dictified_folders = self.folders.get_all_fake(workspace).result fake_api = DictLikeClass( current_user=dictified_current_user, current_workspace_folders=dictified_folders, current_user_workspace_role=workspace.get_user_role(user)) fake_api.sub_items = Context(CTX.FOLDER_CONTENT_LIST).toDict( workspace.get_valid_children(ContentApi.DISPLAYABLE_CONTENTS)) dictified_workspace = Context(CTX.WORKSPACE).toDict( workspace, 'workspace') return DictLikeClass(result=dictified_workspace, fake_api=fake_api)