Here's a multi-recipient email function I just got working. It is newbie-created and horrible, but I'm hoping that building something like this is such a common requirement that someone might be willing to give tips that others could benefit from.
Can anyone give guidance on any part of it? *Model* Parent: fields generally include senderID, subject-line, body-of-message Child: fields generally include recipientID (can be many children for one parent) *Function* The hard part is selecting more than one recipient. First possible error that needs correcting: Used 'selectable' from grid. Is this a bad idea? grid = SQLFORM.grid(potentialEmailRecipientsQuery, selectable=lambda ids: redirect(URL('message_send_to', vars=dict(ids=ids)), searchable=False, sortable=False, editable=False,create=False, deletable=False, details=False , fields=[db.auth_user.id, db.auth_user.first_name, db.auth_user.last_name, db.auth_user.currentPosition]) Two problems with this (1) if allow searching or sorting for recipients, it UN-selects previously selected recipients (2) Don't know how to select recipients and type the subject-line/body of message on same page. In this example, user picks recipients on one page, then gets sent to new page to type subject/body: message_send_to function. Looks unpolished. Finally, in the 2nd function, capturing the recipient group method seems like it's done wrong. Look at the code below. If there is only one recipient, the object list is empty and I have to write special code for just one recipient. Did I do something wrong in capturing recipient list? emailRecipients = db(db.auth_user.id.belongs(request.get_vars.ids)).select() def message_send_to(): emailRecipients = db(db.auth_user.id.belongs(request.get_vars.ids)).select() form=SQLFORM.factory(db.InternalMessage) if form.process().accepted: messageID = db.InternalMessage.insert(**db.InternalMessage._filter_fields(form.vars)) form.vars.messageID=messageID if len(request.get_vars.ids) == 1: ## why need this if there is only one recipient? See "for" loop below. db.InternalMessageRecipient.recipientOfMessage.default = request.get_vars.ids internalMessageRecipientMessageID = db.InternalMessageRecipient.insert(**db.InternalMessageRecipient._filter_fields(form.vars)) if len(request.get_vars.ids) > 1: ## works great ONLY if there is more than one recipient. If only 1 recipient, it is empty! for row in emailRecipients: db.InternalMessageRecipient.insert(recipientOfMessage=row.auth_user.id, messageID=messageID) session.flash='Your message has been sent.' redirect(URL('view_user_profile', args=[auth.user_id])) return locals() If anyone can give some pointers or has their own pick-several-email-recipients example, that would be great. thanks, Alex Glaros -- 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 web2py+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.