Found a solution to this problem. It appears that "contactSearch" needs
two parameters and should be defined as follows (older examples had it
wrong):
def contactSearch(self, url):
...
return form
Topic is considered to be closed by me.
On Friday, April 11, 2014 1:49:12 PM UTC-4, Seth J wrote:
>
> Hello again,
>
> I apologize for potentially naive question as I am new to web2py. I am
> trying to implement a custom search_widget on SQLFORM.smartgrid and ran
> into an error.
>
> My table is defined in db.py as such:
>
> ## We prepend f_ to fieldnames for disambiguity
> db._common_fields.append(auth.signature) ## adds signature fields to all
> tables
>
> db.define_table('work_log',
> Field('f_jacket_no', type='string',
> label=T('Jacket Number')),
> Field('f_job_title_format_no', type='string',
> label=T('Job Title & Format Number')),
> Field('f_assoc_no', type='string',
> label=T('Associated Information')),
> Field('f_status_destination', type='string',
> label=T('Status & Destination')),
> Field('f_probe', type='boolean',
> label=T('Peps')),
> Field('created_on', type='date', default=request.now,
> label=T('Date Out')),
> format='%(f_job_title_format_no)s',
> migrate=settings.migrate)
>
> db.work_log._plural = T('Work Log')
> db.work_log._singular = T('Work Entry')
> db.work_log.f_jacket_no.requires = IS_MATCH('\d{3}-\d{3}', strict=True,
> error_message='Please use 000-000 format for Jacket No. (including leading
> 0)')
> db.work_log.f_job_title_format_no.requires = requires=IS_IN_SET(['Public
> Law: 6580', 'W&M Hearing: 5011', 'VA Hearing: 5011', 'State Disburse:
> 9334', 'Leg Calendar: 7800', 'Leg Branch Appro: 3700', 'Final Calendar:
> 7800', '112th Congress: 7800', 'CFR: 8091 (Indicate title & vol. num. at
> Assoc. Info.)', 'Other (Indicate at Assoc. Info.)'])
> db.work_log.f_status_destination.requires = requires=IS_IN_SET(['1st Try:
> PR', 'OK to Print: TE', 'CX\'s: PR', 'AA\'s: PR', 'Converted: TP'])
> db.work_log.created_on.represent = lambda value, x:
> value.strftime('%m/%d/%Y')
> db.work_log.created_on.writable = False
>
> ## after defining tables, uncomment below to enable auditing
> auth.enable_record_versioning(db)
>
> In a default.py controller I have among other standard things these two
> functions of interest I followed example from this topic (
> https://groups.google.com/forum/#!topic/web2py/tku5zkVZfZc) :
>
> def contactSearch(self):
> # Build a simple form
> userId = auth.user_id
>
> form = FORM('',
> LABEL('Name:', _for='asset_name'),
> INPUT(_name='asset_name',_value=userId, _id='web2py_asset_name'),
> INPUT(_type='submit',_value=T('Search')),
> INPUT(_type='submit',_value=T('Clear'),
> _onclick="jQuery('#asset_name').val('');"), _method="GET",_action='self',
> _id='contactSearch')
> return form
>
>
> @auth.requires_login()
> def work_log_manage():
> is_owner = (lambda row: row.created_by == auth.user_id) if auth.user
> else False
> db.work_log.id.readable=False # Since we do not want to expose the id
> field on the grid
> db.work_log.created_by.readable=True # Show owner of record
> db.work_log_archive.id.readable=False # Since we do not want to expose
> the id field on the grid
> links = [lambda row: A('View
> Post',_href=URL("default","work_log_archive.current_record",args=[row.id
> ]))]
> orderby = ['created_on']
>
> searchForms = dict(work_log=contactSearch, work_log_archive=None)
>
> grid = SQLFORM.smartgrid(db.work_log, linked_tables =
> ['work_log_archive'], editable= dict(work_log=is_owner,
> work_log_archive=False), deletable= dict(work_log=is_owner,
> work_log_archive=False), user_signature=True, details=False,
> search_widget=searchForms, showbuttontext=True, links_in_grid=False,
> links=links, paginate=30,
> maxtextlengths={'work_log.f_job_title_format_no':60}, orderby=orderby)
> return dict(grid=grid)
>
> I know contactSearch doesn't do much. At the moment I am simply trying to
> display a widget. I get the following error when accessing a page:
>
> Version
>> web2py™ Version 2.9.5-stable+timestamp.2014.03.16.02.35.39
>> Python Python 2.7.3: /usr/bin/python (prefix: /usr)
>> Traceback
>>
>> Traceback (most recent call last):
>> File "/home/www-data/web2py/gluon/restricted.py", line 220, in restricted
>> exec ccode in environment
>> File "/home/www-data/web2py/applications/worklog/controllers/default.py",
>> line 104, in <module>
>> File "/home/www-data/web2py/gluon/globals.py", line 385, in <lambda>
>> self._caller = lambda f: f()
>> File "/home/www-data/web2py/gluon/tools.py", line 3287, in f
>> return action(*a, **b)
>> File "/home/www-data/web2py/applications/worklog/controllers/default.py",
>> line 101, in work_log_manage
>> grid = SQLFORM.smartgrid(db.work_log, linked_tables =
>> ['work_log_archive'], editable= dict(work_log=is_owner,
>> work_log_archive=False), deletable= dict(work_log=is_owner,
>> work_log_archive=False), user_signature=True, details=False,
>> search_widget=searchForms, showbuttontext=True, links_in_grid=False,
>> links=links, paginate=30,
>> maxtextlengths={'work_log.f_job_title_format_no':60}, orderby=orderby)
>> File "/home/www-data/web2py/gluon/sqlhtml.py", line 2800, in smartgrid
>> user_signature=user_signature, **kwargs)
>> File "/home/www-data/web2py/gluon/sqlhtml.py", line 2267, in grid
>> form = search_widget and search_widget(sfields, url()) or ''
>> TypeError: contactSearch() takes exactly 1 argument (2 given)
>>
>> Error snapshot help
>>
>> <type 'exceptions.TypeError'>(contactSearch() takes exactly 1 argument (2
>> given))
>
>
> So I must be missing something very obvious, at least I hope so. Can
> anybody help me here, please????
>
--
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
---
You received this message because you are subscribed to the Google Groups
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.