Running the web2py mini-fb clone demo (additional info and some questions)

65 kali dilihat
Langsung ke pesan pertama yang belum dibaca

Arbie Samong

belum dibaca,
24 Mar 2011, 07.06.3124/03/11
kepadaweb...@googlegroups.com

I actually tried the tutorial posted here:

http://blip.tv/file/4912976


and here are some information that wasn't mentioned but might be helpful for absolute beginners like me:

  • You must first register with janrain and take note of the application name

  • In models/db_janrain.py, you need to set domain to the application name you registered with. In the tutorial it is set to web2py. It is https://blabla.rpxnow.com/, where blabla is the applciation name.

  • The file janrain_api_key.txt will contain only the secret api key, which you can see in the janrain dashboard.

  • The web2py source does not have app.yaml. So you copy the one in google_appengine/new_project_template over to web2py/.

  • Edit the file and set the application (first line) to the one you registered with in app engine. Then set script to gaehandler.py (under handlers)

  • When running the local app engine instance for the first time to build indexes, be sure to change the url in models/db_janrain.py from localhost:8000 to localhost:8080. If you don't it will redirect to the web2py instance instead of the app engine instance, and the indexes will not be built causing an error when running it in appspot.com

  • When deploying, appcfg can be found under the google_appengine/ folder, so just copy the full path.


Now, for the question. The friends and search pages do not work when deploying on GAE, both on localhost:8080 and on the real server. It works fine when using the web2py server but not on the GAE. My best guess are database issues, since GAE might not be supporting the db calls used in the tutorial. The errors are:

  • on friends/default/friends/ when viewing the page

    ERROR    2011-03-24 07:34:36,785 restricted.py:55] In FILE: /home/arbie/Documents/python/workspace/supaprends/google_appengine/web2py/applications/friends/controllers/default.py

    Traceback (most recent call last):

      File "/home/arbie/Documents/python/workspace/supaprends/google_appengine/web2py/gluon/restricted.py", line 188, in restricted

        exec ccode in environment

      File "/home/arbie/Documents/python/workspace/supaprends/google_appengine/web2py/applications/friends/controllers/default.py:friends", line 93, in <module>

      File "/home/arbie/Documents/python/workspace/supaprends/google_appengine/web2py/gluon/globals.py", line 124, in <lambda>

        self._caller = lambda f: f()

      File "/home/arbie/Documents/python/workspace/supaprends/google_appengine/web2py/gluon/tools.py", line 2331, in f

        return action(*a, **b)

      File "/home/arbie/Documents/python/workspace/supaprends/google_appengine/web2py/applications/friends/controllers/default.py:friends", line 68, in friends

      File "/home/arbie/Documents/python/workspace/supaprends/google_appengine/web2py/gluon/dal.py", line 5009, in select

        return self.db._adapter.select(self.query,fields,attributes)

      File "/home/arbie/Documents/python/workspace/supaprends/google_appengine/web2py/gluon/dal.py", line 2892, in select

        (items, tablename, fields) = self.select_raw(query,fields,attributes)

      File "/home/arbie/Documents/python/workspace/supaprends/google_appengine/web2py/gluon/dal.py", line 2841, in select_raw

        tablename = self.get_table(query)

      File "/home/arbie/Documents/python/workspace/supaprends/google_appengine/web2py/gluon/dal.py", line 955, in get_table

        raise RuntimeError, "Too many tables selected"

    RuntimeError: Too many tables selected


  • on friends/default/search/ when trying to search 

    ERROR    2011-03-24 07:35:23,136 restricted.py:55] In FILE: /home/arbie/Documents/python/workspace/supaprends/google_appengine/web2py/applications/friends/controllers/default.py

    Traceback (most recent call last):

      File "/home/arbie/Documents/python/workspace/supaprends/google_appengine/web2py/gluon/restricted.py", line 188, in restricted

        exec ccode in environment

      File "/home/arbie/Documents/python/workspace/supaprends/google_appengine/web2py/applications/friends/controllers/default.py:search", line 93, in <module>

      File "/home/arbie/Documents/python/workspace/supaprends/google_appengine/web2py/gluon/globals.py", line 124, in <lambda>

        self._caller = lambda f: f()

      File "/home/arbie/Documents/python/workspace/supaprends/google_appengine/web2py/gluon/tools.py", line 2331, in f

        return action(*a, **b)

      File "/home/arbie/Documents/python/workspace/supaprends/google_appengine/web2py/applications/friends/controllers/default.py:search", line 59, in search

      File "/home/arbie/Documents/python/workspace/supaprends/google_appengine/web2py/gluon/dal.py", line 5009, in select

        return self.db._adapter.select(self.query,fields,attributes)

      File "/home/arbie/Documents/python/workspace/supaprends/google_appengine/web2py/gluon/dal.py", line 2892, in select

        (items, tablename, fields) = self.select_raw(query,fields,attributes)

      File "/home/arbie/Documents/python/workspace/supaprends/google_appengine/web2py/gluon/dal.py", line 2849, in select_raw

        filters = self.expand(query)

      File "/home/arbie/Documents/python/workspace/supaprends/google_appengine/web2py/gluon/dal.py", line 2734, in expand

        return expression.op(expression.first, expression.second)

      File "/home/arbie/Documents/python/workspace/supaprends/google_appengine/web2py/gluon/dal.py", line 2595, in OR

        def OR(self,first,second): raise SyntaxError, "Not supported"

    SyntaxError: Not supported


