def GET(self): col_handler = self.col_handler('artical') form = articalf() form.inputs = (_.Dropdown("category_id", args=map(lambda i:(i['id'], i['name']), self.col_handler('category').find()), description="Category"),) + form.inputs return render_to_response('artical/manager_add_artical', {'form':form})
def POST(self, id): col_handler = self.col_handler('artical') form = articalf() form.inputs = (_.Dropdown("category_id", args=map(lambda i:(i['id'], i['name']), self.col_handler('category').find()), description="Category"),) + form.inputs if not form.validates(): return render_to_response('artical/manager_add_artical', {'form':form}) artical = Artical( form['title'].get_value(), form['tags'].get_value(), form['content'].get_value(), form['category_id'].get_value(), form['author'].get_value(), id=form['id'].get_value() ) artical.save() return web.seeother('/manager/artical')
def GET(self, id): if not id.isdigit(): return "ID is Wrong!" id = int(id) col_handler = self.col_handler('artical') artical = col_handler.find_one({'id':id}) form = articalf() form.inputs = (_.Dropdown("category_id", args=map(lambda i:(i['id'], i['name']), self.col_handler('category').find()), description="Category"),) + form.inputs form.fill({'id':id, 'category_id':artical['category_id'], 'content':artical['content'], 'title':artical['title'], 'tags':artical['tags'], 'author':artical['author'], }) return render_to_response('artical/manager_add_artical', {'form':form})