Finally, I managed to make it work
The solution was to* pass the validator of the table field to the SELECT 
helper of the widget* : 

In HierarchicalSelect class, I replaced
opt=[OPTION(name, _value=key) for key,name in self.options]
        sel = SELECT(opt,_id="%s_%s" % (self.tablename, self.fieldname),
                        _class=self.type, 
                        _name=self.fieldname,
                        value=value)
with

opt=[OPTION(name, _value=key) for key,name in self.options]
        sel = SELECT(opt,_id="%s_%s" % (self.tablename, self.fieldname),
                        _class=self.type, 
                        _name=self.fieldname,
                        value=value,
                        requires=self.tablename.parent.requires)

And it works

Le mardi 10 décembre 2013 12:36:03 UTC+1, Loïc a écrit :
>
> I'm still trying to understand this issue, as it is related to my custom 
> widget (does not occurs when I use the default "reference" list widget)
>
> I try to set some breakpoints for example in "accepts" method of "FORM" 
> class but I can't make it work.
> If I add "dbg.set_trace()",the program breaks several lines later, in my 
> application code, but never in gluon code
> If I add a breakpoint using pycharm, the program never breaks
>
> Is it because of the use of "exec in" statement at the heart of gluon?
> How can I check input / output values of gluon's methods call without 
> adding "print" statements everywhere?
>
> Thanks a lot
>
>
> Le jeudi 5 décembre 2013 23:05:32 UTC+1, Massimo Di Pierro a écrit :
>>
>> I understand and I do not understand why the problem arises there but 
>> your error is:
>>
>> <class 'sqlite3.IntegrityError'> foreign key constraint failed
>>
>> So I would exclude it is a problem with the foreign key contraints.
>>
>> On Thursday, 5 December 2013 09:46:59 UTC-6, Loïc wrote:
>>>
>>> I know Massimo, but my problem seems to be located in the Widget 
>>> management
>>> And that's why I started my message with "
>>> *I have the same problem as the one explained here : 
>>> https://groups.google.com/forum/?fromgroups#!topic/web2py/klspqXpha4E 
>>> <https://groups.google.com/forum/?fromgroups#%21topic/web2py/klspqXpha4E>But
>>>  
>>> as I have more specific informations, I start a new thread...*"
>>>
>>> Do you have any hints about that?
>>> Thank you
>>>
>>> Le jeudi 5 décembre 2013 16:27:55 UTC+1, Massimo Di Pierro a écrit :
>>>>
>>>> The problem is discussed here: 
>>>> https://groups.google.com/forum/#!topic/web2py/klspqXpha4E
>>>>
>>>> On Thursday, 5 December 2013 05:04:17 UTC-6, Loïc wrote:
>>>>>
>>>>> Hello all-
>>>>>
>>>>> I have the same problem as the one explained here 
>>>>> :https://groups.google.com/forum/?fromgroups#!topic/web2py/klspqXpha4E
>>>>> But as I have more specific informations, I start a new thread...
>>>>>
>>>>> *My Model (simplified) : *
>>>>> db.define_table('page',
>>>>>     Field('parent', 'reference page', label=T('Parent')),
>>>>>     Field('title', unique=True, notnull=True, label=T('Title')))
>>>>>
>>>>> db.page.parent.requires = IS_EMPTY_OR(IS_IN_DB(db, db.page.id, 
>>>>> '%(title)s', zero=T('<Empty>')))
>>>>> pageSelector = HierarchicalSelect(db, db.page, db.page.title, db.page.
>>>>> rank)
>>>>> db.page.parent.widget = pageSelector.widget
>>>>>
>>>>> The goal of the HierarchicalSelect widget is to have a "tree-view" of 
>>>>> all my pages. More elegant than the default selector
>>>>>
>>>>> *My Controller (simplified)*
>>>>> def edit_page():
>>>>>     page = db.page(request.args(0))
>>>>>     crud.settings.update_deletable = False
>>>>>     form = crud.update(db.page,page,next=URL('show_page', args=page.id
>>>>> ))
>>>>> return dict(form=form)
>>>>>
>>>>> From 2.8.2 update, when I update a page, I get an error : 
>>>>> <class 'sqlite3.IntegrityError'> foreign key constraint failed
>>>>>
>>>>> This error *occurs only when I update a page and select "<Empty>" 
>>>>> value for the "parent" field.*
>>>>> When I *remove the two following lines of my model definition, 
>>>>> everything works fine*
>>>>> pageSelector = HierarchicalSelect(db, db.page, db.page.title, db.page.
>>>>> rank)
>>>>> db.page.parent.widget = pageSelector.widget
>>>>>
>>>>>
>>>>> So the error seems to be in my HierarchicalSelect class.
>>>>> *Here is the code : *
>>>>> class HierarchicalSelect(object):
>>>>>     def __init__(self, db, table_name, title_field, order_field):
>>>>>         self.options=[]
>>>>>         self.db = db
>>>>>         self.tablename = table_name
>>>>>         self.fieldname = None
>>>>>         self.title = title_field
>>>>>         self.order = order_field
>>>>>         self.type = None
>>>>>         self.rows=None
>>>>>         self.hierarchyseparator = XML("&nbsp;"*4)
>>>>>
>>>>>     def _childs_list(self, field, depth):
>>>>>         path = self.hierarchyseparator*depth
>>>>>        
>>>>>         path += self.hierarchyseparator
>>>>>         self.options.append((field['id'], path+field[self.title]))
>>>>>         [self._childs_list(child, (depth+1)) for child in self.rows.
>>>>> find(lambda row: row.parent == field.id)]   
>>>>>
>>>>>     def widget(self, field, value):
>>>>>         self.fieldname = field.name
>>>>>         self.type = field.type
>>>>>         self.rows = self.db(self.tablename).select(orderby=self.order)
>>>>>         self.options.append(("", T('<Empty>'))) #add root node
>>>>>
>>>>>         [self._childs_list(field,0) for field in self.rows.find(lambdarow
>>>>> : row.parent < 1)] 
>>>>>         opt=[OPTION(name, _value=key) for key,name in self.options]
>>>>>         sel = SELECT(opt,_id="%s_%s" % (self.tablename, self.fieldname
>>>>> ),
>>>>>                         _class="generic-widget", 
>>>>>                         _name=self.fieldname,
>>>>>                         value=value)
>>>>>         return sel
>>>>>
>>>>> *HTML generated with the default SELECT helper for the first option (the 
>>>>> option that causes error)*
>>>>>
>>>>> <select class="generic-widget" id="page_parent" name="parent"><option 
>>>>> value="">&lt;Aucun&gt;</option>
>>>>>
>>>>>
>>>>> *HTML generated with my Widget* *for the first option (the option that 
>>>>> causes error)*
>>>>> <select class="generic-widget" id="page_parent" name="parent"><option 
>>>>> value="">&lt;Aucun&gt;</option>
>>>>>
>>>>>
>>>>> The HTML seems to be the same, so I don't understand what's wrong with my 
>>>>> widget...
>>>>>
>>>>>
>>>>> Can anybody help me with that?
>>>>> Thank you
>>>>>
>>>>

-- 
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 web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to