-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreate_taskboard.py
More file actions
91 lines (70 loc) · 2.72 KB
/
create_taskboard.py
File metadata and controls
91 lines (70 loc) · 2.72 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
import webapp2
import jinja2
from google.appengine.api import users
from google.appengine.ext import ndb
import os
import logging
from myuser import MyUser
from taskboard import TaskBoard
# Setting up the environment for Jinja to work in as we construct a
# jinja2.Environment object.
JINJA_ENVIRONMENT = jinja2.Environment(
loader = jinja2.FileSystemLoader(os.path.dirname(__file__)),
extensions=['jinja2.ext.autoescape'],
autoescape=True
)
class Create(webapp2.RequestHandler):
def get(self):
self.response.headers['Content-Type'] = 'text/html'
# pull the current user from the Request
user = users.get_current_user()
if user == None:
url_string = 'login'
url = users.create_login_url(self.request.uri)
template_values = {
'url_string' : url_string,
'url' : url,
'login_url' : users.create_login_url(self.request.uri)
}
template = JINJA_ENVIRONMENT.get_template('main.html')
self.response.write(template.render(template_values))
return
url_string = 'logout'
url = users.create_logout_url(self.request.uri)
query = MyUser.query()
template_values = {
"user" : user,
'url_string' : url_string,
'url' : url,
}
# pull the template file and ask jinja to render
# it with the given template values
template = JINJA_ENVIRONMENT.get_template('create_taskboard.html')
self.response.write(template.render(template_values))
def post(self):
self.response.headers['Content-Type'] = 'text/html'
# pull the current user from the Request
user = users.get_current_user()
id = user.user_id()
print(id)
new_tbd_id = ''
action = self.request.get('button')
print("hey")
print(id)
name = self.request.get('tbd_name')
if user and action == 'Submit':
myuser_key = ndb.Key('MyUser', id)
myuser = myuser_key.get()
new_taskboard = TaskBoard()
new_taskboard.tbd_name = self.request.get('tbd_name')
#new_taskboard.tbd_creator = myuser_key
new_taskboard.tbd_creator_email = user.email()
new_taskboard.put()
new_tbd_id = ndb.Key('TaskBoard', new_taskboard.key.id())
myuser.tb_key.append(new_tbd_id)
myuser.put()
self.redirect('/view_taskboard')
elif user and action == 'Cancel':
self.redirect('/view_taskboard')
else:
self.redirect('/view_taskboard')