-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
118 lines (100 loc) · 3.57 KB
/
main.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
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
#!/usr/bin/env python
#-*- coding: utf-8 -*-
from google.appengine.api import channel
from google.appengine.ext import webapp, db
from google.appengine.ext.webapp import util, template
import os
import logging
import simplejson
class BacklogItem(db.Model):
TYPES = ['AIR', 'Website', 'Hub', 'Backlog']
STATUSES = ['new', 'assigned', 'processed', 'completed', 'closed']
name = db.StringProperty()
type = db.StringProperty(choices = set(TYPES))
desc = db.TextProperty()
priority = db.IntegerProperty()
status = db.StringProperty(choices = set(STATUSES))
class OpenedPage(webapp.RequestHandler):
def post(self):
channel.send_message('testtest', {
"test": "test"
})
class MainHandler(webapp.RequestHandler):
def get(self, action):
if self.request.headers.get('X-Requested-With') == 'XMLHttpRequest':
self.response.headers['Content-Type'] = 'text/plain'
items = BacklogItem.all()#.filter('status !=', 'closed')#.order('-priority')
if action == 'getOrder':
resp = map(lambda x: str(x.key().id()) + '=' + str(x.priority), items)
else:
resp = map(lambda x: {
'id': x.key().id(),
'type': x.type,
'name': x.name,
'desc': x.desc,
'priority': x.priority,
'status': x.status
}, items)
self.response.out.write(simplejson.dumps({'data': resp}))
return
action = 'edit' if action == 'new' else 'index'
path = os.path.join('templates/%s.html' % action)
params = {
'types': BacklogItem.TYPES,
'statuses': BacklogItem.STATUSES,
'token': channel.create_channel('testtest')
}
self.response.out.write(template.render(path, params))
def post(self, action):
BacklogItem(
name = self.request.get('name'),
type = self.request.get('type'),
desc = self.request.get('desc'),
status = self.request.get('status'),
priority = int(self.request.get('priority'))
).put()
if not self.request.headers.get('X-Requested-With') == 'XMLHttpRequest':
self.redirect('/')
class ItemHandler(webapp.RequestHandler):
def get(self, id, action):
if action == 'close':
item = BacklogItem.get_by_id(int(id))
item.status = 'closed'
item.put()
self.__redirect('/')
return
action = 'edit' if action == 'edit' else 'show'
path = os.path.join('templates/%s.html' % action)
item = BacklogItem.get_by_id(int(id))
params = {
'action': '/%s/edit' % id,
'types': BacklogItem.TYPES,
'item': item,
'itemType': item.type
}
self.response.out.write(template.render(path, params))
def post(self, id, action):
item = BacklogItem.get_by_id(int(id))
if action == 'update_priority':
item.priority = int(self.request.get('priority'))
elif action == 'update_status':
item.status = self.request.get('status')
else:
item.name = self.request.get('name')
item.type = self.request.get('type')
item.desc = self.request.get('desc')
item.priority = int(self.request.get('priority'))
item.status = self.request.get('status')
item.put()
self.__redirect('/')
def __redirect(self, path):
if not self.request.headers.get('X-Requested-With') == 'XMLHttpRequest':
self.redirect(path)
def main():
application = webapp.WSGIApplication([
('/(\d+)(?:/(.*))?', ItemHandler),
('/(\w+)?', MainHandler)
], debug=True)
util.run_wsgi_app(application)
if __name__ == '__main__':
main()