Permalink
Browse files

adding kudos certificates and comment/reason for kudos

  • Loading branch information...
1 parent 5bf1922 commit cb8852a7a7a1794a4fe39c374f542ad8bd37bb67 @progrium progrium committed Apr 18, 2010
Showing with 52 additions and 13 deletions.
  1. +0 −2 TODO
  2. +22 −2 main.py
  3. +14 −0 templates/certificate.html
  4. +16 −9 templates/main.html
View
2 TODO
@@ -1,3 +1 @@
-comment field
-certificate page
history/log
View
24 main.py
@@ -80,8 +80,18 @@ class Kudos(db.Model):
user_from = db.UserProperty(auto_current_user_add=True)
user_to = db.UserProperty(required=True)
amount = db.IntegerProperty(required=True)
+ reason = db.StringProperty()
created = db.DateTimeProperty(auto_now_add=True)
+ def from_profile(self):
+ return Profile.all().filter('user =', self.user_from).get()
+
+ def to_profile(self):
+ return Profile.all().filter('user =', self.user_to).get()
+
+ def hearts(self):
+ return "♥" * self.amount
+
class MainHandler(webapp.RequestHandler):
def get(self):
user = users.get_current_user()
@@ -130,15 +140,24 @@ def post(self):
to_profile.put()
kudos = Kudos(
user_to=to_profile.user,
- amount =kudos_to_give
+ amount =kudos_to_give,
+ reason =self.request.get('reason'),
)
kudos.put()
# if you try to give yourself kudos, you lose the points, as this put overwrites to_profile.put
from_profile.to_give -= kudos_to_give
from_profile.gave_this_month += kudos_to_give
from_profile.gave_total += kudos_to_give
from_profile.put()
- self.redirect('/')
+ self.redirect('/kudos/%s' % kudos.key().id())
+
+class CertificateHandler(webapp.RequestHandler):
+ def get(self, kudos_id):
+ kudos = Kudos.get_by_id(int(kudos_id))
+ if kudos:
+ self.response.out.write(template.render('templates/certificate.html', locals()))
+ else:
+ self.redirect('/')
class CronHandler(webapp.RequestHandler):
#def get(self):
@@ -162,6 +181,7 @@ def post(self):
def main():
application = webapp.WSGIApplication([
('/', MainHandler),
+ ('/kudos/(\d+)', CertificateHandler),
('/reset_points', CronHandler),
('/worker/user', UserWorker), ], debug=True)
util.run_wsgi_app(application)
View
14 templates/certificate.html
@@ -0,0 +1,14 @@
+{% extends 'base.html' %}
+{% block content %}
+<div id="primary" style="padding-top: -10px; text-align: center;">
+ <h1>Certificate of Kudos</h1>
+ <em>{{kudos.from_profile.fullname}} has praised</em>
+ <h1 style="margin-top: 5px; margin-bottom: 10px;">{{kudos.to_profile.fullname}}<br /><span style="color: #d50025;">{{kudos.hearts}}</span></h1>
+ <em>with {{kudos.amount}} kudos {% if kudos.reason %}for</em>
+ <h2>{{kudos.reason}}</h2>
+ <em>{% endif %}on the day of {{kudos.created|date:"F j, Y"}}</em>
+ <p style="margin: 25px;">The Dojo community is better from their efforts.</p>
+ <a href="/" style="color: gray; font-size: smaller;">&larr; Back to Kudos</a>
+</div>
+
+{% endblock %}
View
25 templates/main.html
@@ -18,10 +18,18 @@
<h2>Give kudos</h2>
{% if user %}
+
+<div style="float: right; font-size: x-large; text-align: right; margin-top: -35px; line-height: 16px; margin-right: 5px;">
+ <span style="font-size: x-small;">You have {{profile.to_give}} left to give this month</span><br />
+ <span style="color: #d50025;">{{points_remaining}}</span>{{points_used}}
+</div>
+{% ifequal profile.to_give 0 %}
+<p style="margin-left: 20px;">
+ <strong>You've run out of kudos to give!</strong><br />
+ <span style="font-size: smaller; padding-left: 2px;">I guess you'll have to wait until next month...</span></p>
+{% else %}
<form action="/" method="post" onsubmit="return !$('#submit')[0].disabled">
<table>
- {% ifequal profile.to_give 0 %}
- {% else %}
<tr><td class="label">Who gets kudos:</td><td class="label">How much:</td><td></td></tr>
<tr><td>
<input type="text" onkeyup="updateUser()" onblur="updateUser()" id="user_name" size="18" style="font-size: 18px;"/>
@@ -30,16 +38,15 @@
<select name="points" style="color: #d50025; font-size: 14px;">
{% for points in point_options %}<option value="{{points.0}}">{{points.1}}</option>{% endfor %}
</select>
- </td><td>
+ </td></tr>
+ <tr><td colspan="2" class="label" style="font-size: ;">What for:</td></tr>
+ <tr><td colspan="2"><input type="text" name="reason" style="width: 100%; font-size: 14px;"/></td><td>
<input type="submit" disabled="disabled" id="submit" value="Give em" />
</td></tr>
- {% endifequal %}
-
- <tr><td colspan="3" class="label">You have {{profile.to_give}} left to give this month</td></tr>
- <tr><td colspan="3" style="font-size: 32px; line-height: 20px;"><span style="color: #d50025;">{{points_remaining}}</span>{{points_used}}
-</td></tr>
</table>
- </form>
+</form>
+{% endifequal %}
+
{% else %}
<p><a href="{{login_url}}">Login</a> to give kudos!</p>
{% endif %}

0 comments on commit cb8852a

Please sign in to comment.