[web2py] Re: Logic outside function problem.

2010-09-05 Thread annet
Weheh,

Thanks for your reply.

> Ah, I see. You want it inline, outside the functions. First of all,
> the 2 lines session.id and session.name at the very top will probably
> cause trouble all by themselves. Why don't you delete them?

I deleted them, and that solved the problem.

> I suppose the rest of the code should work, but perhaps you should put
> the rest of the code inside a function and use routes to remap URL?
> Anyway, I'm still curious what results you got?

I haven't used routes before to remap URLs, for now your solution
works:


if not request.args:
redirect(URL(r=request,c='default',f='error'))
else:
if not session.id or session.id!=request.args[0]:
session.id=request.args[0]
row=db(db.member.id==session.id).select(db.member.name)
if row:
session.name=row[0].name

response.menu = [
 
['Home',request.function=='index',URL(r=request,f='index',args=session.id)],
[...],
 
['Contact',request.function=='contact',URL(r=request,f='contact',args=session.id)]]


Massimo,

> This does not work because if not request.args you redirect to a url
> that does not have request.args and your server gets into an infinite
> loop.

Actually the visitor should never see the error view. The visitor
either visits
the application from a link in an index function:


  {{=A(row.member.name,_onmouseover="this.style.cursor='pointer';",\
  _onclick="javascript:details('%s')"%URL(r=request,a='demo',c='site',
  f='home',args=[row.member.id]))}}


from, a bookmarked page:

http://www.mydomain.nl/demo/site/f/1

or from a domain registered by the member which points to a Static/CGI/
PHP
application in which I use an iFrame tag in the index.html file to
include the
contents of http://www.mydomain.nl/demo/site/f/1

At the moment the error view is just there to prevent web2py from
issuing an error ticket when I expose a function from within the admin
interface that requires args to be set.


> You are reinventing the wheel. Why don't you just use auth and
> decorate the functions that require a user?

Because it has nothing to do with auth. I assume you got confused by
the table name user. I changed that to member. I am working on an
idea and I was curious whether my idea about navigation would work
this way.


Kind regards,

Annet.


[web2py] Re: Help needed with upload files & their manipulation [closed]

2010-09-05 Thread weheh
Works now. Thanks. I still need to get the knack of this. I hope
practice makes perfect.

On Sep 5, 11:39 pm, mdipierro  wrote:
> replace
>
>   stream=TAG(stream).flatten() # THIS IS WHERE THE PROBLEM IS
>
> with
>
>   import cStringIO
>   stream=cStringIO.StringIO(TAG(stream).flatten())
>
> On Sep 5, 10:29 pm, weheh  wrote:
>
> > I need to upload a file to uploads, process it, and store the
> > processed result in a new folder/file.
>
> > # I've defined the following two models
> > db.define_table('infile',
> >   Field('parent',db.parent),
> >   Field('name','upload',autodelete=True,uploadseparate=True))
> > db.define_table('outfile',
> >   Field('parent',db.parent),
> >   Field('name','upload',autodelete=True,uploadseparate=True))
>
> > # Here's the controller for uploading the input file
> > def input():
> >  ... blah ...
> >   if form.accepts(request.vars,...):
> >     id=create_parent(form)
> >     request.vars.name.infile.seek(0) # rewind uploaded file
> >     db.infile.insert(parent=id,
>
> > name=db.infile.name.store(request.vars.name.file,request.vars.name.filename))
> >     process(id)
> >     redirect( ...)
>
> > # and here's the routine for processing the input file to generate the
> > output file
> > def process(id):
> >   """Flattens infile and writes outfile"""
> >   # I want to read the input file that was uploaded and then write
> >   # a flattened version of the uploaded file to a path /myapp/static/
> > output/ab/xy/out_abjljsdfljljsdf.xykjsdkjhsf.txt
> >   # I've start with this:
> >   infile=db(db.file.parent==id).select(db.file.name).first()
> >   inpath=get_full_path(infile.name)
> >   stream=open(inpath,'rb')
> >   stream=TAG(stream).flatten() # THIS IS WHERE THE PROBLEM IS
> >   outpath=create_empty_file_under_static_slash_txtfiles(suffix='txt')
> >   db.outfile.insert(parent=id,
> >     name=db.outfile.name.store(stream,outpath)) # THIS DOESN'T WORK
> > BECAUSE IT'S NOT A STREAM
> >   return
>
> > I've embedded comments above showing where I'm running into problems.
> > What's the best way for me to be able to flatten the input file and
> > write to the output file. NOTE: I am doing things this way because I
> > also want the input and output files to be autodeleted in case the
> > parent record is deleted.
>
> > p.s. unless I'm doing things the right way, which I doubt, don't worry
> > about syntax too much above since I just typed it into this post and
> > didn't copy and paste from a running program.


[web2py] Re: Help needed with upload files & their manipulation

2010-09-05 Thread mdipierro
replace

  stream=TAG(stream).flatten() # THIS IS WHERE THE PROBLEM IS

with

  import cStringIO
  stream=cStringIO.StringIO(TAG(stream).flatten())

