Exemplo n.º 1
0
def render(topic_id, newReplyForm, editTopicForm=None):
    if not editTopicForm:
        editTopicForm = EditTopicForm(request.form)
    if not newReplyForm:
        newReplyForm = NewReplyForm(request.form)
    cursor = g.db.cursor()

    if topic_id == "NULL":
        cursor.close()
        g.db.commit()
        return render_template('topicsnotfound.html')

    query = 'SELECT group_id, title, content, poster_id, dateposted FROM Topic WHERE id = %s'
    cursor.execute(query, [topic_id])
    topic = cursor.fetchone()

    if not topic:
        cursor.close()
        g.db.commit()
        return render_template('topicsnotfound.html')

    path = grouppath.getpath(topic[0], cursor)

    query = 'SELECT name FROM RegUser WHERE id = %s'
    cursor.execute(query, [topic[3]])
    poster = cursor.fetchone()

    query = 'SELECT Reply.content, Reply.dateposted, RegUser.name, Reply.id, RegUser.id, Reply.poster_id FROM Reply, RegUser WHERE Reply.deleted = false AND Reply.topic_id = %s AND (RegUser.id = Reply.poster_id OR Reply.poster_id IS NULL)'
    cursor.execute(query, [topic_id])
    replies = cursor.fetchall()
    cursor.close()
    g.db.commit()


    return render_template('view.html', editTopicForm=editTopicForm, topic_id=topic_id, topic=topic, poster=poster, replies=replies, path=path, newReplyForm=newReplyForm)
Exemplo n.º 2
0
def render(group_id, newTopicForm, newGroupForm):
    cursor = g.db.cursor()

    path = grouppath.getpath(group_id, cursor)
    if (not path) and (not group_id == "NULL"):
        cursor.close()
        g.db.commit()
        return render_template('topicsnotfound.html')

    # get topics
    if not group_id == "NULL":
        query = 'SELECT id, title FROM Topic WHERE group_id = %s'
        cursor.execute(query, [group_id])
    else:
        query = 'SELECT id, title FROM Topic WHERE group_id IS NULL'
        cursor.execute(query)
    topics = cursor.fetchall()

    # get subgroups
    if not group_id == "NULL":
        query = 'SELECT id, name FROM TopicGroup WHERE parent_id = %s'
        cursor.execute(query, [group_id])
    else:
        query = 'SELECT id, name FROM TopicGroup WHERE parent_id IS NULL'
        cursor.execute(query)
    groups = cursor.fetchall()
    cursor.close()
    g.db.commit()

    if not newTopicForm:
        newTopicForm = NewTopicForm(request.form)

    if not newGroupForm:
        newGroupForm = NewGroupForm(request.form)
    return render_template('topics.html', topics=topics, groups=groups, group_id=group_id, path=path, newTopicForm=newTopicForm, newGroupForm=newGroupForm)