/
character_view.py
78 lines (57 loc) · 2.41 KB
/
character_view.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# -*- coding: UTF-8 -*-
from maeve.web import BaseHandler, profile_required
from maeve.settings import webapp2_config
from maeve.utils import is_prod_environment
from maeve.models import Account, Character, WalletTransaction
from google.appengine.ext.ndb import toplevel
from google.appengine.api import users
import webapp2
class CharacterHandler(BaseHandler):
def get(self, char_id):
env = {}
char = Character.by_char_id(char_id)
if char:
env.update(dict(character=char,
account=char.account,
current='dashboard'))
if char.active:
pass
self.render_response('character/index.html', env)
else:
self.session.add_flash('No character with that id found', key='top_messages')
self.redirect('/profile')
class CharacterActivationHandler(BaseHandler):
def post(self, char_id, action):
char = Character.by_char_id(char_id)
if char:
if action == 'activate':
char.active = True
self.session.add_flash('Character {0} activated!'.format(char.name), key='top_messages', level='success')
char.put_async()
self.redirect('/character/{0}'.format(char.char_id))
else:
self.session.add_flash('No character with that id found', key='top_messages', level='warning')
self.redirect('/profile')
class CharacterTransactionsHandler(BaseHandler):
def get(self, char_id):
env = {}
char = Character.by_char_id(char_id)
if char:
env.update(dict(character=char,
account=char.account,
current='transactions',
WalletTransaction=WalletTransaction))
if char.active:
pass
self.render_response('character/transactions.html', env)
else:
self.session.add_flash('No character with that id found', key='top_messages')
self.redirect('/profile')
app = webapp2.WSGIApplication([
(r'/character/(\d+)/?$', CharacterHandler),
(r'/character/(\d+)/(activate)/?$', CharacterActivationHandler),
(r'/character/(\d+)/transactions/?$', CharacterTransactionsHandler),
],
debug=(not is_prod_environment()),
config=webapp2_config
)