It's __getattr__ (not __getitem__) that should take the "default" argument,
right?
On Saturday, May 18, 2013 10:44:05 AM UTC-4, Vlasov Vitaly wrote:
>
> Hello group.
>
> I think i found bug in Reference.get(). Please check my message.
>
> Test db.py:
>
> db.define_table('person', Field
> <http://127.0.0.1:8000/examples/global/vars/Field>('name', 'string'), Field
> <http://127.0.0.1:8000/examples/global/vars/Field>('city', 'string'))
> db.define_table('info', Field
> <http://127.0.0.1:8000/examples/global/vars/Field>('somebody', 'reference
> person'), Field
> <http://127.0.0.1:8000/examples/global/vars/Field>('something', 'string'))
>
>
> person table got record: 1, John, New York
> info table got record: 1, 1, someinfo
>
> Test index.py
> def index():
> data=None
>
> form=FORM <http://127.0.0.1:8000/examples/global/vars/FORM>(INPUT
> <http://127.0.0.1:8000/examples/global/vars/INPUT>(_type='submit',
> _value='Test reference.get()'))
> if form.process().accepted:
> ref=db(db.info.id>0).select().first().somebody
> data=[type(ref), ref, ref.name]
> try:
> n = ref.get('name')
> data.append(n)
> except TypeError as TE:
> data.append(TE)
> return dict(form=form, message=data)
> return dict(form=form, message='Click test button')
>
>
> And view/default/index.html show form and returned data.
>
> When a call ref.get('fieldname'), exception is raised. But if i call
> ref['field name'] data is returned.
> So, let's look in gluon/dal.py:
> class Reference(long):
> .....
> def get(self, key, default=None):
> return self.__getattr__(key, default)
> .....
> def __getitem__(self, key):
> if key == 'id':
> return int(self)
> self.__allocate()
> return self._record.get(key, None)
> __getitem__ don't know about default arg.
>
--
---
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.