Permalink
Browse files

Drop down menus for awarding users and error checking

  • Loading branch information...
1 parent 7a9f4f9 commit 75560d245c0db4bb23a04a38f0cd06ad7ca9ccec Navraj Chohan committed Aug 7, 2011
View
3 CHANGELOG
@@ -27,3 +27,6 @@
* Fixed initial look for analytic charts that don't have data
* Ability to remove badges
* Fixed image centering for milestones widget
+ * Error checking for awarding users
+ * Drop down menu for awarding badges
+ * Text field for user entity on anything that has to be over 500 characters
View
2 serverside/api/api.py
@@ -116,7 +116,7 @@ def get_top_users(acc_ref):
def calculate_rank(user_ref, acc_ref):
rank = constants.NOT_RANKED
if not user_ref or not acc_ref:
- error("Unable to cal rank because of missing ref")
+ error("Unable to cal rank because of missing user or account ref")
return rank
if user_ref.rank:
View
66 serverside/console.py
@@ -48,6 +48,19 @@
import simplejson
json = simplejson
+def getErrorString(err):
+ if err == "BadImageType":
+ return "You may only have png, jpg, or gif image types"
+ elif err == "FileTooLarge":
+ return "Sorry, max image size allowed is " + str(constants.MAX_BADGE_SIZE) + " bytes"
+ elif err == "InvalidID":
+ return "Please check your values and try again"
+ elif err == "BadBadge":
+ return "Please check your badge id and try again"
+ elif err == "NoUserID":
+ return "A User ID was not provided, please try again"
+ return err
+
class Console(webapp.RequestHandler):
@account_login_required
def get(self):
@@ -68,18 +81,22 @@ def get(self):
""" Render users template """
current_session = Session().get_current_session(self)
email = current_session.get_email()
-
+ error = self.request.get("error")
+ has_error = False
+ if error:
+ has_error = True
+ error = getErrorString(error)
+ email = current_session.get_email()
+ account = current_session.get_account_entity()
+ badges = badges_dao.get_rendereable_badgeset(account)
template_values = {'users_main': True,
- 'account_name': email }
+ 'account_name': email,
+ 'badges':badges,
+ 'has_error': has_error,
+ 'error': error}
self.response.out.write(template.render(constants.TEMPLATE_PATHS.CONSOLE_DASHBOARD, template_values))
class ConsoleBadges(webapp.RequestHandler):
- def getErrorString(self, err):
- if err == "BadImageType":
- return "You may only have png, jpg, or gif image types"
- elif err == "FileTooLarge":
- return "Sorry, max image size allowed is " + str(constants.MAX_BADGE_SIZE) + " bytes"
- return err
@account_login_required
def get(self):
current_session = Session().get_current_session(self)
@@ -89,7 +106,7 @@ def get(self):
has_error = False
if error:
has_error = True
- error = self.getErrorString(error)
+ error = getErrorString(error)
badgeset = badges_dao.get_rendereable_badgeset(account)
upload_url = blobstore.create_upload_url('/badge/u')
template_values = {'badges_main': True,
@@ -109,6 +126,11 @@ def get(self):
current_session = Session().get_current_session(self)
email = current_session.get_email()
edit_user = self.request.get("name")
+ error = self.request.get("error")
+ has_error = False
+ if error:
+ has_error = True
+ error = getErrorString(error)
""" Generate links to see each widget for user """
userhash = hashlib.sha1(email + '---' + edit_user).hexdigest()
@@ -124,7 +146,9 @@ def get(self):
'view_trophy_case':trophy_case_widget_url,
'view_points':points_widget_url,
'view_rank':rank_widget_url,
- 'view_milestones':milestones_widget_url}
+ 'view_milestones':milestones_widget_url,
+ 'error':error,
+ 'has_error':has_error}
self.response.out.write(template.render(constants.TEMPLATE_PATHS.CONSOLE_DASHBOARD, template_values))
class ConsoleUsersFetch(webapp.RequestHandler):
@@ -485,7 +509,7 @@ def post(self):
email = account_entity.email
new_user_id = self.request.get("id")
if new_user_id == constants.ANONYMOUS_USER:
- self.redirect('/adminconsole/users')
+ self.redirect('/adminconsole/users?error=NoUserID')
return
profile_name = self.request.get("name")
profile_link = self.request.get("profile")
@@ -512,18 +536,29 @@ def post(self):
user_id = self.request.get('userid')
if not user_id:
- self.redirect('/adminconsole/users')
+ self.redirect('/adminconsole/users?error=NoUserID')
return
if user_id == constants.ANONYMOUS_USER:
- self.redirect('/adminconsole/users')
+ self.redirect('/adminconsole/users?error=InvalidID')
+ return
+ if not users_dao.get_user(email, user_id):
+ self.redirect('/adminconsole/users?error=InvalidID')
return
-
award_type = self.request.get('awardtype')
if award_type == 'awardbadge':
badge_id = self.request.get("badgeid")
+ if not badge_id:
+ logging.error("Badge ID not provided %s"%email)
+ self.redirect('/adminconsole/users?error=BadBadge')
+ badge_key = badges_dao.get_key_from_badge_id(email, badge_id)
+ if not badges_dao.get_badge(badge_key):
+ logging.error("Badge ID does not exist for account %s"%email)
+ self.redirect('/adminconsole/users?error=BadBadge')
if not ui.award_badge(user_id, badge_id):
+ self.redirect('/adminconsole/users?error=BadBadge')
logging.error("Make sure the client code urls points to http://<app-id>.appspot.com if this is a custom deploy")
logging.error("Account %s is unable to award badge %s to user %s"%(email, badge_id, user_id))
+ self.redirect('/adminconsole/users?error=BadBadge')
elif award_type == 'awardpoints':
points = self.request.get("points")
try:
@@ -532,9 +567,10 @@ def post(self):
points = 0
if not ui.award_points(user_id, points):
logging.error("Account %s is unable to award points %d to user %s"%(email, points, user_id))
+ self.redirect('/adminconsole/users?error=InvalidID')
else:
logging.error("Received %s for console user award from account %s"%(award_type, email))
- self.redirect('/adminconsole/users')
+ self.redirect('/adminconsole/users?error=InvalidID')
self.redirect('/adminconsole/users/edit?name=' + user_id)
View
1 serverside/logs.py
@@ -57,7 +57,6 @@ def __url_async_post(worker_url, argsdic):
for kk,vv in argsdic.items():
if vv.__class__.__name__ in ['str', 'unicode']:
argsdic[kk] = vv.encode('utf-8')
- logging.info("Worker " + str(worker_url))
taskqueue.add(url=worker_url, params=argsdic)
#urlfetch.make_fetch_call(rpc, url, payload=urllib.urlencode(argsdic), method=urlfetch.POST)
View
4 static/console_templates/dashboard.html
@@ -13,7 +13,7 @@
<link rel="stylesheet" media="screen" href="/console/css/messages.css" />
<link rel="stylesheet" media="screen" href="/console/css/forms.css" />
<link rel="stylesheet" media="screen" href="/console/css/tables.css" />
-
+<link rel="stylesheet" media="screen" href="/console/chosen/chosen.css" />
<!--[if lt IE 8]>
<link rel="stylesheet" media="screen" href="/console/css/ie.css" />
<![endif]-->
@@ -22,7 +22,7 @@
<script src="/console/js/jquery.tools.min.js"></script>
<script src="/console/js/jquery.tables.js"></script>
<script src="/console/js/jquery.ui.min.js"></script>
-
+<script src="/console/chosen/chosen.jquery.min.js"></script>
<script type="text/javascript">
View
20 static/console_templates/section_users.html
@@ -1,4 +1,5 @@
<section class="main-section grid_7">
+
<div class="main-content">
<header>
<ul class="action-buttons clearfix fr">
@@ -18,6 +19,10 @@
<div class="panes clearfix">
<section id="usersOrderedByNameSection">
<h3>Users ordered by name</h3>
+ {% if has_error %}
+ <div class="message error">{{ error }}</div>
+ {% endif %}
+
<p>Click on a user to view information.</p>
<hr />
<table class="datatable">
@@ -84,14 +89,25 @@
<section id="Award User">
<h3>Award a user a badge or points</h3>
<hr/>
- <div class="message error">This functionality currently does not have error handling. Make sure you are using the correct user id and badge id!</div>
<div class="message info">Note: Use the API calls award_badge, award_badge_points, and award_points to award users within your application.</div>
<form id="form" class="form grid_5" action="/adminconsole/users/award" method="post" enctype="multipart/form-data">
<fieldset>
<legend>Award a badge</legend>
<label>User Id<em>*</em><small></small></label><input type="text" name="userid" required="required" />
- <label>Badge Id<em>*</em><small></small></label><input type="text" name="badgeid" />
+ <label>Badge Id<em>*</em><small></small></label></br>
+<div>
+ <div>
+ <select data-placeholder="Choose a badge..." style="width:270px;" tabindex="1" name="badgeid">
+ {% for badge in badges %}
+ <option value="{{badge.id}}">{{badge.id}}</option>
+ {% endfor %}
+ {% if not badges %}
+ <option value="">Upload a badge first</option>
+ {% endif %}
+ </select>
+ </div>
+</div>
<input type="hidden" name="awardtype" value="awardbadge" />
<div class="action">
<button class="button button-gray" type="submit" ><span class="accept"></span>OK</button>
View
4 static/console_templates/section_users_edit.html
@@ -8,6 +8,10 @@
<h2>User information for: {{editusername}}</h2>
</header>
<section>
+ {% if has_error %}
+ <div class="message error">{{ error }}</div>
+ {% endif %}
+
<a href="{{view_trophy_case}}" class="button button-gray help" rel="#overlay">View Trophy Case</a>
<br />
<br />

0 comments on commit 75560d2

Please sign in to comment.