Hi,
you really have to work on packaging examples app if you want someone to
> try to reproduce and identify the bugs... We can't possibly figure out all
> the intricacies of your models and your underlying data structure from a
> few lines.
>
I created a mock app in web2py 2.2.1 which reproduces the problem, however,
google throws a #304 error when I try to upload it. Here's the code, maybe
you're able to reproduce the problem yourself"
in db.py
attributes =
dict(type='datetime',default=request.now,requires=IS_DATETIME(format='%Y-%m-%d
%H:%M:%S'),writable=False,readable=False,represent = lambda v, row:
v.strftime('%d/%m/%Y %H:%M:%S') if v else '')
isnode =
dict(default='',requires=[IS_IN_DB(db,'node.id','%(id)s',zero=T('Select a
value'))],ondelete='CASCADE',notnull=True,writable=False,readable=False)
isemptyorisdate =
dict(type='date',requires=IS_EMPTY_OR(IS_DATE(format='%Y-%m-%d')),represent
= lambda v: v.strftime('%d/%m/%Y') if v else '')
db.define_table('node',
Field('createdOn',**attributes),
Field('modifiedOn',update=request.now,**attributes),
migrate=False)
db.define_table('organization',
Field('nodeID','reference
node',default='',requires=[IS_IN_DB(db,'node.id','%(id)s',zero=T('Select a
value')),IS_NOT_IN_DB(db,'organization.nodeID',error_message=T('organization
already in
database'))],ondelete='CASCADE',notnull=True,unique=True,writable=False,readable=False),
Field('name',length=128,default='',requires=[IS_LENGTH(128,error_message=T('length
exceeds 128 characters')),IS_NOT_EMPTY()],notnull=True,label='Naam * '),
Field('createdOn',**attributes),
Field('modifiedOn',update=request.now,**attributes),
format='%(name)s %(nodeID)s',
migrate=False)
db.define_table('person',
Field('nodeID','reference
node',default='',requires=[IS_IN_DB(db,'node.id','%(id)s',zero=T('Select a
value')),IS_NOT_IN_DB(db,'person.nodeID',error_message=T('person already in
database'))],ondelete='CASCADE',notnull=True,unique=True,writable=False,readable=False),
Field('firstName',length=32,requires=IS_LENGTH(32,error_message=T('length
exceeds 32 characters'))),
Field('familyNamePreposition',length=16,requires=IS_LENGTH(16,error_message=T('length
exceeds 16 characters'))),
Field('lastName',length=64,default='',requires=[IS_LENGTH(64,error_message=T('length
exceeds 64 charactrer')),IS_NOT_EMPTY()],notnull=True),
Field('birthday',**isemptyorisdate),
Field('createdOn',**attributes),
Field('modifiedOn',update=request.now,**attributes),
format='%(firstName)s %(lastName)s',
migrate=False)
db.define_table('hub',
Field('nodeID','reference
node',default='',requires=[IS_IN_DB(db,'node.id','%(id)s',zero=T('Select a
value')),IS_NOT_IN_DB(db,'hub.nodeID',error_message=T('hub already in
database'))],ondelete='CASCADE',notnull=True,unique=True,writable=False,readable=False),
Field('ownerID','reference
node',default='',requires=[IS_IN_DB(db,'node.id','%(id)s',zero=T('Select a
value'))],ondelete='RESTRICT',notnull=True),
Field('name',length=128,default='',requires=[IS_LENGTH(128,error_message=T('length
exceeds 128 characters')),IS_NOT_EMPTY()],notnull=True),
Field('createdOn',**attributes),
Field('modifiedOn',update=request.now,**attributes),
migrate=False)
def set_requirement(tie):
tie.nodeID.requires=[IS_IN_DB(db,'node.id','%(id)s',zero=T('select a
value')),IS_NOT_IN_DB(db(db.tie.hubID==request.vars.hubID),'tie.nodeID',error_message=T('combination
hub and node already in database'))]
db.define_table('tie',
Field('hubID','reference node',**isnode),
Field('nodeID','reference
node',default='',ondelete='CASCADE',notnull=True),
Field('createdOn',**attributes),
Field('modifiedOn',update=request.now,**attributes),
on_define=set_requirement,
migrate=False)
in default.py
def display_form():
db.tie.hubID.default=6
form = SQLFORM(db.tie)
if form.process().accepted:
response.flash = 'form accepted'
elif form.errors:
response.flash = 'form has errors'
else:
response.flash = 'please fill out the form'
return dict(form=form)
Using appadmin I enterd 6 nodes and made them reference 3 organizations
(node: 1, 2 and 3), 2 persons (node: 4 and 5) and 1 hub (node: 6).
In appadmin the validators do work as expected, but this i what happens
when I use display_form:
- when I comment out db.tie.hubID.default=6 and submit the form without any
values I get an error on nodeID 'value not in database'.
- when I comment out db.tie.hubID.default=6 and enter 1 for nodeID a record
with hubID is None and nodeID is 1 is created
- when I uncomment db.tie.hubID.default=6 and enter 2 for node ID a record with
hubID is 6 and nodeID is 2 is created
- when I enter 2 for nodeID again and submit the form it passes validation
without warning me that the database already contains
a record with hubID 6 and nodeID 2 and create another record with hubID is 6
and nodeID is 2
form=crud.update(db.tie,record=row) and form=SQLFORM.factory(db.tie) have the
same problem.
I hope you'll be able to figure out what I did wrong defining my tables as I
did.
Kind regards,
Annet
--