-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
64 lines (54 loc) · 2.24 KB
/
main.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
58
59
60
61
62
63
64
# -*- coding: UTF-8 -*-
# main.py : the main file.
from okasha.baseWebApp import *
from okasha.bottleTemplate import *
from functions import *
class quran_quiz(baseWebApp):
def __init__(self, *args, **kw):
baseWebApp.__init__(self, *args, **kw)
@expose(bottleTemplate, ['index.tpl'])
def _root(self, rq, *args):
return {'rq':rq, 'args':args, 'validate_auth':validate_auth, 'heroes':get_heroes()}
@expose(bottleTemplate, ['menu.tpl'])
def menu(self, rq, *args):
if rq.q.has_key('fb_user_id'):
user = get_user_by_fb_id(rq.q.getfirst('fb_user_id').decode('utf8'))
else:
raise forbiddenExeption()
return {'rq':rq, 'args':args, 'user':user}
@expose(bottleTemplate, ['about.tpl'])
def about(self, rq, *args):
return {'rq':rq, 'args':args}
@expose(bottleTemplate, ['statistics.tpl'])
def statistics(self, rq, *args):
if rq.q.has_key('fb_user_id'):
user = get_user_by_fb_id(rq.q.getfirst('fb_user_id').decode('utf8'))
s = get_statistics(user)
rank = get_rank(user)
return {'rq':rq, 'args':args, 'user':user, 'statistics':s, 'rank':rank}
if rq.q.has_key('round_id'):
r = get_round(round_id = int(rq.q.getfirst('round_id')))
return {'rq':rq, 'args':args, 'r':r}
return {'rq':rq, 'args':args}
@expose(bottleTemplate, ['rounds.tpl'])
def rounds(self, rq, *args):
if rq.q.has_key('fb_user_id'):
user = get_user_by_fb_id(rq.q.getfirst('fb_user_id').decode('utf8'))
else:
raise forbiddenExeption()
if rq.q.has_key('parts_num'):
r = create_new_round(user = user, parts_num = int(rq.q.getfirst('parts_num')), direction = rq.q.getfirst('direction','').decode('utf8'))
else:
r = get_unfinished_round(user)
return {'rq':rq, 'args':args, 'user':user, 'round':r, 'suras':get_suras(r)}
@expose(jsonDumps)
def json(self, rq, *args):
reply = json_page(rq, args)
if reply != 0:
return reply
else:
raise forbiddenException()
@expose(jsonDumps)
def invite(self, rq, *args):
i = add_invite(rq)
return i