Exemplo n.º 1
0
 def send_inquiry(self, data):
     context = aq_inner(self.context)
     subject = _(u"Inquiry from website visitor")  # noqa
     email_subject = api.portal.translate(
         "Inquiry from website visitor",
         'stv.sitecontent',
         api.portal.get_current_language())
     data['subject'] = email_subject
     mail_tpl = self._compose_message(data)
     mail_plain = create_plaintext_message(mail_tpl)
     msg = prepare_email_message(mail_tpl, mail_plain)
     recipients = [
         '*****@*****.**', 
         '*****@*****.**', 
     ]
     send_mail(
         msg,
         recipients,
         email_subject
     )
     next_url = '{0}/@@inquiry-form-dispatched/'.format(
         context.absolute_url()
     )
     url = addTokenToUrl(next_url)
     return self.request.response.redirect(url)
Exemplo n.º 2
0
 def update(self):
     translation_service = api.portal.get_tool(name="translation_service")
     unwanted = ('_authenticator', 'form.button.Submit')
     required = ['email']
     if 'form.button.Submit' in self.request:
         authenticator = getMultiAdapter((self.context, self.request),
                                         name=u"authenticator")
         if not authenticator.verify():
             raise Unauthorized
         form = self.request.form
         form_data = {}
         form_errors = {}
         errorIdx = 0
         for value in form:
             if value not in unwanted:
                 form_data[value] = safe_unicode(form[value])
                 if not form[value] and value in required:
                     error = {}
                     error_msg = _(u"This field is required")
                     error['active'] = True
                     error['msg'] = translation_service.translate(
                         error_msg,
                         'stv.sitecontent',
                         target_language=api.portal.get_default_language()
                     )
                     form_errors[value] = error
                     errorIdx += 1
                 else:
                     error = {}
                     error['active'] = False
                     error['msg'] = form[value]
                     form_errors[value] = error
         if errorIdx > 0:
             self.errors = form_errors
         else:
             self.send_inquiry(form)