예제 #1
0
파일: main.py 프로젝트: hackerdojo/hd-kudos
 def post(self):
     user = users.get_current_user()
     if not user or not self.request.get('user_to') in domain('/users'):
         self.redirect('/')
         return
     from_profile = Profile.get_by_user(user)
     kudos_to_give = int(self.request.get('points'))
     if kudos_to_give > from_profile.to_give:
         kudos_to_give = from_profile.to_give
     if kudos_to_give < 0:
         kudos_to_give = 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.received_total += kudos_to_give
     to_profile.received_this_month += kudos_to_give
     to_profile.put()
     kudos = Kudos(
         user_to=to_profile.user,
         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()
     mail.send_kudos_email(kudos, from_profile, to_profile)
     self.redirect('/kudos/%s' % kudos.key().id())
예제 #2
0
파일: main.py 프로젝트: hackerdojo/hd-kudos
 def get(self):
     user = users.get_current_user()
     profile = Profile.get_by_user(user)
     if user:
         logout_url = users.create_logout_url('/')
         points_remaining = "&hearts;"*profile.to_give
         points_used = "&hearts;"*(MONTHLY_POINTS-profile.to_give)
         point_options = [(n + 1,"&hearts;"*(n+1)) for n in range(profile.to_give)]
     else:
         login_url = users.create_login_url('/')
         points_remaining = 0
         points_used = 0
         point_options = None
         
     names = []
     usernames = {}
     for u in domain('/users'):
         name = fullname(u)
         if not u == username(user):
             usernames[name] = u
             names.append(name)
     usernames = simplejson.dumps(usernames)
     names = simplejson.dumps(names)
     
     # monthly leader board
     receive_leaders = Profile.top_receivers_this_month()
     give_leaders = Profile.top_givers_this_month()
     this_month = datetime.datetime.now().strftime('%B')
     
     self.response.out.write(template.render('templates/main.html', locals()))
예제 #3
0
파일: main.py 프로젝트: hackerdojo/hd-kudos
 def post(self):
     username = self.request.get('username')
     month_ttl = 3600*24*28
     user = domain('/users/%s' % username)
     if len(user):
         memcache.set('/users/%s:fullname' % username, "%s %s" % (user['first_name'], user['last_name']), month_ttl)