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(" "*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(lambda row: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=""><Aucun></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=""><Aucun></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 [email protected].
For more options, visit https://groups.google.com/groups/opt_out.