Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Adding javascript to enable notifications. Adding python code to hand…

…le that. Adding the model to hold that information. Next step: Check those flags and send notifications email/notifyIo to everyone enabled
  • Loading branch information...
commit 37ee55711c8f27ffd6d99edf3680f958c320182b 1 parent 6cde15e
@DFectuoso DFectuoso authored
Showing with 63 additions and 4 deletions.
  1. +33 −0 main.py
  2. +1 −0  static/style.css
  3. +29 −4 templates/base.html
View
33 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)
View
1  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;}
View
33 templates/base.html
@@ -5,11 +5,22 @@
<script type="text/javascript" src="/static/js/jquery.min.js"></script>
</head>
<body>
+ <div id="notificationPanel" style="display:none;">
+ <div><input type="checkbox" id="emailNotification" onClick="updateEmailNotification();"/> Enable mail notifications</div>
+ <div><input type="checkbox" id="notifyIoNotification" onClick="updateNotifyIoNotification();"/> Enable notify.io notifications</div>
+ </div>
<div id="top">
{% if user %}
- <span><strong>{{user.email}}</strong> | <a href="{{logout_url}}">Logout</a></span>
+ <span>
+ <strong>{{user.email}}</strong> |
+ <a href="javascript:void(0);" onclick="toggleNotifications();">Notifications</a> |
+ <a href="{{logout_url}}">Logout</a>
+ </span>
{% else %}
- <span><a style="font-weight: bold;" href="{{login_url}}">Login</a> | <a href="http://signup.hackerdojo.com/upgrade/needaccount">Need an account?</a></span>
+ <span>
+ <a style="font-weight: bold;" href="{{login_url}}">Login</a> |
+ <a href="http://signup.hackerdojo.com/upgrade/needaccount">Need an account?</a>
+ </span>
{% endif %}
</div>
<div id="wrapper">
@@ -22,6 +33,20 @@ <h2 style="font-size: x-large;">Log</h2>
{% block content %}{% endblock %}
</div>
</div>
-
+ <script type="text/javascript">
+ function updateEmailNotification(){
+ $.post('/notifications/email',{enable: $("#emailNotification")[0].checked});
+ }
+ function updateNotifyIoNotification(){
+ $.post('/notifications/notifyio',{enable: $("#notifyIoNotification")[0].checked});
+ }
+ function toggleNotifications(){
+ if($('#notificationPanel').css('display') == 'inline') {
+ $('#notificationPanel').css('display', 'none')
+ } else {
+ $('#notificationPanel').css('display','inline')
+ }
+ }
+ </script>
</body>
-</html>
+</html>
Please sign in to comment.
Something went wrong with that request. Please try again.