On Sep 5, 10:29 pm, weheh  wrote:
> I need to upload a file to uploads, process it, and store the
> processed result in a new folder/file.
>
> # I've defined the following two models
> db.define_table('infile',
>   Field('parent',db.parent),
>   Field('name','upload',autodelete=True,uploadseparate=True))
> db.define_table('outfile',
>   Field('parent',db.parent),
>   Field('name','upload',autodelete=True,uploadseparate=True))
>
> # Here's the controller for uploading the input file
> def input():
>  ... blah ...
>   if form.accepts(request.vars,...):
>     id=create_parent(form)
>     request.vars.name.infile.seek(0) # rewind uploaded file
>     db.infile.insert(parent=id,
>
> name=db.infile.name.store(request.vars.name.file,request.vars.name.filename))
>     process(id)
>     redirect( ...)
>
> # and here's the routine for processing the input file to generate the
> output file
> def process(id):
>   """Flattens infile and writes outfile"""
>   # I want to read the input file that was uploaded and then write
>   # a flattened version of the uploaded file to a path /myapp/static/
> output/ab/xy/out_abjljsdfljljsdf.xykjsdkjhsf.txt
>   # I've start with this:
>   infile=db(db.file.parent==id).select(db.file.name).first()
>   inpath=get_full_path(infile.name)
>   stream=open(inpath,'rb')
>   stream=TAG(stream).flatten() # THIS IS WHERE THE PROBLEM IS
>   outpath=create_empty_file_under_static_slash_txtfiles(suffix='txt')
>   db.outfile.insert(parent=id,
>     name=db.outfile.name.store(stream,outpath)) # THIS DOESN'T WORK
> BECAUSE IT'S NOT A STREAM
>   return
>
> I've embedded comments above showing where I'm running into problems.
> What's the best way for me to be able to flatten the input file and
> write to the output file. NOTE: I am doing things this way because I
> also want the input and output files to be autodeleted in case the
> parent record is deleted.
>
> p.s. unless I'm doing things the right way, which I doubt, don't worry
> about syntax too much above since I just typed it into this post and
> didn't copy and paste from a running program.


[web2py] Help needed with upload files & their manipulation

2010-09-05 Thread weheh
I need to upload a file to uploads, process it, and store the
processed result in a new folder/file.

# I've defined the following two models
db.define_table('infile',
  Field('parent',db.parent),
  Field('name','upload',autodelete=True,uploadseparate=True))
db.define_table('outfile',
  Field('parent',db.parent),
  Field('name','upload',autodelete=True,uploadseparate=True))

# Here's the controller for uploading the input file
def input():
 ... blah ...
  if form.accepts(request.vars,...):
id=create_parent(form)
request.vars.name.infile.seek(0) # rewind uploaded file
db.infile.insert(parent=id,
 
name=db.infile.name.store(request.vars.name.file,request.vars.name.filename))
process(id)
redirect( ...)

# and here's the routine for processing the input file to generate the
output file
def process(id):
  """Flattens infile and writes outfile"""
  # I want to read the input file that was uploaded and then write
  # a flattened version of the uploaded file to a path /myapp/static/
output/ab/xy/out_abjljsdfljljsdf.xykjsdkjhsf.txt
  # I've start with this:
  infile=db(db.file.parent==id).select(db.file.name).first()
  inpath=get_full_path(infile.name)
  stream=open(inpath,'rb')
  stream=TAG(stream).flatten() # THIS IS WHERE THE PROBLEM IS
  outpath=create_empty_file_under_static_slash_txtfiles(suffix='txt')
  db.outfile.insert(parent=id,
name=db.outfile.name.store(stream,outpath)) # THIS DOESN'T WORK
BECAUSE IT'S NOT A STREAM
  return

I've embedded comments above showing where I'm running into problems.
What's the best way for me to be able to flatten the input file and
write to the output file. NOTE: I am doing things this way because I
also want the input and output files to be autodeleted in case the
parent record is deleted.

p.s. unless I'm doing things the right way, which I doubt, don't worry
about syntax too much above since I just typed it into this post and
didn't copy and paste from a running program.


[web2py] Re: Thank You Massimo and all others

2010-09-05 Thread Richard
when I wrote that post there wasn't a central source of documentation
but later the online book came out so I crossed that point out and
added a link. I have added brackets to try and make my intention more
clear.


On Sep 6, 5:07 am, bally boy  wrote:
> Yes it is definitely real productive. By the way just went through your
> blog.. what baffles me is how can this be one of the downsides:-
>
> -->online book now available here 
>
> Or is it just a typo :-)
>
> Have Fun!
>
>
>
>
>
>
>
> On Sun, Sep 5, 2010 at 6:15 PM, Richard  wrote:
> > "there was Massimo standing alone holding the flag"
> > haha, glad you tried it out anyway.
>
> > I was also surprised how productive web2py is and yet how much
> > criticism it gets.
>
> >http://blog.sitescraper.net/2010/06/web2py-flexible-python-web-framew...
>
> > On Sep 4, 5:22 am, bally boy  wrote:
> > > Hi guys.. I have been working across plenty of frameworks, from
> > > django, to pylons to turbogears and more recently to flask. And yes
> > > each one of them is beautiful and has that feel of awesomeness in
> > > their own way. All these days while comparing frameworks I used to
> > > come across web2py but then there were enough comments by many others
> > > which sort of stopped me from using it , and there was Massimo
> > > standing alone holding the flag , countering every other comment ,
> > > accepting what he should and rejecting what was wrong.
>
> > > And possibly his posts and his comments were the only reason that
> > > around few days back , I decided to start using it. And wow , what an
> > > awesome framework, a full stack one , which just does not make web
> > > development easier , but am sure it teaches a lot of those youngsters
> > > out there what web development is.
>
> > > I guess I got in at the right time, particularly when the third
> > > edition of the book is just put up there.The documentation is
> > > excellent. A big thanks to all those who are involved in the
> > > development web2py.


[web2py] Re: TAGs

2010-09-05 Thread weheh
I'm in the process of copying markdown_serializer to modules and
modifying it to treat tags differently. I don't anticipate running
into troubles importing from there and then callying my_serializer, do
you?

On Sep 5, 6:51 pm, mdipierro  wrote:
> html = TAG('xxxyyy')
> for item in html.components: print item
>
> from gluon.html import markdown_serializer
> print html.flatten(render=markdown_serializer)
>
> On Sep 4, 11:35 pm, weheh  wrote:
>
> > - How to get a list of all elements in an html string?
> > - How to specify my own render routine like markmin_serializer &
> > markdown_serializer? Where to put this code? Would it be "from modules
> > include my_serializer" and
> > my_html_string.flatten(render=my_serializer) ?


[web2py] Re: Where to suggest edits for new book? [Closed]

2010-09-05 Thread weheh
Got it to work. Problem was that Firebug was taking up my whole window
and the login wasn't displaying, or something like that.

On Sep 5, 8:36 pm, Anthony  wrote:
> Google login works fine for me. Actually, it works too well -- I seem
> to be able to edit pages without ever having requested Editor status
> from Massimo. So, it looks like anyone with a Google, Yahoo, etc.
> account can edit the book at will -- is that how it's supposed to
> work? (Note, I didn't actually make any changes, but I was able to get
> to the markmin editor -- maybe it wouldn't have worked if I had
> clicked Submit.)
>
> Anthony
>
> On Sep 5, 6:49 pm, mdipierro  wrote:
>
> > works for me. Is anybody else having problems?
>
> > On Sep 4, 11:36 pm, weheh  wrote:
>
> > > Hi Massimo - I have tried logging in with my Google account but
> > > couldn't I got a popup window that loaded a blank page, and then
> > > nothing. I don't have accounts with the other services, so need the
> > > Google auth.
>
> > > On Sep 4, 11:54 pm, mdipierro  wrote:
>
> > > > yes. Please login and then email me. I will make you editor.


[web2py] Re: change Auth.change_password

2010-09-05 Thread mdipierro
This is a bug. Thanks Jose. Now fixed in trunk. please try it.

On Sep 5, 8:07 pm, Jose  wrote:
> I have a legacy database, which we have created the tables to use
> Auth.
>
> We have inserted in auth_user all users through a process, for most
> know the email, so we have set an empty string, and we validate the
> user by username.
>
> In those days we had a situation where I've gone literally mad. I find
> that all passwords are the same for all users. After much spin, I
> found that this situation occurs when a user changes the password.
>
> Viewing Note Auth.change_password code based on the user email
> changes, to identify the record, instead of the id, so for all users
> who do not have a defined email will be changed.
>
> It seems better to base the criterion of identification in the id and
> not in the email.
> chage line:
> s = db (table_user.email == self.user.email)
>
> by:
> s = db (table_user.id == self.user.id)
>
> Regards
> Jose


[web2py] change Auth.change_password

2010-09-05 Thread Jose
I have a legacy database, which we have created the tables to use
Auth.

We have inserted in auth_user all users through a process, for most
know the email, so we have set an empty string, and we validate the
user by username.

In those days we had a situation where I've gone literally mad. I find
that all passwords are the same for all users. After much spin, I
found that this situation occurs when a user changes the password.

Viewing Note Auth.change_password code based on the user email
changes, to identify the record, instead of the id, so for all users
who do not have a defined email will be changed.

It seems better to base the criterion of identification in the id and
not in the email.
chage line:
s = db (table_user.email == self.user.email)

by:
s = db (table_user.id == self.user.id)

Regards
Jose


[web2py] Re: Problem with checkboxes widget

2010-09-05 Thread Fran
On Sep 6, 12:10 am, mdipierro  wrote:
> What is the definition for the field in question? Probably you have
> type='string' but it should be type='list:integer'

You're right, I did, wasn't aware about this new field type having
been introduced.

I'm still seeing the exact same issues with the checkboxes though.

I can see the internal structure has changed - now see: 957

F

> On Sep 5, 3:56 pm, Fran  wrote:
> > I'm running latest stable release (Bzr r2247) & trying to use this for
> > a multiselect field:
> > widget = SQLFORM.widgets.checkboxes.widget
> > But it's not working properly.
> > The create form works fine - the widget appears to work fine & the
> > database is indeed populated properly with the expected:
> > '|8|9|7|'
> > This displays fine in read screens.
> > However it fails to work in update forms - the checkboxes don't show
> > up as checked & so if the record is saved then the previous checkbox
> > states are lost :/
> > I tracked this down 
> > to:http://bazaar.launchpad.net/~mdipierro/web2py/devel/annotate/head:/gl...
> > (value = '|8|9|7|')
> > values = not isinstance(value,(list,tuple)) and [value] or value
> > (values = ['|8|9|7|'])
> > k in values
> > (False)
>
> > The old, commented, code works fine though:
> > values = re.compile('[\w\-:]+').findall(str(value))
> > (values = ['8', '9', '7'])
> > k in values
> > (True)
>
> > I think the change was made to avoid a relatively slow call to 're'
> > right?
> > However it seems not to work properly...
>
> > Many thanks :)
> > Fran.


[web2py] Re: Where to suggest edits for new book?

2010-09-05 Thread Anthony
Google login works fine for me. Actually, it works too well -- I seem
to be able to edit pages without ever having requested Editor status
from Massimo. So, it looks like anyone with a Google, Yahoo, etc.
account can edit the book at will -- is that how it's supposed to
work? (Note, I didn't actually make any changes, but I was able to get
to the markmin editor -- maybe it wouldn't have worked if I had
clicked Submit.)

Anthony

On Sep 5, 6:49 pm, mdipierro  wrote:
> works for me. Is anybody else having problems?
>
> On Sep 4, 11:36 pm, weheh  wrote:
>
>
>
> > Hi Massimo - I have tried logging in with my Google account but
> > couldn't I got a popup window that loaded a blank page, and then
> > nothing. I don't have accounts with the other services, so need the
> > Google auth.
>
> > On Sep 4, 11:54 pm, mdipierro  wrote:
>
> > > yes. Please login and then email me. I will make you editor.
>



[web2py] Re: Web2py Full Text Search Options

2010-09-05 Thread Anthony
On Sep 5, 7:12 pm, mdipierro  wrote:
> You use a relational database an you do not have too much data
> (~1) records you can do
>
> db(db.mytable.myfield.contains('text')).select()

This just does a basic search using the SQL "LIKE" operator, right? So
no real search engine features like word stemming, relevance ranking,
keyword highlighting, etc.?

Since real search functionality is an important feature for many
websites, it would be great if web2py could offer some easy to use
options. I think MySQL and PostgreSQL both have some decent built-in
full text search functionality, and then there are options like
Sphinx, Lucene/Solr, etc. If web2py could provide some plugins, or at
least some recipes in the book or on web2pyslices.com, that would be a
big help. Perhaps it would be easiest to start with Postgres, since
that seems to be a popular RDBMS for web2py and wouldn't require any
additional software.

Anthony


[web2py] Re: Problem loading http://groups.google.com/group/web2py

2010-09-05 Thread Anthony
On Sep 5, 2:00 am, annet  wrote:
> > I just had this same issue with the web2py google group, but not with
> > another group that I follow. Strange.
>
> So had I, however, when I navigate to a bookmarked page (so to .../
> browse_thread/...) this problem doesn't
> occur. Onlyhttp://groups.google.com/group/web2pytakes a long time to
> get loaded.

Yes, as I mentioned, I think the reason the problem is limited to the
home page only is because of the inclusion of the Pages section, which
displays an error when the home page finally loads (the "Pages" page
at /web2py/web displays the same error and has a similarly slow load
time).

If Massimo can remove the Pages section from the home page, perhaps
that will fix the problem (of course, we'll still have a problem with
the Pages functionality not working, but I'm not sure we're using that
anyway). I also recently noticed an error displayed in the Files
section of the home page, so it might be a good idea to remove that
section as well.

Anthony


[web2py] Re: Web2py Full Text Search Options

2010-09-05 Thread mdipierro
You use a relational database an you do not have too much data
(~1) records you can do

db(db.mytable.myfield.contains('text')).select()

If you have lots of data and lots of users you need something better.
I have never user Xapian. Ihave heard good things about http://sphinxsearch.com/

Massimo


On Sep 5, 11:53 am, John  wrote:
> Hi all.
> I'm newby in web2py.
>  How to  implement full text search in my web2py web application?
>   I am a big fan of the Xapian search engine library. Any plugin,
> recipes  suggestion ?
>  Thanks ,
>   John


[web2py] Re: Problem with checkboxes widget

2010-09-05 Thread mdipierro
What is the definition for the field in question? Probably you have
type='string' but it should be type='list:integer'

On Sep 5, 3:56 pm, Fran  wrote:
> I'm running latest stable release (Bzr r2247) & trying to use this for
> a multiselect field:
> widget = SQLFORM.widgets.checkboxes.widget
>
> But it's not working properly.
> The create form works fine - the widget appears to work fine & the
> database is indeed populated properly with the expected:
> '|8|9|7|'
> This displays fine in read screens.
> However it fails to work in update forms - the checkboxes don't show
> up as checked & so if the record is saved then the previous checkbox
> states are lost :/
>
> I tracked this down 
> to:http://bazaar.launchpad.net/~mdipierro/web2py/devel/annotate/head:/gl...
> (value = '|8|9|7|')
> values = not isinstance(value,(list,tuple)) and [value] or value
> (values = ['|8|9|7|'])
> k in values
> (False)
>
> The old, commented, code works fine though:
> values = re.compile('[\w\-:]+').findall(str(value))
> (values = ['8', '9', '7'])
> k in values
> (True)
>
> I think the change was made to avoid a relatively slow call to 're'
> right?
> However it seems not to work properly...
>
> Many thanks :)
> Fran.


[web2py] Re: Logic outside function problem.

2010-09-05 Thread mdipierro
This does not work because if not request.args you redirect to a url
that does not have request.args and your server gets into an infinite
loop.

You are reinventing the wheel. Why don't you just use auth and
decorate the functions that require a user?

On Sep 5, 11:42 am, annet  wrote:
> In a controller outside all functions I have this code:
>
> session.id
> session.name
>
> if not request.args:
>     redirect(URL(r=request,c='default',f='error'))
> else:
>     if not session.id or session.id!=request.args[0]:
>         session.id=request.args[0]
>         row=db(db.user.id==session.id).select(db.user.name)
>         if row:
>             session.name=row[0].name
>
> The idea is multiple users sharing one app . The menu items in the app
> all have args[0] set to session.id, when session.id hasn't been set or
> args[0] for some reason changes (bookmarked page), the code should set
> the id and name in session to the current user's id and name, who's id
> is in request.args[0].
>
> I thought the code above would exactly do this, but it doesn't, why
> not?
>
> Kind regards,
>
> Annet.


[web2py] Re: auth.settings.login.next is not taking affect

2010-09-05 Thread mdipierro
It is not working because you are settings auth.settings.login_next
within the scope of one http request, after redirect you have another
http request and everything is reset. Only session variables persist
from one http request to another.

You can simplify your code and do what you ask in this way:

def index():
meetingparm = (request.env.http_host or '').split('.')[0]
meeting = db(db.meeting.link==meetingparm).select().first()
if meeting:
next =
URL('meetings','getmeetingpassword',args=meeting.id)
redirect(URL('user',args='login',vars=dict(_next=next)))
return dict(message=T(''))

I think you want
  (request.env.http_host or '').split('.')[0]
instead of
  request.env.http_host.split('.')[1]
but that is a guess.

On Sep 5, 8:07 am, "david.waldrop"  wrote:
> I have an application that uses the built in auth components.  Users
> can come to the site wither by hitting the root url, or via a link
> that has been emailed which contains a specific community.  What I
> want to happen is the following:
>
> 1) if a user enterswww.myapp.comthey get the default splash screen
> 2) if a user clicks a link form an invitation email
>        the user is sent to the login page
>        the user is sent to a function to validate the specific
> community password
>        if successful the user is taken to the specific community
>
> I have the function that validates the community password and
> redirects to the specific community
> the issue is that when I set auth.settings.login.next = myfunction it
> is not respected
>
> I have played with putting this in my model file, but got an error
> message form teh server saying too many redirects.  Ithink this is
> because the model is called so frequently.  I now have the following
> in my default/index controller:
>
> def index():
>     # if user clicked email link, redirect to longin and set url to
> get and check meeting password
>     meetingparm = request.env.http_host.split('.')[1]
>     if len(meetingparm):
>         meeting = db(db.meeting.link==meetingparm).select()
>         if len(meeting):     # user clicked a link with a valid
> meeting, lets get'em logged in and figure out who they are
>             meeting = meeting[0]
>             auth.settings.login_next =
> URL(r=request,c='meetings',f='getmeetingpassword',args=meeting.id)
>             redirect(URL(r=request,f='user',args='login'))
>     return dict(message=T(''))
>
> What happens when I click on the link is the login screen is displayed
> and after I enter credentials I am taking to the specific community,
> instead of the function that checks of community password.
>
> Do I have this is in the right place? if so, why isn't the
> 'getmeetingpassword' redirect taking affect?


[web2py] Re: TAGs

2010-09-05 Thread mdipierro
html = TAG('xxxyyy')
for item in html.components: print item

from gluon.html import markdown_serializer
print html.flatten(render=markdown_serializer)



On Sep 4, 11:35 pm, weheh  wrote:
> - How to get a list of all elements in an html string?
> - How to specify my own render routine like markmin_serializer &
> markdown_serializer? Where to put this code? Would it be "from modules
> include my_serializer" and
> my_html_string.flatten(render=my_serializer) ?


[web2py] Re: Where to suggest edits for new book?

2010-09-05 Thread mdipierro
works for me. Is anybody else having problems?

On Sep 4, 11:36 pm, weheh  wrote:
> Hi Massimo - I have tried logging in with my Google account but
> couldn't I got a popup window that loaded a blank page, and then
> nothing. I don't have accounts with the other services, so need the
> Google auth.
>
> On Sep 4, 11:54 pm, mdipierro  wrote:
>
> > yes. Please login and then email me. I will make you editor.
>
> > On Sep 4, 10:49 pm, weheh  wrote:
>
> > > Thank you so very much for the new book MDP! It is wonderful. I have
> > > found minor typos and grammar issues and some things of more
> > > consequence, but I can't make comments in the doc like I used to be
> > > able. Where do you want the community to make such comments?


[web2py] Web2py Full Text Search Options

2010-09-05 Thread John
Hi all.
I'm newby in web2py.
 How to  implement full text search in my web2py web application?
  I am a big fan of the Xapian search engine library. Any plugin,
recipes  suggestion ?
 Thanks ,
  John


[web2py] Re: upgraded to 1.83.2 with db table file appears corrupted

2010-09-05 Thread berubejd
I realize it hasn't been a large amount of time but I haven't had any
occurrence of the problem since upgrading to 1.84.0.

On Sep 1, 11:34 pm, berubejd  wrote:
> Here are the answers to your questions in my case:
>
>  - I am using 1.83.2 on Windows.
>  - The DB in this test is sqlite.
>  - I am using a custom auth but 2 of the 3 instances of the problem
> (another db table file was removed since I posted earlier today)
> occurred in non-auth tables.
>  - I am not using 'notnull = True' on any table within the
> application.
>  - I will download the nightly build now and let you know how it works
> out.
>
> On Sep 1, 9:09 pm, mdipierro  wrote:
>
>
>
> > ... and what db are you using, sqlite?
> > do you use a custom auth table?
> > do you use notnull=True in any of your tables?
>
> > Massimo
>
> > On Sep 1, 11:07 pm, mdipierro  wrote:
>
> > > before we work on a fix. Let me understand what is causing this. What
> > > version are you upgrading from?
>
> > > massimo
>
> > > On Sep 1, 6:07 pm, berubejd  wrote:
>
> > > > This has happened to me twice in the last week on two different
> > > > tables.  I have started backing up the table files so that I can
> > > > restore them.  I will try to use fake_migrate next time.
>
> > > > Is there any way to avoid having this happen in the first place?
>
> > > > Thanks!
> > > > Jeff
>
> > > > On Sep 1, 10:55 am, mdipierro  wrote:
>
> > > > > yes. db.define_table(...,fake_migrate=True)
>
> > > > > On Sep 1, 12:11 pm, vince  wrote:
>
> > > > > > upgraded to 1.83.2, the application itself run fine just with this
> > > > > > error appearing in error log sometimes.
>
> > > > > > is there any way to regenerate the db table file?
>
> > > > > > Traceback (most recent call last):
> > > > > >   File "gluon/restricted.py", line 186, in restricted
> > > > > >     exec ccode in environment
> > > > > >   File "/home/web2py/applications/cms/models/db.py", line 36, in
> > > > > > 
> > > > > >     auth.define_tables()                         # creates all 
> > > > > > needed
> > > > > > tables
> > > > > >   File "gluon/tools.py", line 1153, in define_tables
> > > > > >     self.settings.table_membership_name, migrate))
> > > > > >   File "gluon/sql.py", line 1359, in define_table
> > > > > >     t._create(migrate=migrate, fake_migrate=fake_migrate)
> > > > > >   File "gluon/sql.py", line 1839, in _create
> > > > > >     raise RuntimeError, 'File %s appears corrupted' % self._dbt
> > > > > > RuntimeError: File /home/web2py/applications/cms/databases/
> > > > > > fb87181b96a99be45f5a23f4277867ce_auth_membership.table appears
> > > > > > corrupted


[web2py] Problem with checkboxes widget

2010-09-05 Thread Fran
I'm running latest stable release (Bzr r2247) & trying to use this for
a multiselect field:
widget = SQLFORM.widgets.checkboxes.widget

But it's not working properly.
The create form works fine - the widget appears to work fine & the
database is indeed populated properly with the expected:
'|8|9|7|'
This displays fine in read screens.
However it fails to work in update forms - the checkboxes don't show
up as checked & so if the record is saved then the previous checkbox
states are lost :/

I tracked this down to:
http://bazaar.launchpad.net/~mdipierro/web2py/devel/annotate/head:/gluon/sqlhtml.py#L268
(value = '|8|9|7|')
values = not isinstance(value,(list,tuple)) and [value] or value
(values = ['|8|9|7|'])
k in values
(False)

The old, commented, code works fine though:
values = re.compile('[\w\-:]+').findall(str(value))
(values = ['8', '9', '7'])
k in values
(True)

I think the change was made to avoid a relatively slow call to 're'
right?
However it seems not to work properly...

Many thanks :)
Fran.


Re: [web2py] Re: Thank You Massimo and all others

2010-09-05 Thread bally boy
Yes it is definitely real productive. By the way just went through your
blog.. what baffles me is how can this be one of the downsides:-

-->online book now available here 

Or is it just a typo :-)

Have Fun!

On Sun, Sep 5, 2010 at 6:15 PM, Richard  wrote:

> "there was Massimo standing alone holding the flag"
> haha, glad you tried it out anyway.
>
> I was also surprised how productive web2py is and yet how much
> criticism it gets.
>
>
> http://blog.sitescraper.net/2010/06/web2py-flexible-python-web-framework.html
>
>
> On Sep 4, 5:22 am, bally boy  wrote:
> > Hi guys.. I have been working across plenty of frameworks, from
> > django, to pylons to turbogears and more recently to flask. And yes
> > each one of them is beautiful and has that feel of awesomeness in
> > their own way. All these days while comparing frameworks I used to
> > come across web2py but then there were enough comments by many others
> > which sort of stopped me from using it , and there was Massimo
> > standing alone holding the flag , countering every other comment ,
> > accepting what he should and rejecting what was wrong.
> >
> > And possibly his posts and his comments were the only reason that
> > around few days back , I decided to start using it. And wow , what an
> > awesome framework, a full stack one , which just does not make web
> > development easier , but am sure it teaches a lot of those youngsters
> > out there what web development is.
> >
> > I guess I got in at the right time, particularly when the third
> > edition of the book is just put up there.The documentation is
> > excellent. A big thanks to all those who are involved in the
> > development web2py.
>


[web2py] Re: Logic outside function problem.

2010-09-05 Thread weheh
Ah, I see. You want it inline, outside the functions. First of all,
the 2 lines session.id and session.name at the very top will probably
cause trouble all by themselves. Why don't you delete them?

I suppose the rest of the code should work, but perhaps you should put
the rest of the code inside a function and use routes to remap URL?
Anyway, I'm still curious what results you got?


[web2py] Re: Logic outside function problem.

2010-09-05 Thread weheh
What does it do?

On Sep 5, 12:42 pm, annet  wrote:
> In a controller outside all functions I have this code:
>
> session.id
> session.name
>
> if not request.args:
>     redirect(URL(r=request,c='default',f='error'))
> else:
>     if not session.id or session.id!=request.args[0]:
>         session.id=request.args[0]
>         row=db(db.user.id==session.id).select(db.user.name)
>         if row:
>             session.name=row[0].name
>
> The idea is multiple users sharing one app . The menu items in the app
> all have args[0] set to session.id, when session.id hasn't been set or
> args[0] for some reason changes (bookmarked page), the code should set
> the id and name in session to the current user's id and name, who's id
> is in request.args[0].
>
> I thought the code above would exactly do this, but it doesn't, why
> not?
>
> Kind regards,
>
> Annet.


[web2py] Logic outside function problem.

2010-09-05 Thread annet
In a controller outside all functions I have this code:

session.id
session.name

if not request.args:
redirect(URL(r=request,c='default',f='error'))
else:
if not session.id or session.id!=request.args[0]:
session.id=request.args[0]
row=db(db.user.id==session.id).select(db.user.name)
if row:
session.name=row[0].name

The idea is multiple users sharing one app . The menu items in the app
all have args[0] set to session.id, when session.id hasn't been set or
args[0] for some reason changes (bookmarked page), the code should set
the id and name in session to the current user's id and name, who's id
is in request.args[0].

I thought the code above would exactly do this, but it doesn't, why
not?


Kind regards,

Annet.


[web2py] Re: Scaffolding app with Twitter OAuth1.0a auth

2010-09-05 Thread Yannick
Hello Thanks for the note.
I was using the Simple Authentication on my application to send
tweets. I just noticed that twitter no longer support it.  I guess I
have to switch to Twitter oAuth API.
I was wondering because it looks like to send tweet, each user of my
application should get a CLIENT_ID, CLIENT_SECRET  (oauth_token and
oauth_token_secret). I wonder where they will get it from ? Should
each of them have to register my application in their twitter Account
to get it ?

Thanks for your help,
Yannick P.


On Aug 30, 4:00 am, Michele Comitini 
wrote:
> Actually if you look on developer.twitter.com, you will find some
> library that maps thetwitterREST api to
> python methods.  But I did not relay on that as it would have added
> more dependencies.
> I think that is something that you can use depending the application
> you are going to develop.
>
> Things are simple even without external libraries, look for instance
> at the get_user method in db.py, how it gets user 
> info:http://code.google.com/r/michelecomitini-facebookaccess/source/browse...
>
>     def get_user(self):
>         if self.accessToken() is not None:
>             client =oauth.Client(self.consumer, self.accessToken())
>             resp, content =
> client.request('http://api.twitter.com/1/account/verify_credentials.json')
>             if resp['status'] != '200':
>                 # cannot get user info. should check status
>                 return None
>             u = json.loads(content)
>             return dict(username=u['screen_name'], name=u['name'],
> registration_id=u['id'])
>
> so you build a client, make a request to a REST api url
> (http://api.twitter.com/1/account/verify_credentials.json)
>
> To post a tweet see:http://dev.twitter.com/doc/post/statuses/update
>
> in your controller you should write something like this:
>
> import oauth2 asoauth
> .
> .
> .
> @auth.requires_login()
> def sendtweet():
>   token = auth.settings.login_form.accessToken() # you can use this
> also if you prefer: token=session.access_token
>   consumer =oauth.Consumer(CLIENT_ID, CLIENT_SECRET) #<- CLIENT_ID,
> CLIENT_SECRET are defined in db.py
>   client =oauth.Client(self.consumer, token)
>   # encode the message
>   message = 'My web2py post!"
>   data=urlencode(status=message)
>   #make a post
>   resp, content =
> client.request('http://api.twitter.com/1/statuses/update.json',
> "POST", body=data)
>   if resp['status'] != '200':
>     #manage the error
>     return dict(message="Could not send tweet! :-( ")
>
>   return dict(message="Succesfully sent! :-)")
>
> if you call method returning some data I suggest tu use the .json
> version of it and use
> simplejson to decode it to a python dictionary (see the get_user() method 
> above)
>
> hope that helps...
> mic
>
> 2010/8/30 Albert Abril :
>
> > Just a question: what do you use for post a tweet, read statuses... ?
> > Thanks in advance.
>
> > On Sun, Aug 29, 2010 at 12:39 PM, Albert Abril 
> > wrote:
>
> >> :) Thank you!
>
> >> On Sun, Aug 29, 2010 at 1:45 AM, Michele Comitini
> >>  wrote:
>
> >>> Hello all,
>
> >>> I've uploaded a scaffolding app as example of authentication with
> >>>twitteroauth.  You can find source code here:
>
> >>>https://code.google.com/r/michelecomitini-facebookaccess/source/brows...
>
> >>> Or you can clone the repository locally:
> >>>https://code.google.com/r/michelecomitini-facebookaccess/source/checkout
>
> >>> as usual it is also on GAE for testing:
> >>>http://grafbook.appspot.com/helloTwitter
>
> >>> Please enjoy and send feedback.
>
> >>> tnx
> >>> michele


[web2py] Re: Can't send tweet from my application

2010-09-05 Thread Yannick
Thanks for the note and the link. Yes you right that's the reason why.
Twitter is no longer supporting Basic Authentication.
We need to use OAuth. I just read this post:
http://groups.google.com/group/web2py/browse_thread/thread/56e916dc8784e20a/ea6392970ae4cceb?lnk=gst&q=oAuth+twitter#ea6392970ae4cceb

And it looks like to send tweet, each user of my application should
get a CLIENT_ID, CLIENT_SECRET . I wonder where they will get it
from ? Should they have to register my application in thier twitter
Account to get it ?


Thanks,
Yannick P.

On Sep 4, 11:04 pm, mdmcginn  wrote:
> I don't know if this is the solution, but Twitter is now requiring
> OAuth instead of the previous Basic Auth. They've warned that many
> apps would stop working. Seehttp://dev.twitter.com/pages/basic_to_oauth
> --
> Michael McGinnis
>
> On Sep 4, 5:39 pm, Yannick  wrote:
>
> > Hello Mate,
> > I used to send tweet through my application successfully without any
> > trouble but today I keep getting an "401: Unauthorized" when I send a
> > tweet from my application... Here is the code :
> > def postTweets():
> >    try:
> >         import urllib, urllib2, base64
> >         import gluon.contrib.simplejson as sj
> >         args= urllib.urlencode([('status',"My Message")])
> >         headers={}
> >         headers['Authorization'] = 'Basic
> > '+base64.b64encode("userName"+':' +"password")
> >         request = urllib2.Request('http://twitter.com/statuses/
> > update.json', args, headers)
> >         return sj.loads(urllib2.urlopen(request).read())
> >     except Exception:
> >         print 'Problem here'
> >         raise
>
> > Here is the error I'm getting:
> > .
> > 
> > File "/System/Library/Frameworks/Python.framework/Versions/2.5/lib/
> > python2.5/urllib2.py", line 506, in http_error_default
> >     raise HTTPError(req.get_full_url(), code, msg, hdrs, fp)
> > urllib2.HTTPError: HTTP Error 401: Unauthorized
>
> > Please any help... thanks


[web2py] Re: icon in menu[close]

2010-09-05 Thread Frank
if I change
to(TAG[''](IMG(_src=URL(request.application,'static','home.png')),'title')),
it's ok.

Frank



[web2py] auth.settings.login.next is not taking affect

2010-09-05 Thread david.waldrop
I have an application that uses the built in auth components.  Users
can come to the site wither by hitting the root url, or via a link
that has been emailed which contains a specific community.  What I
want to happen is the following:

1) if a user enters www.myapp.com they get the default splash screen
2) if a user clicks a link form an invitation email
   the user is sent to the login page
   the user is sent to a function to validate the specific
community password
   if successful the user is taken to the specific community

I have the function that validates the community password and
redirects to the specific community
the issue is that when I set auth.settings.login.next = myfunction it
is not respected

I have played with putting this in my model file, but got an error
message form teh server saying too many redirects.  Ithink this is
because the model is called so frequently.  I now have the following
in my default/index controller:

