This file looks large and may slow your browser down if we attempt
to syntax highlight it, so we are showing it without any
pretty colors.
Highlight
it anyway.
1 |
# -*- coding utf-8 -*- |
2 |
# classes/views/context.py |
3 |
|
4 |
from flask import Module, request, render_template, redirect,\ |
5 |
url_for, json, current_app, abort |
6 |
|
7 |
from swtstore.classes.models import Context, User |
8 |
|
9 |
|
10 |
context = Module(__name__) |
11 |
|
12 |
|
13 |
@context.route('/register', methods=['GET', 'POST']) |
14 |
def register(): |
15 |
current_user = User.getCurrentUser() |
16 |
if current_user is None: |
17 |
return redirect(url_for('frontend.index')) |
18 |
|
19 |
if request.method == 'GET': |
20 |
return render_template('context/register.html') |
21 |
|
22 |
if request.method == 'POST': |
23 |
if not request.form.get('name') or not request.form.get('defn'): |
24 |
abort(400) |
25 |
|
26 |
current_app.logger.debug('New Context: defn: %s ', |
27 |
request.form.get('defn')) |
28 |
json_ld = json.loads(request.form.get('defn')) |
29 |
current_app.logger.debug('Resulting json_ld %s', json_ld) |
30 |
|
31 |
new_context = Context( |
32 |
name=request.form.get('name'), |
33 |
definition=json_ld, |
34 |
user_id=current_user.id |
35 |
) |
36 |
current_app.logger.debug('New Context created: %s', new_context) |
37 |
new_context.persist() |
38 |
|
39 |
return redirect(url_for('user.myContexts')) |