This repository has been archived by the owner on May 21, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
task-chrono.py
72 lines (57 loc) · 2.15 KB
/
task-chrono.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
# -*- coding: utf-8 -*-
# Copyright (c) 2014 Ludo Visser
#
# task-chrono is distributed under the terms and conditions of the MIT license.
# The full license can be found in the LICENSE file.
import webapp2
from google.appengine.api import users
from google.appengine.ext import ndb
from google.appengine.ext.webapp.util import login_required
import render
import settings
import stats
import task
# Main page request handler
class MainPage(webapp2.RequestHandler):
@login_required
def get(self):
# Get settings for current user
user = users.get_current_user()
user_settings = settings.get_settings(user)
# Get key for current list
list_name = user_settings.active_list
list_key = ndb.Key('User', user.user_id(), 'TaskList', list_name)
# Get tasks for list, order by priority and creation date
task_query = task.Task.query(ancestor=list_key).order(task.Task.state, task.Task.created)
tasks = task_query.fetch()
# Create template context
context = {
'title': 'Overview of <%s>' % list_name,
'page': 'list',
'tasks': tasks,
'logout_url': users.create_logout_url('/')}
# Parse and serve template
template = render.JINJA.get_template('tasklist.html')
self.response.write(template.render(context))
# Help page request handler
class HelpPage(webapp2.RequestHandler):
def get(self):
# Create template context
context = {
'page': 'help',
'logout_url': users.create_logout_url(self.request.uri)}
# Parse and serve template
template = render.JINJA.get_template('help.html')
self.response.write(template.render(context))
# Main application instance
application = webapp2.WSGIApplication(
[('/', MainPage),
('/stats', stats.StatsPage),
('/settings', settings.SettingsPage),
('/help', HelpPage),
('/new', task.NewTaskHandler),
('/delete', task.DeleteTaskHandler),
('/start', task.StartTaskHandler),
('/stop', task.StopTaskHandler),
('/save', settings.SaveSettingsHandler)
], debug=False)