It would be great if somebody would post a way to get around these limitations assuming they are issues on the db layer. I *typed* the code in the video as verbatim as it could be.

Anthony

belum dibaca,
24 Mar 2011, 07.55.4424/03/11
kepadaweb...@googlegroups.com
Thank you. This is helpful.
 
Note, the web2py source *does* come with a GAE app.yaml file -- it's in the root web2py/ folder (along with queue.yaml), as explained in the book: http://web2py.com/book/default/chapter/11#Configuration
 
Actually, in the current development version, app.yaml and queue.yaml have been replaced with app.example.yaml and queue.example.yaml so they don't get overwritten upon web2py upgrade. See this thread: https://groups.google.com/forum/?fromgroups#!searchin/web2py/app.example.yaml/web2py/cd8Smoiv1V0/x-INRnFgJNoJ. The book should be changed to reflect this.
 
Anthony

Arbie Samong

belum dibaca,
24 Mar 2011, 08.22.1424/03/11
kepadaweb...@googlegroups.com
thanks for the reply, Anthony. The web2py source that I used came from here:
under Current, which is the file web2py_src.zip and it doesn't seem to contain either app.yaml or queue.yaml or *.example.yaml.

Massimo Di Pierro

belum dibaca,
24 Mar 2011, 09.25.0724/03/11
kepadaweb2py-users
I apologize. I thought I made all required changes but I missed one:

In controller replace:

friends = db(User.id==Link.source)
(Link.target==me).select(orderby=alphabetical)
requests = db(User.id==Link.target)
(Link.source==me).select(orderby=alphabetical)

with:


friends = db(Link.target==me).select()
requests = db(Link.source==me).select()

and change the friends.html view into:

{{extend 'layout.html'}}
<h2>Friendship Offered</h2>
<table>
{{for friend in friends:}}
<tr>

<td>{{=A(name_of(db.auth_user(friend.source)),_href=URL('wall',args=friend.source))}}
</td>
<td>{{if friend.accepted:}}accepted{{else:}}<button
onclick="ajax('{{=URL('friendship',args=('accept',friend.source))}}',
[],null); $(this).parent().html('accepted')">accept</button>{{pass}}</
td>
<td><button
onclick="ajax('{{=URL('friendship',args=('deny',friend.source))}}',
[],null); $(this).parent().html('denied')">deny</button></td>
</tr>
{{pass}}
</table>
<h2>Friendship Requested</h2>
<table>
{{for friend in requests:}}
<tr>

