Last active
October 16, 2015 20:05
-
-
Save tomcam/d0f36cb96b304330ddfc to your computer and use it in GitHub Desktop.
web2py todo app fails on GAE cloud server - October 16, 2015
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{{extend 'layout.html'}} | |
{{if 'message' in globals():}} | |
<h3>{{=message}}</h3> | |
{{pass}} | |
<h1> | |
All tasks | |
</h1> | |
<h2> | |
{{=A(T('Active tasks'), _href=URL('index'))}} | |
{{=A(T('Assignments'), _href=URL('assignments'))}} | |
{{=A(T('Team'), _href=URL('team'))}} | |
</h2> | |
{{=grid}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{{extend 'layout.html'}} | |
{{if 'message' in globals():}} | |
<h3>{{=message}}</h3> | |
{{pass}} | |
<h1> | |
Assignments (tasks by team member) | |
</h1> | |
<h2> | |
{{=A(T('Active tasks'), _href=URL('index'))}} | |
{{=A(T('Team'), _href=URL('team'))}} | |
{{=A(T('All tasks'), _href=URL('alltasks'))}} | |
</h2> | |
{{=grid}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def team(): | |
return dict( | |
grid=SQLFORM.grid( | |
db.auth_user, | |
user_signature=False)) | |
def alltasks(): | |
return dict( | |
grid=SQLFORM.grid( | |
db.task, | |
user_signature=False)) | |
def assignments(): | |
return dict( | |
grid=SQLFORM.smartgrid( | |
db.auth_user, | |
linked_tables=['task'], | |
)) | |
def index(): | |
return dict( | |
grid=SQLFORM.grid( | |
db.task.completed == False, | |
user_signature=False)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# -*- coding: utf-8 -*- | |
""" | |
This file is part of the web2py Web Framework | |
Copyrighted by Massimo Di Pierro <mdipierro@cs.depaul.edu> | |
License: LGPLv3 (http://www.gnu.org/licenses/lgpl.html) | |
""" | |
############################################################################## | |
# Configuration parameters for Google App Engine | |
############################################################################## | |
LOG_STATS = False # web2py level log statistics | |
APPSTATS = True # GAE level usage statistics and profiling | |
DEBUG = False # debug mode | |
# | |
# Read more about APPSTATS here | |
# http://googleappengine.blogspot.com/2010/03/easy-performance-profiling-with.html | |
# can be accessed from: | |
# http://localhost:8080/_ah/stats | |
############################################################################## | |
# All tricks in this file developed by Robin Bhattacharyya | |
############################################################################## | |
import time | |
import os | |
import sys | |
import logging | |
import cPickle | |
import pickle | |
import wsgiref.handlers | |
import datetime | |
path = os.path.dirname(os.path.abspath(__file__)) | |
# os.chdir(path) ? | |
if not os.path.isdir('applications'): | |
raise RuntimeError('Running from the wrong folder') | |
sys.path = [path] + [p for p in sys.path if not p == path] | |
sys.modules['cPickle'] = sys.modules['pickle'] | |
from gluon.settings import global_settings | |
from google.appengine.ext import webapp | |
from google.appengine.ext.webapp.util import run_wsgi_app | |
global_settings.web2py_runtime_gae = True | |
global_settings.db_sessions = True | |
if os.environ.get('SERVER_SOFTWARE', '').startswith('Devel'): | |
(global_settings.web2py_runtime, DEBUG) = \ | |
('gae:development', True) | |
else: | |
(global_settings.web2py_runtime, DEBUG) = \ | |
('gae:production', False) | |
import gluon.main | |
def log_stats(fun): | |
"""Function that will act as a decorator to make logging""" | |
def newfun(env, res): | |
"""Log the execution time of the passed function""" | |
timer = lambda t: (t.time(), t.clock()) | |
(t0, c0) = timer(time) | |
executed_function = fun(env, res) | |
(t1, c1) = timer(time) | |
log_info = """**** Request: %.2fms/%.2fms (real time/cpu time)""" | |
log_info = log_info % ((t1 - t0) * 1000, (c1 - c0) * 1000) | |
logging.info(log_info) | |
return executed_function | |
return newfun | |
logging.basicConfig(level=logging.INFO) | |
def wsgiapp(env, res): | |
"""Return the wsgiapp""" | |
env['PATH_INFO'] = env['PATH_INFO'].decode('latin1').encode('utf8') | |
#when using the blobstore image uploader GAE dev SDK passes these as unicode | |
# they should be regular strings as they are parts of URLs | |
env['wsgi.url_scheme'] = str(env['wsgi.url_scheme']) | |
env['QUERY_STRING'] = str(env['QUERY_STRING']) | |
env['SERVER_NAME'] = str(env['SERVER_NAME']) | |
#this deals with a problem where GAE development server seems to forget | |
# the path between requests | |
if global_settings.web2py_runtime == 'gae:development': | |
gluon.admin.create_missing_folders() | |
web2py_path = global_settings.applications_parent # backward compatibility | |
return gluon.main.wsgibase(env, res) | |
if LOG_STATS or DEBUG: | |
wsgiapp = log_stats(wsgiapp) | |
def main(): | |
"""Run the wsgi app""" | |
run_wsgi_app(wsgiapp) | |
if __name__ == '__main__': | |
main() | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{{extend 'layout.html'}} | |
{{if 'message' in globals():}} | |
<h3>{{=message}}</h3> | |
{{pass}} | |
<h1> | |
Active Tasks | |
</h1> | |
<h2> | |
{{=A(T('Assignments'), _href=URL('assignments'))}} | |
{{=A(T('Team'), _href=URL('team'))}} | |
{{=A(T('All tasks'), _href=URL('alltasks'))}} | |
</h2> | |
{{if db(db.auth_user).isempty():}} | |
<h2> | |
Please add at least 1 {{=A(T('Team'), _href=URL('team'))}} | |
member before creating any tasks. | |
</h2> | |
{{else:}} | |
{{=grid}} | |
{{pass}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
routers = dict( | |
BASE = dict( | |
default_application='todo', | |
) | |
) | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
db.define_table('task', | |
Field('title',unique=True,notnull=True), | |
Field('description','text'), | |
Field('priority','integer',default=3, | |
requires=IS_IN_SET([1,2,3,4,5], | |
labels=[ | |
T('Very low'), | |
T('Low'), | |
T('Medium'), | |
T('High'), | |
T('Very High')], | |
zero=None)), | |
Field('completed','boolean',default=False), | |
Field('user_id','reference auth_user', | |
default=auth.user_id, required=False)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{{extend 'layout.html'}} | |
{{if 'message' in globals():}} | |
<h3>{{=message}}</h3> | |
{{pass}} | |
<h1> | |
Team Members | |
</h1> | |
<h2> | |
{{=A(T('Active tasks'), _href=URL('index'))}} | |
{{=A(T('Assignments'), _href=URL('assignments'))}} | |
{{=A(T('All tasks'), _href=URL('alltasks'))}} | |
</h2> | |
{{=grid}} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment