and some additional patches (already send per email):
- for gae it enables the gae build admin console at admin-gae (for
admin only)
- when accessing /admin on a gea (sdk) it gives a more descriptive
error msg
- gentle way of switching between gae-backend and normal backend in
the applications db.py
- some typos
Index: app.yaml
===================================================================
--- app.yaml (revision 954)
+++ app.yaml (working copy)
@@ -10,6 +10,10 @@
upload: applications/(.+?)/static/(.+)
secure: optional
+- url: /admin-gae/.*
+ script: $PYTHON_LIB/google/appengine/ext/admin
+ login: admin
+
- url: .*
script: gaehandler.py
secure: optional
@@ -27,5 +31,5 @@
(\..*)|
((admin|examples|welcome)\.tar)|
(applications/(admin|examples)/.*)|
- (applicaitons/.*/databases/.*) |
+ (applications/.*/databases/.*) |
)$
Index: applications/admin/models/access.py
===================================================================
--- applications/admin/models/access.py (revision 954)
+++ applications/admin/models/access.py (working copy)
@@ -7,7 +7,7 @@
return os.path.join(opath, path).replace('\\', '/')
# ###########################################################
-# ## make sure administrator is on localhost
+# ## make sure administrator is on localhost or https
# ###########################################################
http_host = request.env.http_host.split(':')[0]
@@ -27,7 +27,7 @@
in ['https', 'HTTPS']:
session.secure()
elif not remote_addr in hosts:
- raise HTTP(200, T('Admin is disabled because unsecure channel'))
+ raise HTTP(200, T('Admin is disabled because insecure channel'))
try:
_config = {}
@@ -37,7 +37,12 @@
if not 'password' in _config or not _config['password']:
raise HTTP(200, T('admin disabled because no admin
password'))
except IOError:
- raise HTTP(200,
+ from gluon.settings import settings
+ if settings.web2py_runtime_gae:
+ raise HTTP(200,
+ T('admin disabled because not supported on google
apps engine'))
+ else:
+ raise HTTP(200,
T('admin disabled because unable to access password
file'))
# ###########################################################
Index: applications/welcome/controllers/default.py
===================================================================
--- applications/welcome/controllers/default.py (revision 954)
+++ applications/welcome/controllers/default.py (working copy)
@@ -8,7 +8,7 @@
def index():
"""
- example action using the internationalizaiton operator T and
flash
+ example action using the internationalization operator T and
flash
rendered by views/default/index.html or views/generic.html
"""
response.flash = T('Welcome to web2py')
Index: applications/welcome/models/db.py
===================================================================
--- applications/welcome/models/db.py (revision 954)
+++ applications/welcome/models/db.py (working copy)
@@ -2,17 +2,24 @@
## This scaffolding model makes your app work on Google App Engine
too
#########################################################################
-try:
- from gluon.contrib.gql import * # if running on Google App
Engine
-except:
- db = SQLDB('sqlite://storage.sqlite') # if not, use SQLite or
other DB
-else:
- db = GQLDB() # connect to Google BigTable
- session.connect(request, response, db=db) # and store sessions
there
+from gluon.settings import settings
+
+# if running on Google App Engine
+if settings.web2py_runtime_gae:
+ from gluon.contrib.gql import *
+
+ # connect to Google BigTable
+ db = GQLDB()
+ # and store sessions there
+ session.connect(request, response, db=db)
# or use the following lines to store sessions in Memcache
#from gluon.contrib.memdb import MEMDB
#from google.appengine.api.memcache import Client
#session.connect(request, response, db=MEMDB(Client()))
+else:
+ # if not, use SQLite or other DB
+ db = SQLDB('sqlite://storage.sqlite')
+
#########################################################################
## uncomment the following line if you do not want sessions
Index: applications/examples/models/db.py
===================================================================
--- applications/examples/models/db.py (revision 954)
+++ applications/examples/models/db.py (working copy)
@@ -1,15 +1,20 @@
+#########################################################################
+## This scaffolding model makes your app work on Google App Engine
too
+#########################################################################
-#
########################################################################
-# # This scaffolding model makes your app work on Google App Engine
too
-#
########################################################################
+from gluon.settings import settings
-try:
- from gluon.contrib.gql import * # if running on Google App
Engine
-except:
- db = SQLDB('sqlite://storage.sqlite') # if not, use SQLite or
other DB
+# if running on Google App Engine
+if settings.web2py_runtime_gae:
+ from gluon.contrib.gql import *
+
+ # connect to Google BigTable
+ db = GQLDB()
+ # and store sessions there
+ session.connect(request, response, db=db)
else:
- db = GQLDB() # connect to Google BigTable
- session.connect(request, response, db=db) # and store sessions
there
+ # if not, use SQLite or other DB
+ db = SQLDB('sqlite://storage.sqlite')
db.define_table(
'users',
@@ -43,12 +48,14 @@
SQLField('quantity', 'integer')
)
-from gluon.settings import settings
-if not settings.web2py_runtime_gae:
+# if running on Google App Engine
+if settings.web2py_runtime_gae:
+ # quick hack to skip the join
+ purchased = None
+else:
+ # use a joined view
purchased = (db.users.id == db.purchases.buyer_id) &
(db.products.id
== db.purchases.product_id)
-else:
- purchased = None
db.users.name.requires = IS_NOT_EMPTY()
db.users.email.requires = [IS_EMAIL(), IS_NOT_IN_DB(db,
'users.email')]
Index: gluon/restricted.py
===================================================================
--- gluon/restricted.py (revision 954)
+++ gluon/restricted.py (working copy)
@@ -53,7 +53,7 @@
def log(self, request):
"""
- logs the exeption.
+ logs the exception.
"""
a = request.application
@@ -91,10 +91,10 @@
self.traceback = d['traceback']
-def restricted(code, environment={}, layer='Unkown'):
+def restricted(code, environment={}, layer='Unknown'):
"""
- runs code in evrionment and returns the output. if an exeception
occurs
- in code it raises a RestrictedError containg the traceback. layer
is passed
+ runs code in environment and returns the output. if an exception
occurs
+ in code it raises a RestrictedError containing the traceback.
layer is passed
to RestrictedError to identify where the error occurred.
"""
On May 20, 4:13 am, mdipierro <[email protected]> wrote:
> Can you please email this to me? thanks
>
> On May 19, 5:13 pm, HansD <[email protected]> wrote:
>
> > update for database_examples.py:
> > - small bug fixed for the gae_hack
> > - updated the form to work with dropdown boxes (also for non-gae)
>
> > Index: applications/examples/controllers/database_examples.py
> > ===================================================================
> > --- applications/examples/controllers/database_examples.py (revision
> > 953)
> > +++ applications/examples/controllers/database_examples.py (working
> > copy)
> > @@ -52,13 +52,27 @@
> > """ uses a form to query who is buying what. validates form and
> > updates existing record or inserts new record in purchases
> > """
>
> > - form = FORM(TABLE(TR('Buyer id:', INPUT(_type='text',
> > - _name='buyer_id', requires=IS_NOT_EMPTY())),
> > - TR('Product id:', INPUT(_type='text',
> > _name='product_id'
> > - , requires=IS_NOT_EMPTY())), TR('Quantity:',
> > - INPUT(_type='text', _name='quantity',
> > - requires=IS_INT_IN_RANGE(1, 100))), TR('',
> > - INPUT(_type='submit', _value='Order'))))
> > + buyerRecords = db().select(db.users.ALL)
> > + buyerOptions = []
> > + for row in buyerRecords:
> > + buyerOptions.append(OPTION(row.name, _value=row.id))
> > +
> > + productRecords = db().select(db.products.ALL)
> > + productOptions = []
> > + for row in productRecords:
> > + productOptions.append(OPTION(row.name, _value=row.id))
> > +
> > + form = FORM(TABLE(
> > + TR('Buyer id:',
> > + SELECT(buyerOptions,_name='buyer_id')),
> > + TR('Product id:',
> > + SELECT(productOptions,_name='product_id')),
> > + TR('Quantity:',
> > + INPUT(_type='text', _name='quantity',
> > + requires=IS_INT_IN_RANGE(1, 100))),
> > + TR('',
> > + INPUT(_type='submit', _value='Order'))
> > + ))
> > if form.accepts(request.vars, session, keepvalues=True):
>
> > # ## check if user is in the database
> > @@ -90,7 +104,6 @@
> > else:
>
> > # ## or insert a new record in table
> > -
> > db.purchases.insert(buyer_id=form.vars.buyer_id,
> > product_id=form.vars.product_id,
> > quantity=form.vars.quantity)
> > @@ -100,9 +113,13 @@
>
> > # ## now get a list of all purchases
>
> > - records = db(purchased).select(db.users.name,
> > - db.purchases.quantity,
> > - db.products.name)
> > + # quick fix to make it runnable on gae
> > + if purchased:
> > + records = db(purchased).select(db.users.name,
> > + db.purchases.quantity,
> > + db.products.name)
> > + else:
> > + records = db().select(db.purchases.ALL)
> > return dict(form=form, records=SQLTABLE(records), vars=form.vars,
> > vars2=request.vars)
>
> > On May 19, 8:57 pm, Hans Donner <[email protected]> wrote:
>
> > > Trying to make the web2py examples run out of the box on google apps
> > > engine (sdk). It now runs almost all examples, only the purchase part
> > > of the database not yet, anyone a suggestion for this?
>
> > > The fixing might be a bit quick&dirty, but I was after the results.
>
> > > Index: applications/examples/controllers/database_examples.py
> > > ===================================================================
> > > --- applications/examples/controllers/database_examples.py (revision
> > > 953)
> > > +++ applications/examples/controllers/database_examples.py (working
> > > copy)
> > > @@ -100,9 +100,13 @@
>
> > > # ## now get a list of all purchases
>
> > > - records = db(purchased).select(db.users.name,
> > > - db.purchases.quantity,
> > > - db.products.name)
> > > + # quick fix to make it runnable on gae
> > > + if purchased:
> > > + records = db(purchased).select(db.users.name,
> > > + db.purchases.quantity,
> > > + db.products.name)
> > > + else:
> > > + records = db().select(db.users.ALL))
> > > return dict(form=form, records=SQLTABLE(records), vars=form.vars,
> > > vars2=request.vars)
>
> > > Index: applications/examples/models/db.py
> > > ===================================================================
> > > --- applications/examples/models/db.py (revision 953)
> > > +++ applications/examples/models/db.py (working copy)
> > > @@ -33,8 +33,12 @@
> > > SQLField('product_id', db.products), SQLField
> > > ('quantity'
> > > , 'integer'))
>
> > > -purchased = (db.users.id == db.purchases.buyer_id) & (db.products.id
> > > - == db.purchases.product_id)
> > > +from gluon.settings import settings
> > > +if not settings.web2py_runtime_gae:
> > > + purchased = (db.users.id == db.purchases.buyer_id) &
> > > (db.products.id
> > > + == db.purchases.product_id)
> > > +else:
> > > + purchased = None
>
> > > db.users.name.requires = IS_NOT_EMPTY()
> > > db.users.email.requires = [IS_EMAIL(), IS_NOT_IN_DB(db,
> > > 'users.email')]
> > > Index: gluon/cache.py
> > > ===================================================================
> > > --- gluon/cache.py (revision 953)
> > > +++ gluon/cache.py (working copy)
> > > @@ -160,11 +160,21 @@
> > > class Cache(object):
>
> > > def __init__(self, request):
> > > - self.ram = CacheInRam(request)
> > > - try:
> > > - self.disk = CacheOnDisk(request)
> > > - except IOError:
> > > - logging.warning('no cache.disk')
> > > +
> > > + from gluon.settings import settings
> > > + if settings.web2py_runtime_gae:
> > > + from gluon.contrib.gae_memcache import MemcacheClient
> > > + self.ram=self.disk=MemcacheClient(request)
> > > + else:
> > > +
> > > +
> > > + self.ram = CacheInRam(request)
> > > + try:
> > > + self.disk = CacheOnDisk(request)
> > > + except IOError:
> > > + logging.warning('no cache.disk (IOError)')
> > > + except AttributeError:
> > > + logging.warning('no cache.disk (AttributeError)')
>
> > > def __call__(
> > > self,
> > > Index: gluon/compileapp.py
> > > ===================================================================
> > > --- gluon/compileapp.py (revision 953)
> > > +++ gluon/compileapp.py (working copy)
> > > @@ -37,7 +37,8 @@
> > > logging.warning('unable to import py_compile')
> > > from rewrite import error_message_custom
>
> > > -is_gae = settings.web2py_runtime in
> > > ['gae:development','gae:production']
> > > +#is_gae = settings.web2py_runtime in
> > > ['gae:development','gae:production']
> > > +is_gae = settings.web2py_runtime_gae
>
> > > TEST_CODE = \
> > > r"""
> > > Index: gaehandler.py
> > > ===================================================================
> > > --- gaehandler.py (revision 953)
> > > +++ gaehandler.py (working copy)
> > > @@ -15,10 +15,15 @@
>
> > > from gluon.settings import settings
>
> > > +
> > > +
> > > +
> > > if os.environ.get('SERVER_SOFTWARE','').startswith('Devel'):
> > > - (settings.web2py_runtime, debug) = ('gae:development', True)
> > > + (settings.web2py_runtime, settings.web2py_runtime_gae, debug) = \
> > > + ('gae:development', True, True)
> > > else:
> > > - (settings.web2py_runtime, debug) = ('gae:production', False)
> > > + (settings.web2py_runtime, settings.web2py_runtime_gae, debug) = \
> > > + ('gae:production', True, False)
>
> > > import gluon.main
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"web2py Web Framework" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/web2py?hl=en
-~----------~----~----~----~------~----~------~--~---