Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @app.route("/question", methods=['POST', 'GET'])
- def question():
- if 'username' not in session:
- return redirect(url_for('login'))
- form_text = '''
- <p>Question form:</p>
- <form method="post">
- <label for="theme">Theme:</label><br>
- <input type="text" id="theme" name="theme"><br>
- <label for="question">Question:</label><br>
- <textarea id="question" name="question"></textarea>
- <br>
- <input type="submit" value="Submit">
- </form>
- '''
- if request.method == 'POST':
- title = request.form['title']
- question = request.form['question']
- username = session['username']
- with get_db().session() as db:
- while (True):
- id = ''.join(random.choices(string.ascii_lowercase + string.digits, k=10))
- result = db.run(
- r'MATCH (Q:Question {id: $id}) RETURN Q',
- id = id
- ).single()
- if result is None:
- break
- db.run(
- r'MATCH (U:User {username:$username}) CREATE (Q:Question {title:$title, question:$question, id: $id}) <-[r:ASKED]-(U)',
- title=title, question=question, username = username, id=id
- )
- return form_text
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement