[webpy] Integrating web.py and Google App Engine - What is the situation ?

87 views
Skip to first unread message

ProfessionalIT

unread,
May 22, 2010, 7:05:07 PM5/22/10
to web.py
Hi Friends,

First of all, I would say that the purpose of this question is to
understand what the position of the web.py development team on
integrating with Google App Engine. The goal is not to criticize or
generate polemics.

IMHO, web.py as a wsgi application should have an easy integration
with Google App Engine.
Maybe (probably) because of my limited knowledge about the web.py
and wsgi I have had many difficulties to realize this integration. I
also see that the questions asked here on the list involving the
Google App Engine directly or indirectly, are not answered.

I think maybe the answers may not exist for three reasons:
1. There is no use, or people using web.py with Google App Engine.
2. There is no supporting documentation that manages security in the
use web.py with GAE. And here I can help.
3. There is interest from the development team to do / improve this
integration.

Today, for me the Google App Engine is strategic to my business (and
customers).

I have developed applications with Web2Py and Django. But because I
love the web.py I'd like to migrate these applications to it.

PS:
1. Sorry by my terrible english. Google Tradutor was my teacher.
2. Honestly, the purpose of my question is to understand what the
position of this integration. And I say this because, as my English is
terrible, I think I'm saying one thing and people can understand it
being another ...
3. This understanding is very important to me.


Thanks friends.

--
You received this message because you are subscribed to the Google Groups "web.py" group.
To post to this group, send email to we...@googlegroups.com.
To unsubscribe from this group, send email to webpy+un...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/webpy?hl=en.

justin caratzas

unread,
May 22, 2010, 9:47:25 PM5/22/10
to we...@googlegroups.com
Not speaking for the development team here, but I find integration to be quite trivial when it comes to using webpy on the Google App Engine.  Perhaps I hadn't seen these questions, but I'll go back and search the list to see if I can help resolve some of the issues.

Justin Caratzas

ProfessionalIT

unread,
May 22, 2010, 10:21:31 PM5/22/10
to web.py
Hi Justin,

above all, thank you, thank you very much.

Well, my main question is this:
http://groups.google.com/group/webpy/browse_thread/thread/7d690349fa255500

The problems related in this thread are:
1. First, I need populate a form that has a dropdown based in a
another Entity(in this case, in the Category Entity). To help you
understand... a Entity is as a table but, it' s a table in the Google
big table format.
2. After, I put the values in the rendered form and select a
category(in the Category dropdown) ... I submit it to save a new
record in your Post Entity, in this moment I receive a error because I
need load a Entity Category first and after associate this loaded
Category with the Post Entity. OK, this alternative solution I
implemented and it's work's fine, but when I load the form again (in a
edit method) you receive another error in the form.fill method.

I think that the root of all my problems is: How to map/associate
this Category Entity in a Dropdown.control, I say this because I think
that how did I can (and probably was) not have been more correct.

If you look in my code, you see:

result = data.all_categories() # this method return all records of
table category in GAE/big table format.
args = [(row.key().id(), row.title) for row in result] # I did not
know how to map here on Dropdown Entity Category, so I made this way.

new_post = form.Form(
form.Dropdown('category', args),

Any idea ?

-- Leandro.

justin caratzas

unread,
May 23, 2010, 9:11:16 AM5/23/10
to we...@googlegroups.com
Can you post the class model that you use to store the category entity?

江云帆

unread,
May 23, 2010, 8:59:59 PM5/23/10
to we...@googlegroups.com
acturally, i am only use web.py on GAE cause i like simple and lightweight library
and i cant see any difficult about using web.py on GAE, so what's your problem?

--
welcom to gtalk me
http://hi.baidu.com/jyf1987

ProfessionalIT

unread,
May 24, 2010, 8:54:59 AM5/24/10
to web.py
Hi Justin,

I'm sorry for the delay, follow the code of my data.py (do not be
scared with my code):

from google.appengine.api import users
from google.appengine.ext import db
import logging

from utils import slugify, versionate, markdown

class Category(db.Model):
title = db.StringProperty(required=True)

class Entry(db.Model):
author = db.UserProperty()
category = db.ReferenceProperty(Category, required=True,
collection_name='category_set')
title = db.StringProperty(required=True)
slug = db.StringProperty(required=True)
body = db.TextProperty(required=True)
published = db.DateTimeProperty(auto_now_add=True)
updated = db.DateTimeProperty(auto_now=True)
language = db.StringProperty(required=True)


