Ejemplo n.º 1
0
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('/')
Ejemplo n.º 2
0
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('/')
Ejemplo n.º 3
0
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', ''))
Ejemplo n.º 4
0
 def getTopic(self):
     if self.topic:
         return Topics.get(self.topic)
     return None