-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfunc.py
57 lines (41 loc) · 1.69 KB
/
func.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
from flask import Flask, render_template
from flask_ask import Ask, statement, question, session
from models import db, books, users
def welcome():
user_id = session.user.userId
userstate = users.get_user_state(user_id)
if userstate is not None:
response = render_template('welcome_back', title=userstate.book, page=userstate.sentence + 1)
else:
response = render_template('welcome', title=books.default_book)
users.create_user_state(user_id, books.default_book)
return question(response)
def set_level(level=0):
user_id = session.user.userId
userstate = users.get_user_state(user_id)
users.set_level(userstate, level)
response = render_template('level_updated', level=level)
return question(response)
def read_next_sentence(update_state=True, shift=0, languages=[]):
user_id = session.user.userId
userstate = users.get_user_state(user_id)
sentence_id = userstate.sentence
sentence = books.get_sentences()[sentence_id + shift]
if languages == []:
reader = 'read_sentence_beginner'
if userstate.level == 2:
reader = 'read_sentence_intermediate'
if userstate.level == 3:
reader = 'read_sentence_advanced'
response = render_template(reader, de=sentence['de'], en=sentence['en'])
else:
de, en = None, None
if 'de' in languages:
de = sentence['de']
if 'en' in languages:
en = sentence['en']
response = render_template('repeat_sentence', de=de, en=en)
if update_state:
users.next_sentence(userstate)
want_countinue = render_template('want_countinue')
return question(response).reprompt(want_countinue)