<td>{{=A(name_of(db.auth_user(friend.target)),_href=URL('wall',args=friend.target))}}
</td>
<td>{{if friend.accepted:}}accepted{{else:}}pending{{pass}}</td>
<td><button
onclick="ajax('{{=URL('friendship',args=('deny',friend.target))}}',
[],null); $(this).parent().html('removed')">remove</button></td>
</tr>
{{pass}}
</table>

This is because GAE cannot do joins.

I also think that on GAE the current Query

query = reduce(lambda a,b:a&b,
[User.first_name.contains(k)|
User.last_name.contains(k) \
for k in tokens])

is too complex and should be

query =
(User.first_name==tokens[0])&(User.last_name==tokens[1])



On Mar 24, 6:06 am, Arbie Samong <phek...@gmail.com> wrote:
> I actually tried the tutorial posted here:
>
> http://blip.tv/file/4912976
>
> and here are some information that wasn't mentioned but might be helpful for
> absolute beginners like me:
>
>    -
>
>    You must first register with janrain and take note of the application
>    name
>    -
>
>    In models/db_janrain.py, you need to set domain to the application name
>    you registered with. In the tutorial it is set to web2py. It is
>    https://blabla.rpxnow.com/, where blabla is the applciation name.
>    -
>
>    The file janrain_api_key.txt will contain only the secret api key, which
>    you can see in the janrain dashboard.
>    -
>
>    The web2py source does not have app.yaml. So you copy the one in
>    google_appengine/new_project_template over to web2py/.
>    -
>
>    Edit the file and set the application (first line) to the one you
>    registered with in app engine. Then set script to gaehandler.py (under
>    handlers)
>    -
>
>    When running the local app engine instance for the first time to build
>    indexes, be sure to change the url in models/db_janrain.py from
>    localhost:8000 to localhost:8080. If you don't it will redirect to the
>    web2py instance instead of the app engine instance, and the indexes will not
>    be built causing an error when running it in appspot.com
>    -
>
>    When deploying, appcfg can be found under the google_appengine/ folder,
>    so just copy the full path.
>
> Now, for the question. The friends and search pages do not work when
> deploying on GAE, both on localhost:8080 and on the real server. It works
> fine when using the web2py server but not on the GAE. My best guess are
> database issues, since GAE might not be supporting the db calls used in the
> tutorial. The errors are:
>
>    -
>
>    on friends/default/friends/ when viewing the page
>
>    ERROR    2011-03-24 07:34:36,785 restricted.py:55] In FILE:
>    /home/arbie/Documents/python/workspace/supaprends/google_appengine/web2py/a pplications/friends/controllers/default.py
>
>    Traceback (most recent call last):
>
>      File
>    "/home/arbie/Documents/python/workspace/supaprends/google_appengine/web2py/ gluon/restricted.py",
>    line 188, in restricted
>
>        exec ccode in environment
>
>      File
>    "/home/arbie/Documents/python/workspace/supaprends/google_appengine/web2py/ applications/friends/controllers/default.py:friends",
>    line 93, in <module>
>
>      File
>    "/home/arbie/Documents/python/workspace/supaprends/google_appengine/web2py/ gluon/globals.py",
>    line 124, in <lambda>
>
>        self._caller = lambda f: f()
>
>      File
>    "/home/arbie/Documents/python/workspace/supaprends/google_appengine/web2py/ gluon/tools.py",
>    line 2331, in f
>
>        return action(*a, **b)
>
>      File
>    "/home/arbie/Documents/python/workspace/supaprends/google_appengine/web2py/ applications/friends/controllers/default.py:friends",
>    line 68, in friends
>
>      File
>    "/home/arbie/Documents/python/workspace/supaprends/google_appengine/web2py/ gluon/dal.py",
>    line 5009, in select
>
>        return self.db._adapter.select(self.query,fields,attributes)
>
>      File
>    "/home/arbie/Documents/python/workspace/supaprends/google_appengine/web2py/ gluon/dal.py",
>    line 2892, in select
>
>        (items, tablename, fields) = self.select_raw(query,fields,attributes)
>
>      File
>    "/home/arbie/Documents/python/workspace/supaprends/google_appengine/web2py/ gluon/dal.py",
>    line 2841, in select_raw
>
>        tablename = self.get_table(query)
>
>      File
>    "/home/arbie/Documents/python/workspace/supaprends/google_appengine/web2py/ gluon/dal.py",
>    line 955, in get_table
>
>        raise RuntimeError, "Too many tables selected"
>
>    RuntimeError: Too many tables selected
>
>    -
>
>    on friends/default/search/ when trying to search
>
>    ERROR    2011-03-24 07:35:23,136 restricted.py:55] In FILE:
>    /home/arbie/Documents/python/workspace/supaprends/google_appengine/web2py/a pplications/friends/controllers/default.py
>
>    Traceback (most recent call last):
>
>      File
>    "/home/arbie/Documents/python/workspace/supaprends/google_appengine/web2py/ gluon/restricted.py",
>    line 188, in restricted
>
>        exec ccode in environment
>
>      File
>    "/home/arbie/Documents/python/workspace/supaprends/google_appengine/web2py/ applications/friends/controllers/default.py:search",
>    line 93, in <module>
>
>      File
>    "/home/arbie/Documents/python/workspace/supaprends/google_appengine/web2py/ gluon/globals.py",
>    line 124, in <lambda>
>
>        self._caller = lambda f: f()
>
>      File
>    "/home/arbie/Documents/python/workspace/supaprends/google_appengine/web2py/ gluon/tools.py",
>    line 2331, in f
>
>        return action(*a, **b)
>
>      File
>    "/home/arbie/Documents/python/workspace/supaprends/google_appengine/web2py/ applications/friends/controllers/default.py:search",
>    line 59, in search
>
>      File
>    "/home/arbie/Documents/python/workspace/supaprends/google_appengine/web2py/ gluon/dal.py",
>    line 5009, in select
>
>        return self.db._adapter.select(self.query,fields,attributes)
>
>      File
>    "/home/arbie/Documents/python/workspace/supaprends/google_appengine/web2py/ gluon/dal.py",
>    line 2892, in select
>
>        (items, tablename, fields) = self.select_raw(query,fields,attributes)
>
>      File
>    "/home/arbie/Documents/python/workspace/supaprends/google_appengine/web2py/ gluon/dal.py",
>    line 2849, in select_raw
>
>        filters = self.expand(query)
>
>      File
>    "/home/arbie/Documents/python/workspace/supaprends/google_appengine/web2py/ gluon/dal.py",
>    line 2734, in expand
>
>        return expression.op(expression.first, expression.second)
>
>      File
>    "/home/arbie/Documents/python/workspace/supaprends/google_appengine/web2py/ gluon/dal.py",

Anthony

belum dibaca,
24 Mar 2011, 10.19.4924/03/11
kepadaweb...@googlegroups.com
You are right. It actually looks like the change from app.yaml to app.example.yaml was made prior to the 1.94.1 release.
 
Massimo, why does app.example.yaml not appear in the current release (it's in trunk)?
 
Anthony
 

Massimo Di Pierro

belum dibaca,
24 Mar 2011, 12.09.3924/03/11
kepadaweb2py-users
Could be a mistake in the packaging makefile. Will fix and repost
tonight.

Arbie Samong

belum dibaca,
24 Mar 2011, 13.09.1524/03/11
kepadaweb...@googlegroups.com, Massimo Di Pierro
This got rid of the errors. Thanks Massimo.

The only thing I added was a try-except block on search() when no people were found. The simpler version of the query also restricted the search somehow (had to search first name and last name with the right capitalization) but I guess that's the trade off. Will look for a way to improve the search with the GAE caveats in mind.
Balas ke semua
Balas ke penulis
Teruskan
0 pesan baru