def all_categories():
return Category.all()

def category_by_title(title):
logging.debug('parametro: ' + title)
logging.debug('===============in=============')
cat = db.Query(Category).filter('title =', title).get()
logging.debug('cat : ' + `cat`)
logging.debug('===============out=============')
return cat

def all_entries():
return Entry.all()

def last_updated():
import datetime
last = db.Query(Entry).order('-published').get()
return last.updated if last else datetime.datetime.now()

def latest_entries(limit=10):
return db.Query(Entry).order('-published').fetch(limit=limit)

def entry_by_slug(slug):
'''We're assuming all entries contain a unique slug.'''
return db.Query(Entry).filter('slug =', slug).get()

def exists_entry(slug):
q = db.Query(Entry).filter('slug =', slug).get()
return q is not None

def save_entry(entry):
slug = slugify(entry.title)
while exists_entry(slug):
slug = versionate(slug)

logging.debug('entry: ' + `entry`)
logging.debug('category: ' + `entry.category`)
logging.debug('title: ' + `entry.title`)
logging.debug('language: ' + `entry.language`)

db.put(Entry(
author=users.get_current_user(),
category=category_by_title(entry.category),
title=entry.title,
body=markdown(entry.text),
slug=slug,
language=entry.language
))

def save_category(category):
db.put(Category(title=category.title))

ProfessionalIT

unread,
May 24, 2010, 8:59:11 AM5/24/10
to web.py
Hi Friend,

On May 23, 9:59 pm, 江云帆 <jyf1...@gmail.com> wrote:
> acturally, i am only use web.py on GAE cause i like simple and lightweight
> library
> and i cant see any difficult about using web.py on GAE, so what's your
> problem?

My problem is(in GAE) generate a form(to put/edit values on a table/
entity) with a dropdown control where this dropdown control be based
in another table/entity.

Do you have this situation in your projects ?

-- Leandro.

江云帆

unread,
May 25, 2010, 1:34:58 AM5/25/10
to we...@googlegroups.com
well, i dont have many experience about orm usage,and i dont like server control logic.so couldnt give any advice sorry
--
welcom to gtalk me
http://hi.baidu.com/jyf1987

ProfessionalIT

unread,
May 25, 2010, 8:34:35 AM5/25/10
to web.py
Well,

I don't know if these is the best approach, but I have a solution
to this problem...

To don't change the source code of the framework, I make a copy of
the original form.py called gae_form.py(and put this file in the same
level of code.py) and in this file I put/change this places/codes:

1) Add this imports in the begin of the file:

import logging
from google.appengine.ext import db

2) Change the imports:

[before]
import webapi as web
import utils, net

[after]
import web.webapi as web
import web.utils as utils, web.net as net

3) Change implementation of the function attrget():

[before ]
def attrget(obj, attr, value=None):
if hasattr(obj, 'has_key') and obj.has_key(attr): return obj[attr]
if hasattr(obj, attr): return getattr(obj, attr)
return value

[after ]
def attrget(obj, attr, value=None):
if isinstance(obj,db.Model):
try:
if attr == 'key':
return obj.key()
gae_attribute = getattr(obj,attr)
if isinstance(gae_attribute,db.Model):
id_reference = gae_attribute.key().id()
return id_reference
else:
return gae_attribute
except Exception, ex:
logging.debug(ex)
else:
if hasattr(obj, 'has_key') and obj.has_key(attr): return
obj[attr]
if hasattr(obj, attr): return getattr(obj, attr)
return value

And finally, my forms.py (my file with the definitions of the forms
used in the app):

# from web import form
import gae_form as form
import data

def getPostForm():
category_list = data.all_categories()
category_options = [(row.key().id(), row.title) for row in
category_list]
post_form = form.Form(
form.Hidden('key'),
form.Dropdown('category', category_options),
form.Textbox('title'),
form.Textarea('body'),
form.Dropdown('language', [('pt', 'Portuguese'), ('en',
'English')]),
form.Button('Submit!')
)
return post_form

def getCategoryForm():
category_form = form.Form(
form.Textbox('title'),
form.Button('Submit!')
)
return category_form

Well, now I have a form to manipulate a GAE table/entity with a
Dropdown control based in another table/entity that work's fine.

My last question is: This is the best approach / solution
implementation ?

Any suggestion will be very welcome.

Thanks for all help.
Reply all
Reply to author
Forward
0 new messages