def post(group_id): cursor = g.db.cursor() if not session['loggedUser']: cursor.close() g.db.commit() return abort(401) query = 'SELECT id, permissions FROM RegUser WHERE id = %s' cursor.execute(query, [session['loggedUser'][0]]) user = cursor.fetchone() if not user[1] == 'administrator': cursor.close() g.db.commit() return abort(401) group = request.form if not NewGroupForm(group).validate(): cursor.close() g.db.commit() print u"virheellinen nimi" return topics.render(group_id, None, NewGroupForm(group)) if not user[1]: cursor.close() g.db.commit() return abort(401) if group_id == "NULL": query = 'INSERT INTO TopicGroup (parent_id, name) VALUES (NULL, %s) RETURNING id' cursor.execute(query, [group['name']]) else: query = 'INSERT INTO TopicGroup (parent_id, name) VALUES (%s, %s) RETURNING id' cursor.execute(query, [group_id, group['name']]) group_id = cursor.fetchone()[0] cursor.close() g.db.commit() if group_id: return redirect('/topics/'+str(group_id)+'/') else: return redirect('/topics/')
def post(group_id): cursor = g.db.cursor() if not session['loggedUser']: return abort(401) query = 'SELECT id, permissions, banexpire FROM RegUser WHERE id = %s' cursor.execute(query, [session['loggedUser'][0]]) user = cursor.fetchone() if not user: cursor.close() g.db.commit() return abort(401) topic = request.form if not NewTopicForm(topic).validate(): cursor.close() g.db.commit() print u"virheellinen viesti" return topics.render(group_id, NewTopicForm(topic), None) if user[2] and user[2] > datetime.datetime.today(): cursor.close() g.db.commit() return redirect('/banned') if not group_id == "NULL": query = 'INSERT INTO Topic (group_id, poster_id, title, content, dateposted) VALUES (%s, %s, %s, %s, NOW()) RETURNING id' cursor.execute(query, [group_id, user[0], topic['title'], topic['content']]) else: query = 'INSERT INTO Topic (poster_id, title, content, dateposted) VALUES (%s, %s, %s, NOW()) RETURNING id' cursor.execute(query, [user[0], topic['title'], topic['content']]) topic_id = cursor.fetchone()[0] cursor.close() g.db.commit() if not topic_id == "NULL": return redirect('/topics/view/'+str(topic_id)+'/') else: return redirect('/topics/'+str(group_id)+'/')
def discusList(group_id="NULL"): if request.method == 'POST': return newtopic.post(group_id) return topics.render(group_id, None, None)