def index():
# if user clicked email link, redirect to longin and set url to
get and check meeting password
meetingparm = request.env.http_host.split('.')[1]
if len(meetingparm):
meeting = db(db.meeting.link==meetingparm).select()
if len(meeting): # user clicked a link with a valid
meeting, lets get'em logged in and figure out who they are
meeting = meeting[0]
auth.settings.login_next =
URL(r=request,c='meetings',f='getmeetingpassword',args=meeting.id)
redirect(URL(r=request,f='user',args='login'))
return dict(message=T(''))

What happens when I click on the link is the login screen is displayed
and after I enter credentials I am taking to the specific community,
instead of the function that checks of community password.

Do I have this is in the right place? if so, why isn't the
'getmeetingpassword' redirect taking affect?



[web2py] Re: icon in menu

2010-09-05 Thread Frank
thanks for your feedback,it's 6 to 6, it is nothing wrong with ]. please refer
to my reply to annet, it should be web2py related.

thanks again,
Frank 





[web2py] Re: Thank You Massimo and all others

2010-09-05 Thread Richard
"there was Massimo standing alone holding the flag"
haha, glad you tried it out anyway.

I was also surprised how productive web2py is and yet how much
criticism it gets.

http://blog.sitescraper.net/2010/06/web2py-flexible-python-web-framework.html


On Sep 4, 5:22 am, bally boy  wrote:
> Hi guys.. I have been working across plenty of frameworks, from
> django, to pylons to turbogears and more recently to flask. And yes
> each one of them is beautiful and has that feel of awesomeness in
> their own way. All these days while comparing frameworks I used to
> come across web2py but then there were enough comments by many others
> which sort of stopped me from using it , and there was Massimo
> standing alone holding the flag , countering every other comment ,
> accepting what he should and rejecting what was wrong.
>
> And possibly his posts and his comments were the only reason that
> around few days back , I decided to start using it. And wow , what an
> awesome framework, a full stack one , which just does not make web
> development easier , but am sure it teaches a lot of those youngsters
> out there what web development is.
>
> I guess I got in at the right time, particularly when the third
> edition of the book is just put up there.The documentation is
> excellent. A big thanks to all those who are involved in the
> development web2py.


[web2py] Re: How to include the record_id of the in crud.message

2010-09-05 Thread weheh
This is from a Massimo answer in another thread:

form=crud.create(db.table,onaccept=lambda form:
do_something_with(form.vars.id))

On Sep 5, 6:52 am, Johann Spies  wrote:
> I want the id of the just record inserted with crud.create to be shown
> in the message but I don't know how to ask crud for the id.
>
> How can it be done?
>
> Regards
> Johann
>
> --
>     "Be not deceived; God is not mocked: for whatsoever a
>      man soweth, that shall he also reap."
>                                   Galatians 6:7


Re: [web2py] Re: icon in menu

2010-09-05 Thread Mohamed Zenadi
In fact there is an extra ] if you count them ^_^

On Sun, Sep 5, 2010 at 2:03 PM, Frank  wrote:

> thanks for your feedback, you are absolutely right because web2pyis python
> based. please refer to my message replying to annet, it shoulb be web2py
> related. please advise what I have to deal with the problem, thanks you.
>
> Frank
>
>
>
>
>


[web2py] Re: icon in menu

2010-09-05 Thread Frank
thanks for your feedback, you are absolutely right because web2pyis python
based. please refer to my message replying to annet, it shoulb be web2py
related. please advise what I have to deal with the problem, thanks you.

Frank  






[web2py] Re: icon in menu

2010-09-05 Thread Frank
thanks for your feedback,

after remove the comma, still get same error,
Traceback (most recent call last):
  File "C:\web2py\gluon\restricted.py", line 184, in restricted
ccode = compile2(code,layer)
  File "C:\web2py\gluon\restricted.py", line 171, in compile2
return compile(code.rstrip().replace('\r\n','\n')+'\n', layer, 'exec')
  File "C:/web2py/applications/www/models/menu.py", line 63
]
^
SyntaxError: invalid syntax

this error happen after I change 'title' to
TAG[''](IMG(_src=URL(request.application,'static','home.png'),'title').

if I change back, it will be fine.

Frank
 





[web2py] How to include the record_id of the in crud.message

2010-09-05 Thread Johann Spies
I want the id of the just record inserted with crud.create to be shown
in the message but I don't know how to ask crud for the id.

How can it be done?

Regards
Johann

-- 
    "Be not deceived; God is not mocked: for whatsoever a
     man soweth, that shall he also reap."
                                  Galatians 6:7


[web2py] Re: icon in menu

2010-09-05 Thread Vidul Petrov
It's a Python homework, not web2py issue.

On Sep 4, 5:48 pm, Frank  wrote:
> hi,
>
> I have code,
>         response.menu_index = [
>
> [TAG[''](IMG(_src=URL(request.application,'static','home.png'),'title'), 
> False,
> URL(request.application,'default','facepda'),
>              [
>                 [T('login'), False,
> URL(request.application,'default','user/login')],
>                 [T('retrieve password'), False,
> URL(request.application,'default','user/retrieve_password')]]
>             ],
>            ]
>
> and get this error,
>
> Traceback (most recent call last):
>   File "C:\web2py\gluon\restricted.py", line 184, in restricted
>     ccode = compile2(code,layer)
>   File "C:\web2py\gluon\restricted.py", line 171, in compile2
>     return compile(code.rstrip().replace('\r\n','\n')+'\n', layer, 'exec')
>   File "C:/web2py/applications/www/models/menu.py", line 59
>     ],
>     ^
> SyntaxError: invalid syntax
>
> it will be great if somebody advise me to figure out the problem.
>
> thanks,
>
> Frank