def answnerSave(self): userInput = self.getInput() try: qID = int(userInput['question']) question = Questions.get(Questions.id == qID) current_user = Users.get(Users.name == self.isLogin()) if not self.isAdmin() or question.group.owner != current_user: return self.error(msg = '权限不足!', url=self.makeUrl('/admin/questions/answners', {'id': qID})) Answners.create( question = question, owner = current_user, content = userInput['content'] ) except Exception, e: return self.error(msg = '新增回答失败: %s' % e, url=self.makeUrl('/admin/questions/list'))
def answnerEdit(self): inputParams = self.getInput() answner = Answners.get(Answners.id == inputParams['id']) current_user = Users.get(Users.name == self.isLogin()) if not self.isAdmin() or answner.question.group.owner != current_user: return self.error(msg = '权限不足!', url=self.makeUrl('/admin/questions/list')) self.privData['ANSWNER'] = answner return self.display('answnerEdit')
def answnerDelete(self): userInput = self.getInput() try: answner = Answners.get(Answners.id == int(userInput['id'])) current_user = Users.get(Users.name == self.isLogin()) if not self.isAdmin() or answner.question.group.owner != current_user: return self.error(msg = '权限不足!', url=self.makeUrl('/admin/questions/list')) answner.delete_instance() except Exception, e: return self.error(msg = '删除回复失败: %s' % e, url=self.makeUrl('/admin/questions/list'))
def answners(self): inputParams = self.getInput() qID = inputParams['id'] page = int(inputParams['page']) if inputParams.has_key('page') else 1 count = config.COUNT_PER_PAGE question = Questions.get(Questions.id == qID) answnersList = Answners.select().where(Answners.question == qID) answnersList = answnersList.order_by(Answners.id.desc()) pageString = self.getPageStr(self.makeUrl('/admin/answners/list', {'id': qID}), page, count, answnersList.count()) self.privData['ANSWNERS_LIST'] = answnersList.paginate(page, count) self.privData['PAGE_STRING'] = pageString self.privData['QUESTION'] = question return self.display('answnersList')
def answnerModify(self): userInput = self.getInput() try: answner = Answners.get(Answners.id == int(userInput['id'])) current_user = Users.get(Users.name == self.isLogin()) if not self.isAdmin() or answner.question.group.owner != current_user: return self.error(msg = '权限不足!', url=self.makeUrl('/admin/questions/list')) answner.content = userInput['content'] answner.save() except Exception, e: return self.error(msg = '修改回复失败: %s' % e, url=self.makeUrl('/admin/questions/list'))
def answnersSearch(self): inputParams = self.getInput() keywords = inputParams['keywords'].strip().lower() if inputParams.has_key('keywords') else '' page = int(inputParams['page']) if inputParams.has_key('page') else 1 qID = int(inputParams['qid']) count = config.COUNT_PER_PAGE question = Questions.get(Questions.id == qID) answnersList = Answners.select().where(Answners.question == qID and Answners.content.contains(keywords)) answnersList = answnersList.order_by(Answners.id.desc()) pageString = self.getPageStr(self.makeUrl('/admin/questions/answners', {'id': qID}), page, count, answnersList.count()) self.privData['ANSWNERS_LIST'] = answnersList.paginate(page, count) self.privData['PAGE_STRING'] = pageString self.privData['QUESTION'] = question return self.display('answnersList')