[web2py] callback on an anchor tag

2012-07-24 Thread Toby Shepard

Working through the html helper docs,
I decided to try the callback parameter
to the anchor tag:


{{=A("CLICK ME!!", callback=URL('http://mysite.com/foo.html'), 
target='hater')}}

{{=DIV(_id = 'hater')}}

foo.html delivers a bit of content.  This did not work.
Viewing the source, I see that the tag was rendered like this:

onclick="ajax('/css/edit/http://register.rcsreg.com/foo.html',[],'hater';);return 
false;">CLICK ME!!


That doesn't so good.  Am I doing something wrong?

Thanks,

Tobiah

--





Re: [web2py] Re: Suggestion - a pickled DAL field

2012-07-25 Thread Toby Shepard

On 07/24/2012 06:55 PM, Anthony wrote:

On Tuesday, July 24, 2012 5:58:29 PM UTC-4, Derek wrote:

Make it a computed field?


I'm not sure that would be helpful in this case. A computed field
computes its value automatically based on other fields in the record,
but in this case, he needs to pickle an object, which is not one of the
other fields. Also, it needs to be unpickled when queried, which a
computed field wouldn't handle.



I haven't used one, but I remember coming across it in the manual.
Don't you just pass a lambda when you create the field.  It would
seem that you could do anything you want to the value without consulting
other fields.

--





Re: [web2py] Re: callback on an anchor tag

2012-07-25 Thread Toby Shepard




