Skip to content

Commit

Permalink
Adding javascript to enable notifications. Adding python code to hand…
Browse files Browse the repository at this point in the history
…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
DFectuoso committed Apr 28, 2010
1 parent 6cde15e commit 37ee557
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 4 deletions.
33 changes: 33 additions & 0 deletions main.py
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions static/style.css
Expand Up @@ -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;}
33 changes: 29 additions & 4 deletions templates/base.html
Expand Up @@ -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">
Expand All @@ -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>

0 comments on commit 37ee557

Please sign in to comment.