Specific SQLForm Field Selection and Variables

18 views
Skip to first unread message

Cform

unread,
Jul 2, 2013, 8:38:55 AM7/2/13
to web...@googlegroups.com
        This might be sort of an easy question so I apologize. I am making an application where the user selects from a drop down list of template messages and then the program sends a text where the message body depends on what item was selected from the drop down. I.e If I selected 6 from the drop down list the message would send string "update" or if it selected 3 it might send the word "lock".
        This is relationship is defined in a Table and then called in a field in a separate table. So there are two tables, one that has the Message type and the corresponding word as fields, and then Table 2 which is displayed for the user to enter information in, has a field that calls IS_IN_DB to the message type in Field 1.
        My problem is I can't seem to figure out how to send a message that sends the corresponding word based on which message type the user selects from the drop down. I tried reading about validators and the database abstraction layer but I didn't find anything that would really help me.

The code is here but it doesn't quite work.


@auth.requires_login()
def send_message():
    form1=SQLFORM(db.t_sms, fields=['f_service','f_messagevar1'])
    form2=SQLFORM(db.t_sms, fields=['f_service','f_messagevar2'])
    
    if request.vars.f_service:
        servicetype1 = db(db.t_messagetype.id==request.vars.f_service).select().f_servicenumber
      

    if form1.process(formname='form_one').accepted:
        session.flash = 'form accepted'
        account = "account number"
        token = "token number"
        client = TwilioRestClient(account, token)
        message = client.sms.messages.create(to="+to phone number", from_="from phone number",
                                             body= 'Service' + ' ' + str(form1.vars.f_messagevar1) + ' ' + str(servicetype1)

Alan Etkin

unread,
Jul 2, 2013, 8:24:05 PM7/2/13
to
        This might be sort of an easy question so I apologize. I am making an application where the user selects from a drop down list of template messages and then the program sends a text where the message body depends on what item was selected from the drop down. I.e If I selected 6 from the drop down list the message would send string "update" or if it selected 3 it might send the word "lock".
 
It is not clear to me why you need to expose to db crud forms instead of using a fake one and process the request accordingly. I'd use something like

def action():
    form
= SQLFORM.factory(<...>)
   
if form.process().accepted:
       
<here you process the message with the submitted values>
   
return dict(form=form, ...)

Note that you can use actual database tables/fields and their validators with the form factory.
http://www.web2py.com/book/default/chapter/07#SQLFORM.factory
Reply all
Reply to author
Forward
0 new messages