def player_add_points(profile, points, transaction_date, message, related_object=None): """Adds points based on the point value of the submitted object.""" # player won't get points if outside of the competitions. # ignore the transaction if not challenge_mgr.in_competition(transaction_date): return # Create a transaction first. transaction = PointsTransaction( user=profile.user, points=points, transaction_date=transaction_date, message=message, ) if related_object: transaction.related_object = related_object transaction.save() # update the scoreboard entry _update_scoreboard_entry(profile, points, transaction_date) # Invalidate info bar cache. cache_mgr.invalidate_template_cache("RIB", profile.user.username)
def player_remove_points(profile, points, transaction_date, message, related_object=None): """Removes points from the user. If the submission date is the same as the last_awarded_submission field, we rollback to a previously completed task. """ if not challenge_mgr.in_competition(transaction_date): return # update the scoreboard entry _update_scoreboard_entry(profile, points * -1, transaction_date) # Log the transaction. transaction = PointsTransaction( user=profile.user, points=points * -1, transaction_date=transaction_date, message=message, ) if related_object: transaction.related_object = related_object transaction.save() # Invalidate info bar cache. cache_mgr.invalidate_template_cache("RIB", profile.user.username)
def check_resource_goals(resource, date): """Check the previous day's resource goal for all teams.""" # check the previous day's data and goal date = date - datetime.timedelta(days=1) date = datetime.datetime(date.year, date.month, date.day, hour=23, minute=59, second=59) # do nothing if out of round if not challenge_mgr.in_competition(date): return 0 update_resource_usage(resource, date) is_awarded = False for team in Team.objects.all(): count = check_team_resource_goal(resource, team, date) if count: print '%s users in %s are awarded %s points each.' % ( count, team, team_goal_settings(team, resource).goal_points) is_awarded = True if not is_awarded: print 'No user are awarded daily goal points.'
def check_resource_goals(resource, date): """Check the previous day's resource goal for all teams.""" # check the previous day's data and goal date = date - datetime.timedelta(days=1) date = datetime.datetime(date.year, date.month, date.day, hour=23, minute=59, second=59) # do nothing if out of round if not challenge_mgr.in_competition(date): return 0 update_resource_usage(resource, date) is_awarded = False for team in Team.objects.all(): count = check_team_resource_goal(resource, team, date) if count: print '%s users in %s are awarded %s points each.' % ( count, team, team_goal_settings(team, resource).goal_points) is_awarded = True if not is_awarded: print 'No user are awarded daily goal points.'
def notify_round_started(): """Notify the user of a start of a round.""" if not challenge_mgr.in_competition(): return today = datetime.datetime.today() current_round = None previous_round = None rounds = challenge_mgr.get_all_round_info()["rounds"] for key in rounds.keys(): # We're looking for a round that ends today and another that starts # today (or overall) start = rounds[key]["start"] end = rounds[key]["end"] # Check yesterday's round and check for the current round. if start < (today - datetime.timedelta(days=1)) < end: previous_round = key if start < today < end: current_round = key print "Previous Round: %s" % previous_round print "Current Round: %s" % current_round if current_round and previous_round and current_round != previous_round: print "Sending out round transition notices." template = NoticeTemplate.objects.get(notice_type="round-transition") message = template.render({"PREVIOUS_ROUND": previous_round, "CURRENT_ROUND": current_round}) for user in User.objects.all(): UserNotification.create_info_notification(user, message, display_alert=True)
def player_remove_points(profile, points, transaction_date, message, related_object=None): """Removes points from the user. If the submission date is the same as the last_awarded_submission field, we rollback to a previously completed task. """ if not challenge_mgr.in_competition(transaction_date): return # update the scoreboard entry _update_scoreboard_entry(profile, points * -1, transaction_date) # Log the transaction. transaction = PointsTransaction( user=profile.user, points=points * -1, transaction_date=transaction_date, message=message, ) if related_object: transaction.related_object = related_object transaction.save() # Invalidate info bar cache. cache_mgr.invalidate_template_cache("RIB", profile.user.username)
def player_add_points(profile, points, transaction_date, message, related_object=None): """Adds points based on the point value of the submitted object.""" # player won't get points if outside of the competitions. # ignore the transaction if not challenge_mgr.in_competition(transaction_date): return # Create a transaction first. transaction = PointsTransaction( user=profile.user, points=points, transaction_date=transaction_date, message=message, ) if related_object: transaction.related_object = related_object transaction.save() # update the scoreboard entry _update_scoreboard_entry(profile, points, transaction_date) # Invalidate info bar cache. cache_mgr.invalidate_template_cache("RIB", profile.user.username)
def check_competition_period(self, request): """Checks if we are still in the competition. If the user is logged in, they are redirected to a competition status page. """ staff_user = self.is_staff(request) if not staff_user and \ not challenge_mgr.in_competition(): return HttpResponseRedirect(reverse("home_restricted")) return None
def check_competition_period(self, request): """Checks if we are still in the competition. If the user is logged in, they are redirected to a competition status page. """ staff_user = request.user.is_staff or request.session.get('staff', False) if not staff_user and \ not challenge_mgr.in_competition(): return HttpResponseRedirect(reverse("home_restricted")) return None
def restricted(request): """The view when they have logged in before the competition begins.""" # If we are in the competition, bring them back to the home page. if challenge_mgr.in_competition(): return HttpResponseRedirect(reverse('home_index')) rounds_info = challenge_mgr.get_all_round_info() start = rounds_info["competition_start"] end = rounds_info["competition_end"] return render_to_response("widgets/home/templates/restricted.html", { "before": datetime.datetime.today() < start, "start": start, "end": end, }, context_instance=RequestContext(request))
def notify_round_started(): """Notify the user of a start of a round.""" if not challenge_mgr.in_competition(): return today = datetime.datetime.today() current_round = None previous_round = None all_round_info = challenge_mgr.get_all_round_info() rounds = all_round_info["rounds"] for key in rounds.keys(): # We're looking for a round that ends today and another that starts # today (or overall) start = rounds[key]["start"] end = rounds[key]["end"] # Check yesterday's round and check for the current round. if start < (today - datetime.timedelta(days=1)) < end: previous_round = key if start < today < end: current_round = key print 'Previous Round: %s' % previous_round print 'Current Round: %s' % current_round if current_round and previous_round and current_round != previous_round: # only carry over the scoreboard entry if the round don't need to be reset if not rounds[current_round]["round_reset"]: print "carry over scoreboard entry to new round." score_mgr.copy_scoreboard_entry(previous_round, current_round) # if there is a gap, previous_round is null, check if it is not out of round if current_round and current_round != previous_round and\ all_round_info["competition_start"] <= today <= all_round_info["competition_end"]: print 'Sending out round transition notices.' template = NoticeTemplate.objects.get(notice_type="round-transition") message = template.render({ "PREVIOUS_ROUND": previous_round, "CURRENT_ROUND": current_round, }) for user in User.objects.all(): UserNotification.create_info_notification( user, message, display_alert=True, )
def notify_round_started(): """Notify the user of a start of a round.""" if not challenge_mgr.in_competition(): return today = datetime.datetime.today() current_round = None previous_round = None all_round_info = challenge_mgr.get_all_round_info() rounds = all_round_info["rounds"] for key in rounds.keys(): # We're looking for a round that ends today and another that starts # today (or overall) start = rounds[key]["start"] end = rounds[key]["end"] # Check yesterday's round and check for the current round. if start < (today - datetime.timedelta(days=1)) < end: previous_round = key if start < today < end: current_round = key print 'Previous Round: %s' % previous_round print 'Current Round: %s' % current_round if current_round and previous_round and current_round != previous_round: # only carry over the scoreboard entry if the round don't need to be reset if not rounds[current_round]["round_reset"]: print "carry over scoreboard entry to new round." score_mgr.copy_scoreboard_entry(previous_round, current_round) # if there is a gap, previous_round is null, check if it is not out of round if current_round and current_round != previous_round and\ all_round_info["competition_start"] <= today <= all_round_info["competition_end"]: print 'Sending out round transition notices.' template = NoticeTemplate.objects.get(notice_type="round-transition") message = template.render({"PREVIOUS_ROUND": previous_round, "CURRENT_ROUND": current_round, }) for user in User.objects.all(): UserNotification.create_info_notification(user, message, display_alert=True,)
def restricted(request): """The view when they have logged in before the competition begins.""" # If we are in the competition, bring them back to the home page. if challenge_mgr.in_competition(): return HttpResponseRedirect(reverse('home_index')) rounds_info = challenge_mgr.get_all_round_info() today = datetime.datetime.today() start = rounds_info["competition_start"] before = today < start end = today > rounds_info["competition_end"] if not before: next_round = challenge_mgr.get_next_round_info() if next_round: start = next_round["start"] return render_to_response("widgets/home/templates/restricted.html", { "before": before, "start": start, "end": end, }, context_instance=RequestContext(request))