-
Notifications
You must be signed in to change notification settings - Fork 0
/
base.py
41 lines (29 loc) · 1.01 KB
/
base.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
# -*- coding: utf-8 -*-
import webapp2, db
from google.appengine.api import users
class BaseHandler(webapp2.RequestHandler):
def loggedIn(self):
user = users.get_current_user()
return user is not None
def getUserName(self):
user = self.getEmail()
if user.find("@") <> -1:
user = user.split("@")[0]
return user
def getEmail(self):
return users.get_current_user().email()
def getLanguage(self):
email = self.getEmail()
teacher = db.Teacher.getByEmail(email)
return teacher.language if teacher is not None else "en_US"
def getUserId(self):
email = self.getEmail()
teacher = db.Teacher.getByEmail(email)
return teacher.key.id() if teacher else None
def getValues(self):
return {"logoutUrl": users.create_logout_url("/"),
"username": self.getUserName(),
"userid": self.getUserId()}
"""app = webapp2.WSGIApplication([
('/', BaseHandler)
], debug=True)"""