-
Notifications
You must be signed in to change notification settings - Fork 0
/
edit.py
39 lines (35 loc) · 1.24 KB
/
edit.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
import webapp2
import jinja2
from google.appengine.api import users
from google.appengine.ext import ndb
from myuser import MyUser
import os
JINJA_ENVIRONMENT = jinja2.Environment(
loader=jinja2.FileSystemLoader(os.path.dirname(__file__)),
extensions=['jinja2.ext.autoescape'],
autoescape=True
)
class Edit(webapp2.RequestHandler):
def get(self):
self.response.headers['Content-Type'] = 'text/html'
user = users.get_current_user()
myuser_key = ndb.Key('MyUser', user.user_id())
myuser = myuser_key.get()
template_values = {
'myuser' : myuser
}
template =JINJA_ENVIRONMENT.get_template('edit.html')
self.response.write(template.render(template_values))
def post(self):
action = self.request.get('button')
if action == 'Submit':
user = users.get_current_user()
myuser_key = ndb.Key('MyUser', user.user_id())
myuser = myuser_key.get()
myuser.username = self.request.get('value_1')
myuser.fullname = self.request.get('value_2')
myuser.bio = self.request.get('value_3')
myuser.put()
self.redirect('/')
elif action == 'Back':
self.redirect('/')