def home(): from kernel import logged if not logged(): from flask import redirect return redirect('/') from kernel.models.users import select_session, Select from kernel.models.users import create_session, Create from kernel.models.core import tool_session, Tool tool_list = [] selects = select_session.query(Select.tool_id) creates = create_session.query(Create.tool_id) for i in selects: tool_list.append(i[0]) selects = tool_session.query(Tool.id, Tool.name).filter( Tool.id.in_( tool_list ) ) for i in creates: tool_list.append(i[0]) creates = tool_session.query(Tool.id, Tool.name).filter( Tool.id.in_( tool_list ) ) from flask import render_template return render_template( 'home.html', selects = selects, creates = creates )
def select(): from kernel import logged if not logged(): from flask import redirect return redirect('/') from flask import request agree = None try: tool = request.args['id'] try: agree = request.args['agree'] except Exception: pass except Exception: return 'invalid parameter(s)' if agree: if registered(tool): from flask import redirect return redirect('/tools/' + tool) else: return 'Error' from kernel.models.core import tool_session, Tool license = tool_session.query(Tool.license).filter_by(id = tool).first() if not license: return 'Not found' from flask import render_template return render_template( 'select.html', tool = tool, license = license )
def tools(): from kernel.models.core import tool_session, Tool ids = [] names = [] rows = tool_session.query(Tool.id, Tool.name) for row in rows: ids.append(row[0]) names.append(row[1]) from flask import render_template return render_template( 'tools.html', count = len(ids), ids = ids, names = names )
new_tool = Tool( name, creator, '' ) try: tool_session.add(new_tool) tool_session.commit() except Exception, e: tool_session.rollback() return None row = tool_session.query(Tool.id).\ filter_by(name = name).first() tool_id = row[0] new_create = Create( tool_id ) try: create_session.add(new_create) create_session.commit() except Exception, e: create_session.rollback() return False
def register(name, creator): from kernel.models.core import tool_session, Tool from kernel.models.users import create_session, Create new_tool = Tool(name, creator, '') try: tool_session.add(new_tool) tool_session.commit() except Exception, e: tool_session.rollback() return None row = tool_session.query(Tool.id).\ filter_by(name = name).first() tool_id = row[0] new_create = Create(tool_id) try: create_session.add(new_create) create_session.commit() except Exception, e: create_session.rollback() return False return tool_id