{{=A("CLICK ME!!", callback=URL('http://mysite.com/foo.html'
<http://mysite.com/foo.html'>),
target='hater')}}

should be

{{=A("CLICK ME!!", callback='http://mysite.com/foo.html'
<http://mysite.com/foo.html'>,target='hater')}}


Ok, thanks.  Perhaps there is a small problem with the
manual section on views.  I copied my example from the manual:


{{=A('click me', callback=URL('myaction'), target="t")}}


and the response of the ajax callback will be stored in the DIV with id 
equal to "t".



Tobiah


which would produce:

http://mysite.com/foo.html',[],'hater';);return
false">CLICK ME!!

and that is what is expected. Perhaps I misunderstand the question.


On Tuesday, 24 July 2012 16:21:59 UTC-5, Toby Shepard wrote:

Working through the html helper docs,
I decided to try the callback parameter
to the anchor tag:


{{=A("CLICK ME!!", callback=URL('http://mysite.com/foo.html'
<http://mysite.com/foo.html'>),
target='hater')}}
{{=DIV(_id = 'hater')}}

foo.html delivers a bit of content. This did not work.
Viewing the source, I see that the tag was rendered like this:

http://register.rcsreg.com/foo.html'
<http://register.rcsreg.com/foo.html'>;,[],'hater');return

false;">CLICK ME!!

That doesn't so good. Am I doing something wrong?

Thanks,

Tobiah

--





--





Re: [web2py] Re: callback on an anchor tag

2012-07-25 Thread Toby Shepard

On 07/24/2012 06:48 PM, Massimo Di Pierro wrote:

{{=A("CLICK ME!!", callback=URL('http://mysite.com/foo.html'
),
target='hater')}}

should be

{{=A("CLICK ME!!", callback='http://mysite.com/foo.html'
,target='hater')}}


Ok, so now I have:

{{=A("CLICK ME!!", callback='http://mysite.com/foo.html', target='hater')}}
{{=DIV(_id = 'hater')}}

And, viewing the source, I'm getting this:

onclick="ajax('http://mysite.com/foo.html',[],'hater';);return 
false;">CLICK ME!!




Thanks,

Tobiah

--





Re: [web2py] Re: callback on an anchor tag

2012-07-25 Thread Toby Shepard

On 07/25/2012 09:21 AM, Anthony wrote:

Ok, thanks. Perhaps there is a small problem with the
manual section on views. I copied my example from the manual:


{{=A('click me', callback=URL('myaction'), target="t")}}


and the response of the ajax callback will be stored in the DIV with id
equal to "t".


No, there's no problem with the book. Notice, you didn't copy the
example exactly. The example generates the callback URL using the web2py
URL() function, which generates web2py URLs. In your code, you passed a
fully formed URL (possibly an external URL?) to the URL() function,
which is not how it works.

Anthony

--





Oh, I had thought that 'myaction' stood for a full URL.  So in this
case, is 'myaction' actually the name of a controller, or function?

Thanks,

Toby

--





[web2py] BR()

2012-07-25 Thread Toby Shepard

In my own html generating libraries, I normally allow
an integer argument to the  maker, which is a count
of how many tags to put out.  So:

{{=BR(5)}}

could output 

This works out since the BR tag can't have any components
anyway.

Just a thought.  I find it useful at times.

Tobiah

--





[web2py] Question about a section of the book.

2012-08-02 Thread Toby Shepard

In the forms section:

It is possible to have multiple forms per page, but you must allow web2py to 
distinguish them.
If these are derived by SQLFORM from different tables, then web2py gives them 
different names
automatically; otherwise you need to explicitly give them different form names. 
Here is an example:


def two_forms():
form1 = FORM(INPUT(_name='name', requires=IS_NOT_EMPTY()),
   INPUT(_type='submit'))
form2 = FORM(INPUT(_name='name', requires=IS_NOT_EMPTY()),
   INPUT(_type='submit'))
if form1.process(formname='form_one').accepted:
response.flash = 'form one accepted'
if form2.process(formname='form_two').accepted:
response.flash = 'form two accepted'
return dict(form1=form1, form2=form2)


Does it matter at all that both of the forms have the
same NAME attribute?  I would have thought that to be
poor HTML practice.

Thanks,

Toby

--





Re: [web2py] Re: Question about a section of the book.

2012-08-02 Thread Toby Shepard

On 08/02/2012 11:35 AM, Massimo Di Pierro wrote:

if you have two forms in one page, web2py needs to be able to
discriminate which one is being submitted. It does that by using a
input type=hidden name=formname.


But the forms below have the same name.  I don't
think I understand completely.


Massimo

On Thursday, 2 August 2012 13:13:10 UTC-5, Toby Shepard wrote:

In the forms section:

It is possible to have multiple forms per page, but you must allow
web2py to distinguish them. If these are derived by SQLFORM from
different tables, then web2py gives them different names
automatically; otherwise you need to explicitly give them different
form names. Here is an example:


def two_forms(): form1 = FORM(INPUT(_name='name',
requires=IS_NOT_EMPTY()), INPUT(_type='submit')) form2 =
FORM(INPUT(_name='name', requires=IS_NOT_EMPTY()),
INPUT(_type='submit')) if
form1.process(formname='form_one').accepted: response.flash = 'form
one accepted' if form2.process(formname='form_two').accepted:
response.flash = 'form two accepted' return dict(form1=form1,
form2=form2)


Does it matter at all that both of the forms have the same NAME
attribute? I would have thought that to be poor HTML practice.

Thanks,

Toby

--





--





[web2py] Subclass FORM?

2012-08-02 Thread Toby Shepard

I tried doing this:


def index():

doc = Document()

return doc

class Document(FORM):

def __init__(self):
super(Document, self).__init__(self)
self.append('A message')



But when I run it I get this huge ticket with
an error about recursion.  I wouldn't have thought
there would be any difference then just making
the FORM() and appending text to it, which works.

Thanks!

Tobiah


Traceback (most recent call last):
  File "/home/toby/web2py/gluon/main.py", line 498, in wsgibase
serve_controller(request, response, session)
  File "/home/toby/web2py/gluon/main.py", line 202, in serve_controller
page = run_controller_in(request.controller, request.function, environment)
  File "/home/toby/web2py/gluon/compileapp.py", line 581, in run_controller_in
vars = vars.xml()
  File "/home/toby/web2py/gluon/html.py", line 1896, in xml
return DIV.xml(newform)
  File "/home/toby/web2py/gluon/html.py", line 848, in xml
(fa, co) = self._xml()
  File "/home/toby/web2py/gluon/html.py", line 839, in _xml
self.components])
  File "/home/toby/web2py/gluon/html.py", line 114, in xmlescape
return data.xml()
  File "/home/toby/web2py/gluon/html.py", line 1896, in xml
return DIV.xml(newform)
  File "/home/toby/web2py/gluon/html.py", line 848, in xml
(fa, co) = self._xml()
  File "/home/toby/web2py/gluon/html.py", line 839, in _xml
self.components])
  File "/home/toby/web2py/gluon/html.py", line 114, in xmlescape
return data.xml()
  File "/home/toby/web2py/gluon/html.py", line 1896, in xml
return DIV.xml(newform)


.

  File "/home/toby/web2py/gluon/html.py", line 1892, in xml
newform = FORM(*self.components, **self.attributes)
  File "/home/toby/web2py/gluon/html.py", line 1797, in __init__
DIV.__init__(self, *components,  **attributes)
RuntimeError: maximum recursion depth exceeded in __instancecheck__

--





Re: [web2py] Re: Question about a section of the book.

2012-08-03 Thread Toby Shepard

On 08/02/2012 12:29 PM, Niphlod wrote:

formname='something' serializes within the form a hidden input, so
web2py can distinguish what form is being submitted. If the submitted
values were to be serialized as urlencoded, just to explain, for the
first form would be

name=value&formname=form_one

and for the second

name=value&formname=form_two


Ok, I'm starting to understand.  So looking at the manual
exceprt:

def two_forms():
form1 = FORM(INPUT(_name='name', requires=IS_NOT_EMPTY()),
   INPUT(_type='submit'))
form2 = FORM(INPUT(_name='name', requires=IS_NOT_EMPTY()),
   INPUT(_type='submit'))
if form1.process(formname='form_one').accepted:
response.flash = 'form one accepted'
if form2.process(formname='form_two').accepted:
response.flash = 'form two accepted'
return dict(form1=form1, form2=form2)

I would have to assume that the hiddens are only generated
because of the call to FORM.accepted().  Should I assume then
that the 'formname' keyword is only necessary when there is
more than one form in the page?

Thanks,

Toby

--





Re: [web2py] Re: Subclass FORM?

2012-08-03 Thread Toby Shepard

def __init__(self):
super(Document, self).__init__(self)


Don't pass self to __init__() -- should be:



Ahh... much better.  Thanks!

Tobiah

--





[web2py] Get result set back as list?

2012-08-10 Thread Toby Shepard


I'm in a situation where I just want a single column back from
a table.  I'd like it as a list so I could just pass it on
to the next function.

All I can think of is something like:

temp = []

for thing in db(db.mytable).select(db.mytable.myfield):
temp.append(thing)

return temp

I was hoping for something like:

return db(db.mytable).select(db.mytable.myfield).as_list()

Or something like that.

As an aside, I have a python dbi that has four central ways to get
data back.  I call them:

atom()  scalar as in'select first from person where id = 1'
row()   dict as in  'select * from person' where id = 1'
column()list as in  'select first from person'
world() list of dict:   'select * from person'

They end up being uite convenient and result in concise syntax.

Thanks,

Tobiah

--





Re: [web2py] Re: Get result set back as list?

2012-08-11 Thread Toby Shepard


On 8/10/2012 3:58 PM, Vasile Ermicioi wrote:

for me that works

alist = db(db.auth_user).select().as_list()


How funny.  I was just making up the name as_list().
Great minds think alike I guess.  I was looking for a flat
list of field values, but the list comprehension solution
is ok I guess.

Thanks,

Tobiah

--





[web2py] generic.html controller wide?

2012-08-20 Thread Toby Shepard

I was thinking that it would be nice if I could
make a director in the views folder matching a
controller name, but then just put a file in there
called 'generic.html' that would apply to any function
called in that controller.

Perhaps there is another way to do this.

Thanks,

Tobiah

--