def testCompletionAddsPoints(self): """Tests that completing a task adds points.""" points = self.user.profile.points() # Setup to check round points. (entry, _) = self.user.profile.scoreboardentry_set.get_or_create( round_name=self.current_round) round_points = entry.points commitment_member = ActionMember(user=self.user, action=self.commitment, completion_date=datetime.datetime.today()) commitment_member.save() # Check that the user's signup point. self.assertEqual(points + score_mgr.signup_points(), self.user.profile.points()) entry = self.user.profile.scoreboardentry_set.get(round_name=self.current_round) self.assertEqual(round_points + score_mgr.signup_points(), entry.points) commitment_member.award_date = datetime.datetime.today() commitment_member.approval_status = "approved" commitment_member.save() points += commitment_member.action.commitment.point_value self.assertEqual(points + score_mgr.signup_points(), self.user.profile.points()) self.assertEqual(self.user.profile.last_awarded_submission(), commitment_member.award_date) entry = self.user.profile.scoreboardentry_set.get(round_name=self.current_round) round_points += commitment_member.action.commitment.point_value self.assertEqual(round_points + score_mgr.signup_points(), entry.points) self.assertTrue( abs(entry.last_awarded_submission - commitment_member.award_date) < datetime.timedelta( minutes=1))
def testCompletionAddsPoints(self): """Tests that completing a task adds points.""" points = self.user.get_profile().points() # Setup to check round points. (entry, _) = self.user.get_profile().scoreboardentry_set.get_or_create( round_name=self.current_round) round_points = entry.points commitment_member = ActionMember(user=self.user, action=self.commitment, completion_date=datetime.datetime.today()) commitment_member.save() # Check that the user's signup point. self.assertEqual(points + score_mgr.signup_points(), self.user.get_profile().points()) entry = self.user.get_profile().scoreboardentry_set.get(round_name=self.current_round) self.assertEqual(round_points + score_mgr.signup_points(), entry.points) commitment_member.award_date = datetime.datetime.today() commitment_member.approval_status = "approved" commitment_member.save() points += commitment_member.action.commitment.point_value self.assertEqual(points + score_mgr.signup_points(), self.user.get_profile().points()) self.assertEqual(self.user.get_profile().last_awarded_submission(), commitment_member.award_date) entry = self.user.get_profile().scoreboardentry_set.get(round_name=self.current_round) round_points += commitment_member.action.commitment.point_value self.assertEqual(round_points + score_mgr.signup_points(), entry.points) self.assertTrue( abs(entry.last_awarded_submission - commitment_member.award_date) < datetime.timedelta( minutes=1))
def drop_action(request, action_type, slug): """Handles the play tester dropping the given action defined by the action_type and slug.""" draft = _get_current_draft(request) action = smartgrid_mgr.get_designer_action(draft=draft, slug=slug) _ = action_type user = request.user try: member = user.testeractionsubmittion_set.get(action=action, approval_status="pending") member.delete() response = HttpResponseRedirect( reverse("tester_view_action", args=( action.type, action.slug, ))) value = score_mgr.signup_points() notification = "%s dropped. you lose %d points." % (action.type, value) response.set_cookie("task_notify", notification) return response except ObjectDoesNotExist: pass messages.error = 'It appears that you are not participating in this action.' # Take them back to the action page. return HttpResponseRedirect( reverse("tester_view_action", args=( action.type, action.slug, )))
def _award_possible_reverse_penalty_points(self): """ reverse event/excursion noshow penalty.""" if self._has_noshow_penalty(): message = "%s (Reverse No Show Penalty)" % self.action self.user.get_profile().add_points( score_mgr.noshow_penalty_points() + score_mgr.signup_points(), self.award_date, message, self )
def drop_action(request, action_type, slug): """Handle the drop task request.""" _ = action_type action = smartgrid.get_action(slug=slug) user = request.user try: member = user.actionmember_set.get(action=action, approval_status="pending") member.delete() response = HttpResponseRedirect( reverse("activity_task", args=( action.type, action.slug, ))) value = score_mgr.signup_points() notification = "%s dropped. you lose %d points." % (action.type, value) response.set_cookie("task_notify", notification) return response except ObjectDoesNotExist: pass messages.error = 'It appears that you are not participating in this action.' # Take them back to the action page. return HttpResponseRedirect( reverse("activity_task", args=( action.type, action.slug, )))
def _drop_signup_points(self): """award the sign up point for commitment and event.""" if self.action.type != "activity": # increase the point from signup message = "%s (Drop Sign up)" % self.action self.user.get_profile().remove_points(score_mgr.signup_points(), self.submission_date, message, self)
def _award_possible_reverse_penalty_points(self): """ reverse event noshow penalty.""" if self._has_noshow_penalty(): message = "%s (Reverse No Show Penalty)" % self.action self.user.profile.add_points( score_mgr.noshow_penalty_points() + score_mgr.signup_points(), self.award_date, message, self)
def _award_signup_points(self): """award the sign up point for commitment and event.""" if self.action.type != "activity": #increase the point from signup message = "%s (Sign up)" % self.action self.user.profile.add_points(score_mgr.signup_points(), self.submission_date, message, self)
def _drop_signup_points(self): """award the sign up point for commitment and event.""" if self.action.type != "activity": #increase the point from signup message = "%s (Drop Sign up)" % self.action self.user.get_profile().remove_points(score_mgr.signup_points(), self.submission_date, message, self)
def signup(request, event): """Commit the current user to the activity.""" user = request.user action_member = ActionMember(user=user, action=event) action_member.save() response = HttpResponseRedirect( reverse("activity_task", args=(event.type, event.slug,))) value = score_mgr.signup_points() notification = "You just earned " + str(value) + " points." response.set_cookie("task_notify", notification) return response
def signup(request, event): """Commit the current user to the activity.""" user = request.user value = None # Search for an existing activity for this user if event not in user.action_set.all(): action_member = ActionMember(user=user, action=event) action_member.save() response = HttpResponseRedirect( reverse("activity_task", args=(event.type, event.slug,))) value = score_mgr.signup_points() notification = "You just earned " + str(value) + " points." response.set_cookie("task_notify", notification) return response # adding to the existing activity results in redirecting to the task page return HttpResponseRedirect(reverse("activity_task", args=(event.type, event.slug,)))
def drop_action(request, action_type, slug): """Handles the play tester dropping the given action defined by the action_type and slug.""" draft = _get_current_draft(request) action = smartgrid_mgr.get_designer_action(draft=draft, slug=slug) _ = action_type user = request.user try: member = user.testeractionsubmittion_set.get(action=action, approval_status="pending") member.delete() response = HttpResponseRedirect( reverse("tester_view_action", args=(action.type, action.slug,))) value = score_mgr.signup_points() notification = "%s dropped. you lose %d points." % (action.type, value) response.set_cookie("task_notify", notification) return response except ObjectDoesNotExist: pass messages.error = 'It appears that you are not participating in this action.' # Take them back to the action page. return HttpResponseRedirect(reverse("tester_view_action", args=(action.type, action.slug,)))
def drop_action(request, action_type, slug): """Handle the drop task request.""" _ = action_type action = smartgrid.get_action(slug=slug) user = request.user try: member = user.actionmember_set.get(action=action, approval_status="pending") member.delete() response = HttpResponseRedirect( reverse("activity_task", args=(action.type, action.slug,))) value = score_mgr.signup_points() notification = "%s dropped. you lose %d points." % (action.type, value) response.set_cookie("task_notify", notification) return response except ObjectDoesNotExist: pass messages.error = 'It appears that you are not participating in this action.' # Take them back to the action page. return HttpResponseRedirect(reverse("activity_task", args=(action.type, action.slug,)))
def add(request, commitment): """Commit the current user to the commitment.""" user = request.user draft = commitment.draft value = None if request.method == "GET": # redirect to task page, only allow POST return HttpResponseRedirect( reverse("tester_view_action", args=(commitment.type, commitment.slug,))) form = TestCommitmentCommentForm(request.POST, user=request.user.username) if not form.is_valid(): # invalid form request.session['form'] = form return HttpResponseRedirect( reverse("tester_view_action", args=(commitment.type, commitment.slug,)) + "?display_form=True") # now we have a valid form if play_tester.can_complete_commitment(user, commitment): try: member = user.actionmember_set.get(action=commitment, award_date=None) except ObjectDoesNotExist: # ignore the race condition return HttpResponseRedirect( reverse("tester_view_action", args=(commitment.type, commitment.slug,))) #commitment end, award full point member.award_date = datetime.datetime.today() member.approval_status = "approved" if form.cleaned_data["social_email"]: member.social_email = form.cleaned_data["social_email"].lower() member.save() value = commitment.point_value elif play_tester.can_add_commitment(user): # User can commit to this commitment. allow to commit to completed commitment again # as long as the pending does not reach max member = TesterActionSubmittion(user=user, action=commitment, draft=draft) if form: member.social_email = form.cleaned_data["social_email"].lower() try: member.save() value = score_mgr.signup_points() except IntegrityError: messages.error = 'Sorry, but it appears that you are already participating in ' \ 'this commitment.' return HttpResponseRedirect( reverse("tester_view_action", args=(commitment.type, commitment.slug,))) else: # user can not add more than 5 commitment return HttpResponseRedirect( reverse("tester_view_action", args=(commitment.type, commitment.slug,))) response = HttpResponseRedirect( reverse("tester_view_action", args=(commitment.type, commitment.slug,))) notification = "You just earned " + str(value) + " points." response.set_cookie("task_notify", notification) return response
def process_rsvp(): """Process RSVP notification and penalty""" noshow_penalty_points = score_mgr.noshow_penalty_points() signup_points = score_mgr.signup_points() members = ActionMember.objects.filter( Q(action__type="event") | Q(action__type="excursion"), approval_status="pending") # try and load the notification template. template_noshow = None try: template_noshow = NoticeTemplate.objects.get( notice_type="event-noshow-penalty") except NoticeTemplate.DoesNotExist: pass template_reminder = None try: template_reminder = NoticeTemplate.objects.get( notice_type="event-post-reminder") except NoticeTemplate.DoesNotExist: pass for member in members: action = member.action user = member.user profile = user.get_profile() diff = datetime.date.today() - action.event.event_date.date() if diff.days == NOSHOW_PENALTY_DAYS: # send out notification to remind the penalty if template_reminder: message = template_reminder.render({"ACTIVITY": action}) else: message = "Hi %s, <p/> We just wanted to remind you that the "\ "%s <a href='http://%s%s'>%s</a> had ended. Please "\ "click on the link to claim your points." % ( profile.name, action.type.capitalize(), challenge_mgr.get_challenge().domain, reverse("activity_task", args=(action.type, action.slug,)), action.title) message += "<p/>Because you signed up for the "\ "event, if you do not enter the "\ "confirmation code within %d days after the "\ "event, a total of %d points (%d point "\ "signup bonus plus %d point no-show penalty) will "\ "be deducted from your total points. So please "\ "enter your confirmation code early to avoid the "\ "penalty." % ( NOSHOW_PENALTY_DAYS, noshow_penalty_points + signup_points, noshow_penalty_points, signup_points, ) message += "<p/><p/>Kukui Cup Administrators" subject = "[Kukui Cup] Reminder to enter your event confirmation code" UserNotification.create_email_notification(user.email, subject, message, message) print "sent post event email reminder to %s for %s" % ( profile.name, action.title) elif diff.days == (NOSHOW_PENALTY_DAYS + 1): # the day after the penalty day, process the penalty reduction message = "%s: %s (No Show)" % (action.type.capitalize(), action.title) profile.remove_points(noshow_penalty_points + signup_points, datetime.datetime.today() - datetime.timedelta(minutes=1), message, member) print "removed noshow penalty points from %s for '%s'" % (profile.name, message) if template_noshow: message = template_noshow.render({"ACTIVITY": action}) else: message = "%d points had been deducted from you, "\ "because you signed up but did not enter the "\ "confirmation code %d days after the %s <a "\ "href='%s'>%s</a>, " % ( noshow_penalty_points + signup_points, NOSHOW_PENALTY_DAYS, action.type.capitalize(), reverse("activity_task", args=(action.type, action.slug,)), action.title) message += " If you did attend, please click on the link to "\ "claim your points and reverse the deduction." UserNotification.create_info_notification(user, message, display_alert=True, content_object=member) print "created no-show penalty notification for %s for %s" % ( profile.name, action.title)
def add(request, commitment): """Commit the current user to the commitment.""" user = request.user value = None if request.method == "GET": # redirect to task page, only allow POST return HttpResponseRedirect( reverse("activity_task", args=( commitment.type, commitment.slug, ))) form = CommitmentCommentForm(request.POST, user=request.user.username) if not form.is_valid(): # invalid form request.session["form_dict"] = form.data request.session["form_errors"] = form.errors return HttpResponseRedirect( reverse("activity_task", args=( commitment.type, commitment.slug, )) + "?display_form=True") # now we have a valid form if smartgrid.can_complete_commitment(user, commitment): try: member = user.actionmember_set.get(action=commitment, award_date=None) except ObjectDoesNotExist: # ignore the race condition return HttpResponseRedirect( reverse("activity_task", args=( commitment.type, commitment.slug, ))) #commitment end, award full point member.award_date = datetime.datetime.today() member.approval_status = "approved" if form.cleaned_data["social_email"]: member.social_email = form.cleaned_data["social_email"].lower() member.save() value = commitment.point_value elif smartgrid.can_add_commitment(user): # User can commit to this commitment. allow to commit to completed commitment again # as long as the pending does not reach max member = ActionMember(user=user, action=commitment) if form: member.social_email = form.cleaned_data["social_email"].lower() try: member.save() value = score_mgr.signup_points() except IntegrityError: messages.error = 'Sorry, but it appears that you are already participating in ' \ 'this commitment.' return HttpResponseRedirect( reverse("activity_task", args=( commitment.type, commitment.slug, ))) else: # user can not add more than 5 commitment return HttpResponseRedirect( reverse("activity_task", args=( commitment.type, commitment.slug, ))) response = HttpResponseRedirect( reverse("activity_task", args=( commitment.type, commitment.slug, ))) notification = "You just earned " + str(value) + " points." response.set_cookie("task_notify", notification) return response
def process_rsvp(): """Process RSVP notification and penalty""" noshow_penalty_points = score_mgr.noshow_penalty_points() signup_points = score_mgr.signup_points() members = ActionMember.objects.filter(Q(action__type="event") | Q(action__type="excursion"), approval_status="pending") # try and load the notification template. template_noshow = None try: template_noshow = NoticeTemplate.objects.get( notice_type="event-noshow-penalty") except NoticeTemplate.DoesNotExist: pass template_reminder = None try: template_reminder = NoticeTemplate.objects.get( notice_type="event-post-reminder") except NoticeTemplate.DoesNotExist: pass for member in members: action = member.action user = member.user profile = user.profile diff = datetime.date.today() - action.event.event_date.date() if diff.days == NOSHOW_PENALTY_DAYS: # send out notification to remind the penalty if template_reminder: message = template_reminder.render({"ACTIVITY": action}) else: message = "Hi %s, <p/> We just wanted to remind you that the "\ "%s <a href='http://%s%s'>%s</a> had ended. Please "\ "click on the link to claim your points." % ( profile.name, action.type.capitalize(), challenge_mgr.get_challenge().domain, reverse("activity_task", args=(action.type, action.slug,)), action.title) message += "<p/>Because you signed up for the "\ "event, if you do not enter the "\ "confirmation code within %d days after the "\ "event, a total of %d points (%d point "\ "signup bonus plus %d point no-show penalty) will "\ "be deducted from your total points. So please "\ "enter your confirmation code early to avoid the "\ "penalty." % ( NOSHOW_PENALTY_DAYS, noshow_penalty_points + signup_points, noshow_penalty_points, signup_points, ) message += "<p/><p/>Kukui Cup Administrators" subject = "[Kukui Cup] Reminder to enter your event confirmation code" UserNotification.create_email_notification(user.email, subject, message, message) print "sent post event email reminder to %s for %s" % ( profile.name, action.title) elif diff.days == (NOSHOW_PENALTY_DAYS + 1): # the day after the penalty day, process the penalty reduction message = "%s: %s (No Show)" % (action.type.capitalize(), action.title) profile.remove_points( noshow_penalty_points + signup_points, datetime.datetime.today() - datetime.timedelta(minutes=1), message, member) print "removed noshow penalty points from %s for '%s'" % ( profile.name, message) if template_noshow: message = template_noshow.render({"ACTIVITY": action}) else: message = "%d points had been deducted from you, "\ "because you signed up but did not enter the "\ "confirmation code %d days after the %s <a "\ "href='%s'>%s</a>, " % ( noshow_penalty_points + signup_points, NOSHOW_PENALTY_DAYS, action.type.capitalize(), reverse("activity_task", args=(action.type, action.slug,)), action.title) message += " If you did attend, please click on the link to "\ "claim your points and reverse the deduction." UserNotification.create_info_notification(user, message, display_alert=True, content_object=member) print "created no-show penalty notification for %s for %s" % ( profile.name, action.title)