def dashboard(rdb): models = [] obj = rdb.hgetall('models') for itm in obj: model = Model.from_json(obj[itm]) models.append(model) return template("admin/dashboard.tpl", models=models)
def model_new(model_name, rdb): jsmodel = rdb.hget('models', model_name) model = Model.from_json(jsmodel) return template( "admin/model_new.tpl", model_name=model_name, model=model )
def model_edit(model_name, id, rdb): jsmodel = rdb.lindex("%s::%s" % ("models", model_name), id - 1) model = Model.from_json(jsmodel) return template( "admin/model_new.tpl", model_name=model_name, model=model )
def models_list(model_name, rdb): models = [] obj = rdb.hgetall('models') for itm in obj: model = Model.from_json(obj[itm]) models.append(model) jsmodel = rdb.hget('models', model_name) model = Model.from_json(jsmodel) item_list = rdb.lrange("%s::%s" % ("models", model_name), 0, 10) items = [] for a in item_list: items.append(Model.from_json(a)) return template( "admin/model_list.tpl", model_name=model_name, model=model, models=models, items=items )
def model_save(model_name, rdb): jsmodel = rdb.hget('models', model_name) model = Model.from_json(jsmodel) for f in model.fields: f.value = request.forms.get(f.name) index = rdb.lpush( "%s::%s" % ("models", model_name), model.__json__() ) redirect( self.get_url(urls.models_edit, model_name=model_name, id=index) )
def model_design_save(rdb): model_name = request.POST.get('model_name') types = request.POST.getall('type[]') labels = request.POST.getall('label[]') names = request.POST.getall('name[]') ids = request.POST.getall('id[]') orders = request.POST.getall('order[]') values = request.POST.getall('values[]') fields = [] for a in range(0, len(types)): field = Field( names[a], types[a], labels[a], ids[a], orders[a], values[a] if a in values else '' ) fields.append(field) model = Model(model_name, fields) rdb.hset('models', model.name, model.__json__()) redirect(self.get_url(urls.models_list, model_name=model_name))