Not complete my sentence :

You already retrieve auth_user row, so I guess instead of use form.vars
instance for this piece of information you can get it from auth_user row...


On Thu, Mar 10, 2016 at 2:41 PM, Richard Vézina <[email protected]
> wrote:

> You can't get it in you onupdate function?
>
> You already retrieve auth_user row, so I guess instead of use form.vars
> instance for this piece of information...
>
> Though I am not sure what is exactly you problem...
>
> Richard
>
> On Thu, Mar 10, 2016 at 1:34 PM, David Orme <[email protected]> wrote:
>
>> Hello,
>>
>> I'm trying to use a variable from a form in an onupdate function, but
>> because I've set it to writeable=False in the controller, it doesn't get
>> passed in form.vars. In more depth:
>>
>> I've got a table for volunteers to post offers of help on a project.
>> Those have to be approved by an admin before becoming visible, but I don't
>> want the admin to be able to change the original data. So, I have this as
>> my table:
>>
>> db.define_table('help_offered',
>>     Field('volunteer_id', 'reference auth_user'),
>>     Field('volunteer_type', requires=IS_IN_SET(volunteer_type), notnull=
>> True),
>>     Field('available_from','date', notnull=True),
>>     Field('admin_status','string', requires=IS_IN_SET(['Pending',
>> 'Approved','Rejected']),
>>     Field('approval_notes','text'),
>>
>> For users, I just have a SQLFORM, which just doesn't show the two admin
>> fields (admin_status and approval_notes):
>>
>> def volunteer():
>>
>>     form = SQLFORM(db.help_offered,
>>                    fields =['volunteer_type', 'research_statement',
>> 'available_from'])
>>
>> Now for admin users, I want a table of pending offer, where they can view
>> records but only edit those two admin fields. So, SQLFORM.grid fits
>> perfectly:
>>
>> def administer_volunteers():
>>
>>     # lock down which fields can be changed
>>     db.help_offered.volunteer_id.writable = False
>>     db.help_offered.volunteer_type.writable = False
>>     db.help_offered.available_from.writable = False
>>
>>     # get a query of pending requests with user_id
>>     form = SQLFORM.grid(query=(db.help_offered.admin_status == 'Pending'
>> ), csv=False,
>>                         fields=[db.help_offered.volunteer_id,
>>                                 db.help_offered.volunteer_type,
>>                                 db.help_offered.available_from],
>>                          deletable=False, editable=True, create=False,
>> details=False,
>>                          onupdate = update_administer_volunteers)
>>
>> However, now I want to email the volunteers the decision, so onupdate
>> does this:
>>
>> def update_administer_volunteers(form):
>>
>>     # Email the decision to the proposer
>>     row = db(db.auth_user.id == form.vars.volunteer_id).select().first()
>>     volunteer_email = row.email
>>     volunteer_fn = row.first_name
>>
>>     # alternatives
>>     if form.vars.admin_status == 'Approved':
>>         mail.send(to=volunteer_email,
>>                   subject='Decision',
>>                   message='Approved'
>>     elif form.vars.admin_status == 'Rejected':
>>         mail.send(to=volunteer_email,
>>                   subject='Decision',
>>                   message='Rejected')
>>     else:
>>         pass
>>
>> But, form.vars only contains the writable fields and the row id:
>>
>> admin_status : Approved
>> approval_decision_date : 2016-03-10
>> approval_notes : Sounds good
>> approver_id : 1L
>> id : 3L
>>
>> I've seen solutions using hidden but I don't want to hide the field, just
>> make it read only, and I can't work out how to insert volunteer_id back
>> into my form. I could look up id in help_offered and then get the
>> volunteer_id that way but that seems like an unnecessary extra step!
>>
>> A long post for a simple question!
>>
>>
>> --
>> 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/d/optout.
>>
>
>

-- 
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/d/optout.

Reply via email to