Пример #1
0
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')
Пример #2
0
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}
Пример #3
0
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))
Пример #4
0
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))
Пример #5
0
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),
    }
Пример #6
0
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),
    }
Пример #7
0
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))
Пример #8
0
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))
Пример #9
0
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
    }
Пример #10
0
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))
Пример #11
0
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))
Пример #12
0
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}
Пример #13
0
def home_controller():
    aaa = get_aaa()
    aaa.require(fail_redirect='/admin/login')
    return {'models': site.get_models()}
Пример #14
0
def logout_controller():
    aaa = get_aaa()
    aaa.logout(success_redirect='/admin/login')
Пример #15
0
def home_controller():
    aaa = get_aaa()
    aaa.require(fail_redirect='/admin/login')
    return {'models': site.get_models()}
Пример #16
0
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}
Пример #17
0
def logout_controller():
    aaa = get_aaa()
    aaa.logout(success_redirect='/admin/login')
Пример #18
0
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')
Пример #19
0
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()
Пример #20
0
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()