-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
initial commit -- mostly functional. no monthly reset
- Loading branch information
0 parents
commit ab8aead
Showing
11 changed files
with
336 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
-prevent giving self kudos | ||
-monthly reset of points |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
application: hd-kudos | ||
version: 1 | ||
runtime: python | ||
api_version: 1 | ||
|
||
handlers: | ||
- url: /favicon.ico | ||
static_files: static/favicon.ico | ||
upload: static/favicon.ico | ||
- url: /robots.txt | ||
static_files: static/robots.txt | ||
upload: static/robots.txt | ||
- url: /static | ||
static_dir: static | ||
- url: .* | ||
script: main.py |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
indexes: | ||
|
||
# AUTOGENERATED | ||
|
||
# This index.yaml is automatically updated whenever the dev_appserver | ||
# detects that a new type of query is run. If you want to manage the | ||
# index.yaml file manually, remove the above marker line (the line | ||
# saying "# AUTOGENERATED"). If you want to manage some indexes | ||
# manually, move them above the marker line. The index.yaml file is | ||
# automatically uploaded to the admin console when you next deploy | ||
# your application using appcfg.py. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
from google.appengine.ext import webapp, db | ||
from google.appengine.ext.webapp import util, template | ||
from google.appengine.api import urlfetch, memcache, users | ||
from django.utils import simplejson | ||
|
||
MONTHLY_POINTS = 10 | ||
|
||
class Profile(db.Model): | ||
user = db.UserProperty(auto_current_user_add=True) | ||
points = db.IntegerProperty(default=MONTHLY_POINTS) | ||
total_kudos = db.IntegerProperty(default=0) | ||
monthly_kudos = db.IntegerProperty(default=0) | ||
|
||
@classmethod | ||
def get_by_user(cls, user): | ||
profile = cls.all().filter('user =', user).get() | ||
if not profile: | ||
profile = cls(user=user) | ||
profile.put() | ||
return profile | ||
|
||
class Kudos(db.Model): | ||
user_from = db.UserProperty(auto_current_user_add=True) | ||
user_to = db.UserProperty(required=True) | ||
amount = db.IntegerProperty(required=True) | ||
created = db.DateTimeProperty(auto_now_add=True) | ||
|
||
|
||
class MainHandler(webapp.RequestHandler): | ||
@util.login_required | ||
def get(self): | ||
user = users.get_current_user() | ||
profile = Profile.get_by_user(user) | ||
if user: | ||
logout_url = users.create_logout_url('/') | ||
else: | ||
login_url = users.create_login_url('/') | ||
usernames = memcache.get('usernames') | ||
if not usernames: | ||
usernames = simplejson.loads(urlfetch.fetch('http://localhost/~jeff/users.json').content) | ||
memcache.set('usernames', usernames, 3600) | ||
point_options = [n + 1 for n in range(profile.points)] | ||
self.response.out.write(template.render('templates/main.html', locals())) | ||
|
||
def post(self): | ||
user = users.get_current_user() | ||
if not user: | ||
return | ||
from_profile = Profile.get_by_user(user) | ||
points = int(self.request.get('points')) | ||
if points > from_profile.points: | ||
points = from_profile.points | ||
if points < 0: | ||
points = 0 | ||
# If profile doesn't exist it will be created, no matter if user exists (which is fine) | ||
to_profile = Profile.get_by_user(users.User(self.request.get('user_to') + '@hackerdojo.com')) | ||
to_profile.total_kudos += points | ||
to_profile.monthly_kudos += points | ||
to_profile.put() | ||
kudos = Kudos( | ||
user_to=to_profile.user, | ||
amount =points | ||
) | ||
kudos.put() | ||
from_profile.points -= points | ||
from_profile.put() | ||
self.redirect('/') | ||
|
||
def main(): | ||
application = webapp.WSGIApplication([ | ||
('/', MainHandler)], debug=True) | ||
util.run_wsgi_app(application) | ||
|
||
if __name__ == '__main__': | ||
main() |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
User-agent: * | ||
Allow: / |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
body { font-family: Verdana,Arial,sans-serif; margin: 0px;} | ||
#wrapper { margin-left: auto; margin-right: auto; width: 700px; } | ||
|
||
#top a:visited { color: blue;} | ||
#top { height: 20px; border-bottom: 1px solid #ccc; text-align: right; font-size: 12px; padding-right: 5px; padding-top: 4px; } | ||
|
||
#header { margin-left: auto; margin-right: auto; width: 670px; height: 125px;} | ||
#header img { margin-right: 10px;} | ||
#header h1 { font-size: 42px; margin-top: 20px; padding-top: 10px; margin-bottom: 0px; padding-bottom: 0px;} | ||
#header h2 { font-size: x-large; margin: 0px; } | ||
|
||
.step span { color: white; background-color: #b10026; padding: 1px; padding-left: 4px; padding-right: 4px;} | ||
.step.inactive span { background-color: gray;} | ||
.step.inactive { color: gray; } | ||
|
||
h3 { margin-top: 0px;} | ||
h4 { margin-bottom: 0px;} | ||
|
||
table td { padding-left: 10px; padding-top: 4px;} | ||
|
||
form div { margin-top: 10px; } | ||
|
||
label { display: block; font-size: smaller;} | ||
|
||
a:visited { color: blue;} | ||
|
||
#content { border-top: 3px solid #d50025; background: #eee; padding: 10px; } | ||
#primary { background: white; width: 660px; padding: 10px;} | ||
h4 { font-size: smaller; } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<html> | ||
<head> | ||
<title>Hacker Dojo Kudos</title> | ||
<link href="/static/style.css" type="text/css" rel="stylesheet" /> | ||
<script type="text/javascript" src="/static/js/jquery.min.js"></script> | ||
</head> | ||
<body> | ||
<div id="top"> | ||
{% if user %} | ||
<span><strong>{{user.email}}</strong> | <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> | ||
{% endif %} | ||
</div> | ||
<div id="wrapper"> | ||
<div id="header"> | ||
<img src="/static/dojo_icon.png" style="float: left;" /> | ||
<h1>Hacker Dojo</h1> | ||
<h2 style="font-size: x-large;">Kudos!</h2> | ||
</div> | ||
<div id="content"> | ||
{% block content %}{% endblock %} | ||
</div> | ||
</div> | ||
|
||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
{% extends 'base.html' %} | ||
{% block content %} | ||
<p>You have: {{profile.total_kudos}} kudos total</p> | ||
<p>You have: {{profile.points}} points remaining to give</p> | ||
{% ifequal profile.points 0 %} | ||
{% else %} | ||
<p><form action="/" method="post"> | ||
Give | ||
<select name="points"> | ||
{% for points in point_options %}<option>{{points}}</option>{% endfor %} | ||
</select> | ||
kudo points to | ||
<select name="user_to"> | ||
{% for username in usernames %} | ||
<option value="{{username}}">{{username}}</option> | ||
{% endfor %} | ||
</select> <input type="submit" value="Give em" /> | ||
</form></p> | ||
{% endifequal %} | ||
{% endblock %} |