def action(self, d):
'''
'''
action = self.request.get('action')
res = {}
if action == 'create_common':
common_tasks = self.user.get_setting_prop(['tasks', 'common_tasks'])
if common_tasks:
task_put = []
for ct in common_tasks:
title = ct.get('title')
if title:
task_put.append(Task.Create(self.user, title))
if task_put:
ndb.put_multi(task_put)
self.message = "Created %d task(s)" % len(task_put)
res['tasks'] = [t.json() for t in task_put]
self.success = True
else:
self.message = "You haven't configured any common tasks"
elif action == 'archive_complete':
recent = Task.Recent(self.user, limit=20)
to_archive = []
for t in recent:
if not t.archived and t.is_done():
t.archive()
to_archive.append(t)
if to_archive:
ndb.put_multi(to_archive)
res['archived_ids'] = [t.key.id() for t in to_archive]
self.message = "Archived %d %s" % (len(to_archive), tools.pluralize('task', count=len(to_archive)))
else:
self.message = "No completed tasks to archive"
self.success = True
else:
self.message = "Unknown action"
self.set_response(res)
评论列表
文章目录