hi,
is it possible to retrieve data from table and then input it to another
table using sqlform grid?
my goal is when i submit the check out form, it will retrieve room and
guest data from table check in and then insert it to table check out.
below is the code that not work (no error occured, but the result is not
expected when i submit it the form is not responding)
thank you very much in advance.
*db.py*
db.define_table('check_out',
Field('check_in', 'reference check_in'),
Field('room', 'reference room'),
Field('guest', 'reference guest'),
Field('description', 'text'),
format=lambda r: '%s %s-%s-%s' % (r.guest.first_name,
r.guest.last_name,
r.room.branch.address,
r.room.room_no))
db.check_out.check_in.requires=IS_IN_DB(db(db.check_in.is_active==True),
db.check_in.id,
label=format_check_in)
db.check_out.description.requires=IS_NOT_EMPTY()
*default.py*
def __oncreate_check_out(form):
room=db(db.room.id==form.vars.room).update(status='Checked Out')
check_in=db(db.check_in.room==form.vars.room).update(is_active=False)
return locals()
def __onvalidation_check_out(form):
if form.vars.check_in:
rows = db(db.check_in.id==form.vars.check_in).select()
for row in rows:
form.vars.room = row.room
form.vars.guest = row.guest
else:
form.errors.check_in = 'cannot be empty'
@auth.requires_login()
def check_out():
query = db.check_out.is_active==True
has_membership=auth.has_membership('Manager')
grid=SQLFORM.grid(query, user_signature=False,
maxtextlength=100,
onvalidation=__onvalidation_check_out,
oncreate=__oncreate_check_out, onupdate=auth.archive,
editable=has_membership, deletable=has_membership)
return locals()
*check_out.html*
{{extend 'layout.html'}}
{{=grid}}
<script>
jQuery(document).ready(function(){
jQuery('#check_out_room__row').hide();
jQuery('#check_out_guest__row').hide();
});
</script>
--
---
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.