Chris,

I hope you don't mind me bothering you again, but your posts made me
reconsider other parts of my applications as well.

I now have a module widgets.py:

from gluon.sqlhtml import *

def timeplain(field,value):
    if value == None:
        value = ''
    elif 'strftime' in dir(value):
        value = value.strftime('%H:%M')
    id = '%s_%s' % (field._tablename, field.name)
    return INPUT
(_type='text',_id=id,_class='time_plain',_name=field.name,value=str
(value),requires=field.requires)

.. and a model which contains the following lines of code:

from applications.demo.modules.widgets import*

widget=timeplain


On Mac OS X Leopard Server I did not have to restart the server, it
worked right away.


>From this I learn that I could also import the widgets from one
application into the other. Which means I could create the widgets.py
file in a parent application's module folder and move the widgets from
its child applications into that widgets.py file. Right?

In two of my applications I created a handlers.py controller
containing functions that handle auto_completion. In a function in a
controller I have:

form=form_factory(SQLField('place',requires=IS_NOT_EMPTY
(),widget=lambda self, value:INPUT
(_type='text',_id='clubbyplace',_class='ac_input',_name='place',requires=self.requires)))

... in web2py_ajax.html:

$('#clubbyplace').autocomplete('/core/handlers/clubbyplaceAC',
{maxItemsToShow:12});

... and in handlers.py

def clubbyplaceAC():
    q=''
    if request.vars:
        q=request.vars.q
    if not q:
        return q
    rows=db((db.adres.bedrijf==db.bedrijfinschrijving.bedrijf)&
(db.bedrijfinschrijving.inschrijving==2)&\
    (db.adres.plaats.like('%s%%'%q.capitalize())))\
    .select(db.adres.plaats,orderby=db.adres.plaats,distinct=True)
    r=''
    for row in rows:
        r='%s%s\n'%(r,row.plaats)
    return r


Based on what I've learned today, I assume I could create a
handlers.py file in the parent application's modules folder:

from gluon.sqlhtml import *

def clubbyplaceAC():
    q=''
    if request.vars:
        q=request.vars.q
    if not q:
        return q
    rows=db((db.adres.bedrijf==db.bedrijfinschrijving.bedrijf)&
(db.bedrijfinschrijving.inschrijving==2)&\
    (db.adres.plaats.like('%s%%'%q.capitalize())))\
    .select(db.adres.plaats,orderby=db.adres.plaats,distinct=True)
    r=''
    for row in rows:
        r='%s%s\n'%(r,row.plaats)
    return r


... change the line of code in web2py_ajax.html to read like:

$('#clubbyplace').autocomplete('applications/parent/handlers/
clubbyplaceAC',{maxItemsToShow:12});


... somehow rewrite the widget: widget=lambda self, value:INPUT
(_type='text',_id='clubbyplace',_class='ac_input',_name='place',requires=self.requires))
.. to read like:

def clubbyplace(field,value):
    if value == None:
        value = ''
    id = field
    return INPUT
(_type='text',_id=id,_class='ac_input',_name=????,value=str
(value),requires=self.requires)

... and put it the widgets.py


... in the model of my application:

from applications.parent.modules.widgets import*

... and in the function:

form=form_factory(SQLField('place',requires=IS_NOT_EMPTY
(),widget=clubbyplace(clubbyplace,???)))


I gave it a try, but I don't get the widget right. I hope you will
help me to get this to work.


Kind regards,

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