Пример #1
0
 def get(self, page):
   try:
     path = os.path.join(os.path.dirname(__file__), 'templates/' + page + '.html')
     response_text = template.render(path, {'init': True})
   except template.django.template.TemplateDoesNotExist:
     logging.warn('ContentPage.get - Warning: page %s not found.'%(page))
     self.error(404)
     response_text = utils.getErrorTemplate(404)
   except:
     logging.error('ContentPage.get - Error: ' + traceback.format_exc())
     self.error(500)
     response_text = utils.getErrorTemplate(500)
   self.response.out.write(response_text)
Пример #2
0
 def get(self):
   redirect_map = {'/devis':'/commande'}
   target_url = redirect_map.get(self.request.path)
   if target_url:
     query = self.request.query
     if query:
       target_url = target_url + '?' + query
     self.redirect(target_url)
   else:
     logging.warn('RedirectHandler.get - Warning: page not found.')
     self.error(404)
     self.response.out.write(utils.getErrorTemplate(404))
Пример #3
0
 def post(self):
   try:
     nom = self.request.POST.get('nom')
     email = self.request.POST.get('email')
     tel = self.request.POST.get('tel')
     message = self.request.POST.get('message')
     if nom and email and message:
       if utils.validateEmail(email):
         email_template_path = os.path.join(os.path.dirname(__file__), 'templates/email_message.html')
         html_body = template.render(email_template_path, {'nom': nom,
                                                           'email': email,
                                                           'tel': tel,
                                                           'message': message})
         mail.send_mail(sender='Faster\'s energy <*****@*****.**>', 
                        to='*****@*****.**',
                        subject='Message de la part de ' + nom,
                        body=html_body,
                        html=html_body)
         path = os.path.join(os.path.dirname(__file__), 'templates/contactez-nous.html')
         response_text = template.render(path, {'init': False,
                                                'success': True,
                                                'response': u'Message envoyé.'})
       else:
         path = os.path.join(os.path.dirname(__file__), 'templates/contactez-nous.html')
         response_text = template.render(path, {'init': False,
                                                'success': False,
                                                'nom':nom,
                                                'email':email,
                                                'tel': tel,
                                                'message': message,
                                                'response': u'L\'email renseigné n\'est pas valide.'})
     else:
       if not nom:
         response = u'Le nom est obligatoire.'
       elif not email:
         response = u'L\'email est obligatoire.'
       elif not message:
         response = u'Vous devez mettre un message.'
       path = os.path.join(os.path.dirname(__file__), 'templates/contactez-nous.html')
       response_text = template.render(path, {'init': False,
                                              'success': False,
                                              'nom':nom,
                                              'email':email,
                                              'tel': tel,
                                              'message': message,
                                              'response': response})
   except:
     logging.error('Message.post - Error : ' + traceback.format_exc())
     self.error(500)
     response_text = utils.getErrorTemplate(500)
   self.response.out.write(response_text)