def dislike_topic(topic_id=''): session = bottle.request.environ.get('beaker.session') #@UndefinedVariable topic = Topics.get(int(topic_id)) if topic: topic.dislikes = topic.dislikes + 1 if not topic.save(): session['alert'] = 'Failed to dislike Topic' bottle.redirect('/topic/' + str(topic.id)) session['alert'] = "Failed to dislike Topic, doesn't exist" bottle.redirect('/')
def add_message(): session = bottle.request.environ.get('beaker.session') #@UndefinedVariable form = bottle.request.forms required = ['username', 'message', 'topic'] for r in required: if not r in form or len(form.get(r)) == 0: session['alert'] = 'Failed to add Topic. Missing ' + r bottle.redirect('/') topic = Topics.get(id=int(form.get('topic'))) if topic: message = Messages.Message(username=form.get('username'), message=form.get('message'), reply_to=form.get('reply_to', None), topic=topic.id) if message.save(): session['alert'] = 'Successfully added Reply' bottle.redirect('/topic/' + str(topic.id)) session['alert'] = 'Failed to add Message' bottle.redirect('/')
def topic(topic_id=''): session = bottle.request.environ.get('beaker.session') #@UndefinedVariable return bottle.template('page-topic', topic=Topics.get(int(topic_id)), alert=session.pop('alert', ''))
def getTopic(self): if self.topic: return Topics.get(self.topic) return None