This repository was archived by the owner on Mar 1, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbase_handler.py
More file actions
128 lines (117 loc) · 4.76 KB
/
base_handler.py
File metadata and controls
128 lines (117 loc) · 4.76 KB
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
# -*- coding: utf-8 -*-
import webapp2, jinja2, os
loader = jinja2.FileSystemLoader(os.path.dirname(__file__))
jinja_environment = jinja2.Environment(loader=loader)
from app_languages import *
class BaseHandler(webapp2.RequestHandler):
"""
BaseHandler
"""
def getTemp(self, temp_file, temp_vars):
"""
Get a rendered template.
Parameters
----------
temp_file: the html file
temp_vars: dict with values for the template
Returns
-------
A rendered template.
"""
template = jinja_environment.get_template('templates/' + temp_file)
return template.render(temp_vars)
def getLang(self):
"""
Get the current language from cookie or as url parameter.
Set default value when not present, set for application and set cookie.
Returns
-------
The current language.
"""
userlocale = self.request.cookies.get('gaeuserlocale', '')
urllocale = self.request.get("locale")
if not urllocale:
if not userlocale:
locale = 'en'
else:
locale = userlocale
else:
locale = urllocale
cv = 'gaeuserlocale='+str(locale)+';expires=31-Dec-202023:59:59 GMT'
self.response.headers.add_header('Set-Cookie', cv)
return locale
def getMsgsForKey(self, key):
"""
Get messages for a specific key.
Parameters
----------
key: section key
Returns
-------
dict - with specific messages
"""
locale = self.getLang()
uitext = app_languages[locale]
return uitext[key]
def getTplText(self, key):
"""
Get placeholder for template.
Parameters
----------
key: ui section
Returns
-------
dict - with specific messages
"""
locale = self.getLang()
uitext = app_languages[locale]
text = ''
if key == 'uiindex':
text = {'title': uitext['uiindex']['title'],
'headline': uitext['uiindex']['headline'],
'login': uitext['uiindex']['login'],
'loginbtn': uitext['uiindex']['loginbtn'],
'email': uitext['uiindex']['email'],
'password': uitext['uiindex']['password'],
'repassword': uitext['uiindex']['repassword'],
'losepw': uitext['uiindex']['losepw'],
'register': uitext['uiindex']['register'],
'registerbtn': uitext['uiindex']['registerbtn']}
elif key == 'uiconform':
text = {'title': uitext['uiconform']['title'],
'backbtn': uitext['uiconform']['backbtn']}
elif key == 'uilosepw':
text = {'title': uitext['uilosepw']['title'],
'email': uitext['uilosepw']['email'],
'send': uitext['uilosepw']['send'],
'back': uitext['uilosepw']['back']}
elif key == 'uiprofile':
text = {'title': uitext['uiprofile']['title'],
'changepw': uitext['uiprofile']['changepw'],
'delaccount': uitext['uiprofile']['delaccount'],
'logout': uitext['uiprofile']['logout'],
'headline': uitext['uiprofile']['headline']}
elif key == 'uichangepw':
text = {'title': uitext['uichangepw']['title'],
'profile': uitext['uichangepw']['profile'],
'changepw': uitext['uichangepw']['changepw'],
'delaccount': uitext['uichangepw']['delaccount'],
'logout': uitext['uichangepw']['logout'],
'oldpassword': uitext['uichangepw']['oldpassword'],
'newpassword': uitext['uichangepw']['newpassword'],
'renewpassword': uitext['uichangepw']['renewpassword'],
'lospwBtn': uitext['uichangepw']['lospwBtn']}
elif key == 'uisetpw':
text = {'title': uitext['uisetpw']['title'],
'newpassword': uitext['uisetpw']['newpassword'],
'renewpassword': uitext['uisetpw']['renewpassword'],
'back': uitext['uisetpw']['back']}
elif key == 'uidelaccount':
text = {'title': uitext['uidelaccount']['title'],
'profile': uitext['uidelaccount']['profile'],
'changepw': uitext['uidelaccount']['changepw'],
'delaccount': uitext['uidelaccount']['delaccount'],
'delete': uitext['uidelaccount']['delete'],
'logout': uitext['uidelaccount']['logout']}
text['locale'] = locale
return text