From 600ad5caf442f04c79cd38aa8ef78b95ef2f3080 Mon Sep 17 00:00:00 2001 From: Salvo 'LtWorf' Tomaselli Date: Thu, 26 Dec 2013 23:39:36 +0100 Subject: [PATCH] Google webapp to receive feedbacks --- feedback-ltworf/app.yaml | 9 +++++++++ feedback-ltworf/feedback.py | 30 ++++++++++++++++++++++++++++++ feedback-ltworf/micro_webapp2.py | 23 +++++++++++++++++++++++ 3 files changed, 62 insertions(+) create mode 100644 feedback-ltworf/app.yaml create mode 100644 feedback-ltworf/feedback.py create mode 100644 feedback-ltworf/micro_webapp2.py diff --git a/feedback-ltworf/app.yaml b/feedback-ltworf/app.yaml new file mode 100644 index 0000000..a89a1bf --- /dev/null +++ b/feedback-ltworf/app.yaml @@ -0,0 +1,9 @@ +application: feedback-ltworf +version: 1 +runtime: python27 +api_version: 1 +threadsafe: true + +handlers: +- url: /.* + script: feedback.application diff --git a/feedback-ltworf/feedback.py b/feedback-ltworf/feedback.py new file mode 100644 index 0000000..fe644ca --- /dev/null +++ b/feedback-ltworf/feedback.py @@ -0,0 +1,30 @@ +from google.appengine.api import users + +import webapp2 + +import micro_webapp2 +application = micro_webapp2.WSGIApplication() + +@application.route('/') +def m(request, *args, **kwargs): + return "" + +@application.route('/feedback/') +def mail_sender(request, *args, **kwargs): + + if request.method != "POST": + return "" + + message = "" + for k,v in request.POST.iteritems(): + message += "%s: %s\n" % (k,v) + + if kwargs["id"] == "relational": + from google.appengine.api import mail + + mail.send_mail(sender="Feedback service ", + to="tiposchi@tiscali.it", + subject="Feedback from %s" % kwargs["id"], + body=message) + + return "Message queued" diff --git a/feedback-ltworf/micro_webapp2.py b/feedback-ltworf/micro_webapp2.py new file mode 100644 index 0000000..34e76a8 --- /dev/null +++ b/feedback-ltworf/micro_webapp2.py @@ -0,0 +1,23 @@ +import webapp2 + +class WSGIApplication(webapp2.WSGIApplication): + def __init__(self, *args, **kwargs): + super(WSGIApplication, self).__init__(*args, **kwargs) + self.router.set_dispatcher(self.__class__.custom_dispatcher) + + @staticmethod + def custom_dispatcher(router, request, response): + rv = router.default_dispatcher(request, response) + if isinstance(rv, basestring): + rv = webapp2.Response(rv) + elif isinstance(rv, tuple): + rv = webapp2.Response(*rv) + + return rv + + def route(self, *args, **kwargs): + def wrapper(func): + self.router.add(webapp2.Route(handler=func, *args, **kwargs)) + return func + + return wrapper