def toolbar_xxx(request, n): wf = get_workflow() if not wf.is_manageable(n, request.user): return '' bar = nav(class_='navbar navbar-default')[ div(class_='container-fluid')[ div(class_='collapse navbar-collapse')[ ul(class_='nav navbar-nav')[ li(a('View', href=request.route_url('node-view', path=n.url))), li(a('Edit', href=request.route_url('node-edit', path=n.url))), li(a('Content', href=request.route_url('node-content', path=n.url))), li(a('Info', href=request.route_url('node-info', path=n.url))), get_add_menu(n, request), ], ul(class_='nav navbar-nav navbar-right')[ li(a('Delete')), wf.show_menu(n, request) ] ] ] ] return bar
def toolbar(request, n, workflow=None): if not request.user: return div(breadcrumb(request, n)) if not workflow: wf = get_workflow(n) else: wf = workflow if not wf.is_manageable(n, request.user): return div(breadcrumb(request, n), node_info(request, n)) bar = nav(class_='navbar navbar-default')[ div(class_='container-fluid')[ div(class_='collapse navbar-collapse')[ ul(class_='nav navbar-nav')[ li(a('View', href=request.route_url('node-view', path=n.url))), li(a('Edit', href=request.route_url('node-edit', path=n.url))), li(a('Content', href=request.route_url('node-content', path=n.url))), li(a('Info', href=request.route_url('node-info', path=n.url))), get_add_menu(n, request), ], ul(class_='nav navbar-nav navbar-right')[ li(a('Delete')), wf.show_menu(n, request) ] ] ] ] return div(breadcrumb(request, n), node_info(request, n), bar)
def add(request, node): if request.method == 'POST': # sanity check d = parse_form(request.params) new_node = PageNode() get_workflow(new_node).set_defaults(new_node, request.user, node) new_node.update(d) if not new_node.slug: new_node.generate_slug() node.add(new_node) get_dbhandler().session().flush() new_node.ordering = 19 * new_node.id if request.params['_method'].endswith('_edit'): return HTTPFound(location = request.route_url('node-edit', path=new_node.url)) return HTTPFound(location = new_node.path) # show the edit form # create a dummy node dbh = get_dbhandler() with dbh.session().no_autoflush: new_node = PageNode() new_node.parent_id = node.id new_node.site = node.site new_node.group_id = node.group_id new_node.user_id = request.user.id new_node.mimetype_id = dbh.get_ekey('text/x-rst').id eform, jscode = edit_form(new_node, request, create=True) return render_to_response('cmsfix:templates/pagenode/edit.mako', { 'parent_url': node.path, 'node': new_node, 'toolbar': '', # new node does not have toolbar yet! 'eform': eform, 'code': jscode, }, request = request )
def is_accessible(self, node, user): # journal node is accessible to owner and container's user if not user: return False print("check is_accessible()") if node.user_id == user.id: return True if isinstance(node, JournalNode): print("check parent container") if node.parent.user_id == user.id: return True if isinstance(node, JournalItemNode): return get_workflow(node.parent).is_accessible(node.parent, user) return False
def render_node_content(node, request): table_body = tbody() for n in node.children: wf = get_workflow(n) table_body.add( tr( td(literal('<input type="checkbox" name="node-ids" value="%d">' % n.id)), td(a(n.title or n.slug, href=request.route_url('node-index', path=n.url))), td(n.id), td(n.__class__.__name__), td(n.user.login), td(str(n.stamp)), td(n.lastuser.login), td( span(wf.states[n.state], class_=wf.styles[n.state]) ) ) ) content_table = table(class_='table table-condensed table-striped') content_table.add( thead( tr( th('', style="width:2em;"), th('Title'), th('ID'), th('Node type'), th('User'), th('Last modified'), th('Last user'), th('State') ) ), table_body ) content_bar = selection_bar('node-ids', action=request.route_url('node-action', path=node.url)) content_table, content_js = content_bar.render(content_table) html = row( div(content_table, class_='col-md-10') ) return render_to_response('cmsfix:templates/node/content.mako', { 'node': node, 'toolbar': get_toolbar(node, request), 'html': html, 'code': content_js, }, request = request )
def add(request, node): if request.method == 'POST': # sanity check if node.user_id != request.user.id: return error_page(request, 'Journal can only be added by its owner!') d = parse_form(request.params) n = JournalItemNode() wf = get_workflow(n) print(wf) wf.set_defaults(n, request.user, node) n.update(d) n.slug = str(time.time()) node.add(n) #n.user_id = request.user.id #n.group_id = node.group_id #n.lastuser_id = request.user.id get_dbhandler().session().flush() n.ordering = 19 * n.id if request.params['_method'].endswith('_edit'): return HTTPFound(location = request.route_url('node-edit', path=n.url)) return HTTPFound(location = request.route_url('node-index', path=n.url)) dbh = get_dbhandler() with dbh.session().no_autoflush: new_node = JournalItemNode() new_node.parent_id = node.id new_node.site = node.site new_node.user_id = request.user.id new_node.log_date = datetime.date.today() new_node.mimetype_id = dbh.get_ekey('text/x-rst').id eform, jscode = edit_form(new_node, request, create=True) return render_to_response('cmsfix:templates/node/edit.mako', { 'parent_url': '%s <%s>' % (node.title, node.path), 'node': new_node, 'toolbar': '', # new node does not have toolbar yet! 'eform': eform, 'code': jscode, }, request = request )