I am working on a custom crud function. In my model I have got the following table:
db.define_table('adres', SQLField('bedrijf', db.bedrijf, default='', notnull=True), SQLField('adressoort', length=30, default='Vestigingsadres', notnull=True), SQLField('straat', length=42, default='', notnull=True), SQLField('huisnummer', length=6, default='', notnull=True), SQLField('huisnummerextensie', length=6), SQLField('postcode_cijferdeel', type='integer'), SQLField('postcode_letterdeel'), SQLField('plaats', length=42, default='', notnull=True), migrate='adres.table') db.adres.bedrijf.requires=IS_IN_DB(db, db.bedrijf.id, '%(bedrijfsnaam) s') db.adres.bedrijf.writable=False db.adres.bedrijf.readable=False db.adres.adressoort.requires=IS_IN_SET(['Statutair vestigingsadres','Vestigingsadres','Postadres']) db.adres.straat.requires=[IS_LENGTH(42,error_message=T('length exceeds 42')), IS_NOT_EMPTY()] db.adres.huisnummer.requires=[IS_LENGTH(6,error_message=T('length exceeds 6')), IS_NOT_EMPTY()] db.adres.huisnummerextensie.requires=IS_LENGTH(6,error_message=T ('length exceeds 6')) db.adres.postcode_cijferdeel.requires=IS_NULL_OR(IS_MATCH('\d {4}',error_message=T('no match 4 digits'))) db.adres.postcode_letterdeel.requires=IS_NULL_OR(IS_MATCH('[A-Z] {2}',error_message=T('no match 2 capitals'))) db.adres.plaats.requires=[IS_LENGTH(42,error_message=T('length exceeds 42')), IS_NOT_EMPTY()] To enable the user to manage his OWN records in this table, I defined the following function: @auth.requires_login() def crud_address(): form=crud.create(db.adres,onvalidation=lambda form: form.vars.bedrijf=auth.user.bedrijf) rows=db(db.adres.bedrijf==auth.user.bedrijf)\ .select (db.adres.id,db.adres.adressoort,db.adres.straat,db.adres.plaats,orderby=db.adres.straat) if form.accepts(form.vars,session): response.flash = T('new record inserted') elif form.errors: response.flash = T('form has errors') else: response.flash = T('please fill the form') return dict(form=form,rows=rows) The user shouldn't be able to edit the adres.bedrijf field, therefore, I defined the following validators: db.adres.bedrijf.writable=False db.adres.bedrijf.readable=False The field adres.bedrijf isn't displayed, but doesn't get a value either when I create a record (appadmin displays None). Whereas, I thought onvalidation=lambda form: form.vars.bedrijf=auth.user.bedrijf would give adres.bedrijf the desired value. How do I solve this problem? Is it in this case possible to use SQLFORM to define the custom form? I assume I will run into the same problem when defining an update function... 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 web2py@googlegroups.com To unsubscribe from this group, send email to web2py+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/web2py?hl=en -~----------~----~----~----~------~----~------~--~---