def login_post_controller(): username = request.forms.get('username') password = request.forms.get('password') aaa = get_aaa() aaa.login(username, password, success_redirect='/admin', fail_redirect='/admin/login')
def edit_model_get_controller(model_name, model_id): aaa = get_aaa() aaa.require(fail_redirect='/admin/login') model = site.get_model(model_name) session = sessionmaker(bind=site.engine)() obj = session.query(model.model_cls).get(model_id) if not obj: return u'{0} {1} not found'.format(model.name, model_id) obj.as_list = get_object_as_list(model, obj) return {'model': model, 'obj': obj}
def delete_model_controller(model_name, model_id): aaa = get_aaa() aaa.require(fail_redirect='/admin/login') model = site.get_model(model_name) session = sessionmaker(bind=site.engine)() obj = session.query(model.model_cls).get(model_id) if not obj: return u'{0}: {1} not found'.format(model.name, model_id) session.delete(obj) session.commit() return redirect('/admin/{0}'.format(model.name))
def delete_model_controller(model_name, model_id): aaa = get_aaa() aaa.require(fail_redirect='/admin/login') model = site.get_model(model_name) session = sessionmaker(bind=site.engine)() obj = session.query(model.model_cls).get(model_id) if not obj: return u'{0}: {1} not found'.format(model.name, model_id) session.delete(obj) session.commit() return redirect('/admin/{0}'.format(model.name))
def list_model_controller(model_name): aaa = get_aaa() aaa.require(fail_redirect='/admin/login') model = site.get_model(model_name) session = sessionmaker(bind=site.engine)() fields = model.get_select_fields() objects = list(session.query(model.model_cls.id, *fields).all()) return { 'model': model, 'results': get_objects_as_list(model, objects), }
def list_model_controller(model_name): aaa = get_aaa() aaa.require(fail_redirect='/admin/login') model = site.get_model(model_name) session = sessionmaker(bind=site.engine)() fields = model.get_select_fields() objects = list(session.query(model.model_cls.id, *fields).all()) return { 'model': model, 'results': get_objects_as_list(model, objects), }
def add_model_post_controller(model_name): aaa = get_aaa() aaa.require(fail_redirect='/admin/login') fields = dict(request.forms) model = site.get_model(model_name) session = sessionmaker(bind=site.engine)() try: obj = model.model_cls(**fields) except TypeError: return u'{0} object not created. Not enough data'.format(model_name) session.add(obj) session.commit() return redirect('/admin/{0}'.format(model.name))
def add_model_post_controller(model_name): aaa = get_aaa() aaa.require(fail_redirect='/admin/login') fields = dict(request.forms) model = site.get_model(model_name) session = sessionmaker(bind=site.engine)() try: obj = model.model_cls(**fields) except TypeError: return u'{0} object not created. Not enough data'.format(model_name) session.add(obj) session.commit() return redirect('/admin/{0}'.format(model.name))
def edit_model_get_controller(model_name, model_id): aaa = get_aaa() aaa.require(fail_redirect='/admin/login') model = site.get_model(model_name) session = sessionmaker(bind=site.engine)() obj = session.query(model.model_cls).get(model_id) if not obj: return u'{0} {1} not found'.format(model.name, model_id) obj.as_list = get_object_as_list(model, obj) return { 'model': model, 'obj': obj }
def edit_model_post_controller(model_name, model_id): aaa = get_aaa() aaa.require(fail_redirect='/admin/login') model = site.get_model(model_name) session = sessionmaker(bind=site.engine)() obj = session.query(model.model_cls).get(model_id) fields = dict(request.forms) for column, value in fields.items(): setattr(obj, column, value) if not obj: return u'{0} {1} object not found'.format(model_name, model_id) session.add(obj) session.commit() session.close() return redirect('/admin/{0}'.format(model_name))
def edit_model_post_controller(model_name, model_id): aaa = get_aaa() aaa.require(fail_redirect='/admin/login') model = site.get_model(model_name) session = sessionmaker(bind=site.engine)() obj = session.query(model.model_cls).get(model_id) fields = dict(request.forms) for column, value in fields.items(): setattr(obj, column, value) if not obj: return u'{0} {1} object not found'.format(model_name, model_id) session.add(obj) session.commit() session.close() return redirect('/admin/{0}'.format(model_name))
def add_model_get_controller(model_name): aaa = get_aaa() aaa.require(fail_redirect='/admin/login') model = site.get_model(model_name) return {'model': model}
def home_controller(): aaa = get_aaa() aaa.require(fail_redirect='/admin/login') return {'models': site.get_models()}
def logout_controller(): aaa = get_aaa() aaa.logout(success_redirect='/admin/login')
def home_controller(): aaa = get_aaa() aaa.require(fail_redirect='/admin/login') return {'models': site.get_models()}
def add_model_get_controller(model_name): aaa = get_aaa() aaa.require(fail_redirect='/admin/login') model = site.get_model(model_name) return {'model': model}
def logout_controller(): aaa = get_aaa() aaa.logout(success_redirect='/admin/login')
def login_post_controller(): username = request.forms.get('username') password = request.forms.get('password') aaa = get_aaa() aaa.login(username, password, success_redirect='/admin', fail_redirect='/admin/login')
session_opts = { 'session.type': 'file', 'session.auto': True, 'session.data_dir': './test_data' } app = SessionMiddleware(app, session_opts) session = sessionmaker(bind=engine)() role_user = Role(role='user', level=50) session.add(role_user) role_admin = Role(role='admin', level=500) session.add(role_admin) session.commit() aaa = get_aaa() hash = aaa._hash('user', '123') session.add( User(username='******', hash=hash, role='user', fullname='full', email_addr='*****@*****.**')) hash = aaa._hash('admin', '123') session.add( User(username='******', hash=hash, role='admin', fullname='admin', email_addr='*****@*****.**')) session.commit()
class ProductAdmin(ModelAdmin): list_display = ('name', 'description', 'price') site.setup(engine, app) site.register(Product, ProductAdmin) session_opts = { 'session.type': 'file', 'session.auto': True, 'session.data_dir': './test_data' } app = SessionMiddleware(app, session_opts) session = sessionmaker(bind=engine)() role_user = Role(role='user', level=50) session.add(role_user) role_admin = Role(role='admin', level=500) session.add(role_admin) session.commit() aaa = get_aaa() hash = aaa._hash('user', '123') session.add(User(username='******', hash=hash, role='user', fullname='full', email_addr='*****@*****.**')) hash = aaa._hash('admin', '123') session.add(User(username='******', hash=hash, role='admin', fullname='admin', email_addr='*****@*****.**')) session.commit()