From 37ee55711c8f27ffd6d99edf3680f958c320182b Mon Sep 17 00:00:00 2001 From: DFectuoso Date: Wed, 28 Apr 2010 00:24:45 -0700 Subject: [PATCH] Adding javascript to enable notifications. Adding python code to handle that. Adding the model to hold that information. Next step: Check those flags and send notifications email/notifyIo to everyone enabled --- main.py | 33 +++++++++++++++++++++++++++++++++ static/style.css | 1 + templates/base.html | 33 +++++++++++++++++++++++++++++---- 3 files changed, 63 insertions(+), 4 deletions(-) diff --git a/main.py b/main.py index 8fa8762..b0c4761 100755 --- a/main.py +++ b/main.py @@ -49,6 +49,21 @@ def post(self): memcache.set('/users/%s:fullname' % username, "%s %s" % (user['first_name'], user['last_name']), month_ttl) #Data Models: +class Profile(db.Model): + user = db.UserProperty(auto_current_user_add=True) + emailNotification = db.BooleanProperty(default=False) + notifyIoNotification = db.BooleanProperty(default=False) + + @staticmethod + def get_or_create(): + profile = Profile.all().filter('user =',users.get_current_user()).fetch(1) + if len(profile) == 0: + profile = Profile() + profile.put() + return profile + else: + return profile[0] + class Update(db.Model): user = db.UserProperty(auto_current_user_add=True) body = db.StringProperty(required=True, multiline=True) @@ -115,11 +130,29 @@ def post(self): update.put() self.redirect('/') +class EmailNotificationHandler(webapp.RequestHandler): + def post(self): + user = Profile.get_or_create() + user.emailNotification = str_to_bool(self.request.get('enable')) + user.put() + +class NotifyIoNotificationHandler(webapp.RequestHandler): + def post(self): + user = Profile.get_or_create() + user.notifyIoNotification = str_to_bool(self.request.get('enable')) + user.put() + +def str_to_bool(str): + if str == "true": return True + else: return False + def main(): application = webapp.WSGIApplication([ ('/', MainHandler), ('/updates/(.+)', UpdatesHandler), ('/comment/(.+)', CommentHandler), + ('/notifications/email', EmailNotificationHandler), + ('/notifications/notifyio', NotifyIoNotificationHandler), ('/worker/user', UserWorker), ], debug=True) util.run_wsgi_app(application) diff --git a/static/style.css b/static/style.css index c80bfba..5143caf 100644 --- a/static/style.css +++ b/static/style.css @@ -36,3 +36,4 @@ h4 { font-size: smaller; } .update { min-height:50px;} .update-input { width:500px;} .comment-form { clear:both;} +#notificationPanel{position:absolute; right:0px; top:20px; width:150px; height:150px; background:grey;} diff --git a/templates/base.html b/templates/base.html index 203e0a5..d713fa2 100644 --- a/templates/base.html +++ b/templates/base.html @@ -5,11 +5,22 @@ +
{% if user %} - {{user.email}} | Logout + + {{user.email}} | + Notifications | + Logout + {% else %} - Login | Need an account? + + Login | + Need an account? + {% endif %}
@@ -22,6 +33,20 @@

Log

{% block content %}{% endblock %}
- + - \ No newline at end of file +