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
-~----------~----~----~----~------~----~------~--~---

Reply via email to