def update_flags(self): response.content_type = 'application/json' ids = None if 'ids[]' in request.params: ids = [int(v) for k,v in request.params.items()\ if 'ids[]' in k] else: session['flash'] = "No ids were passed" session.save() return '{"success": false}' flags = None if 'flags[]' in request.params: flags = [v for k,v in request.params.items()\ if 'flags[]' in k] else: session['flash'] = "No flags were passed" session.save() return '{"success": false}' description = None if 'description' in request.params: description = request.params['description'] if 'user' in request.params: username = request.params['user'] else: session['flash'] = "No username was passed" session.save() return '{"success": false"}' for node_id in ids: node = Session.query(Node).filter(Node.id == node_id).first() node.flags = [] nfi = NodeFlagInfo() nfi.node = node nfi.user = Session.query(User).filter( User.name == username).first() nfi.description = description nfi.flags = Session.query(Flag)\ .filter(Flag.name.in_(flags)).all() for f in ['setup', 'hardware', 'maintenance']: if f in flags: comment = NodeComment() comment.node_id = node.id comment.user_id = nfi.user.id comment.description = description node.comments.append(comment) Session.add(node) Session.add(comment) Session.commit() break Session.add(nfi) Session.commit() session['flash'] = 'Flags were updated' session.save() return '{"success": true}'
def create_comment(self): content = None node = None if 'comment' in request.params: content = request.params['comment'] if not content: return redirect( url(controller='nodes', action='show', id=id)) if 'node' in request.params: id = request.params['node'] node = Session.query(Node)\ .filter(Node.id == id).first() if node: if not node.comments: node.comments = [] comment = NodeComment() comment.node_id = id user = Session.query(User).filter( User.id == session['active_user']['user_id']).first() comment.user_id = session['active_user']['user_id'] comment.description = content node.comments.append(comment) Session.add(node) Session.add(comment) Session.commit() return redirect(url(controller='nodes', action='show', id=id))
def create_comment(self): content = None node = None if 'comment' in request.params: content = request.params['comment'] if not content: return redirect(url(controller='nodes', action='show', id=id)) if 'node' in request.params: id = request.params['node'] node = Session.query(Node)\ .filter(Node.id == id).first() if node: if not node.comments: node.comments = [] comment = NodeComment() comment.node_id = id user = Session.query(User).filter( User.id == session['active_user']['user_id']).first() comment.user_id = session['active_user']['user_id'] comment.description = content node.comments.append(comment) Session.add(node) Session.add(comment) Session.commit() return redirect(url(controller='nodes', action='show', id=id))
def update_flags(self): response.content_type = 'application/json' ids = None if 'ids[]' in request.params: ids = [int(v) for k,v in request.params.items()\ if 'ids[]' in k] else: session['flash'] = "No ids were passed" session.save() return '{"success": false}' flags = None if 'flags[]' in request.params: flags = [v for k,v in request.params.items()\ if 'flags[]' in k] else: session['flash'] = "No flags were passed" session.save() return '{"success": false}' description = None if 'description' in request.params: description = request.params['description'] if 'user' in request.params: username = request.params['user'] else: session['flash'] = "No username was passed" session.save() return '{"success": false"}' for node_id in ids: node = Session.query(Node).filter( Node.id == node_id).first() node.flags = [] nfi = NodeFlagInfo() nfi.node = node nfi.user = Session.query(User).filter( User.name == username).first() nfi.description = description nfi.flags = Session.query(Flag)\ .filter(Flag.name.in_(flags)).all() for f in ['setup', 'hardware', 'maintenance']: if f in flags: comment = NodeComment() comment.node_id = node.id comment.user_id = nfi.user.id comment.description = description node.comments.append(comment) Session.add(node) Session.add(comment) Session.commit() break Session.add(nfi) Session.commit() session['flash'] = 'Flags were updated' session.save() return '{"success": true}'