本文整理汇总了Python中apps.widgets.smartgrid.models.ActionMember类的典型用法代码示例。如果您正苦于以下问题:Python ActionMember类的具体用法?Python ActionMember怎么用?Python ActionMember使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ActionMember类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: testPopularActivities
def testPopularActivities(self):
"""Check which activity is the most popular."""
activity_member = ActionMember(user=self.user, action=self.activity)
activity_member.approval_status = "approved"
activity_member.save()
activities = smartgrid.get_popular_actions("activity", "approved")
self.assertEqual(activities[0].title, self.activity.title)
示例2: testCompletedActivity
def testCompletedActivity(self):
"""Tests that approved_action works when a task is completed."""
activity = Activity(
type="activity",
name="Test",
title="Test activity",
slug="test-activity",
description="Variable points!",
expected_duration=10,
point_value=10,
pub_date=datetime.datetime.today(),
expire_date=datetime.datetime.today() + datetime.timedelta(days=7),
confirm_type="text",
)
activity.save()
# Test within context of a quest
self.quest.unlock_conditions = "approved_action(slug='test-activity')"
self.quest.save()
quests = get_quests(self.user)
self.assertTrue(self.quest not in quests,
"User should not be able to participate in this quest.")
member = ActionMember(user=self.user, action=activity, approval_status="approved")
member.save()
self.assertTrue(approved_action(self.user, slug="test-activity"),
"User should have completed 'Test'.")
self.assertTrue(approved_some_of(self.user, action_type="activity"),
"User should have completed an activity")
quests = get_quests(self.user)
self.assertTrue(self.quest in quests["available_quests"],
"User should be able to participate in this quest.")
self.quest.unlock_conditions = "approved_some_of(action_type='activity')"
self.quest.save()
quests = get_quests(self.user)
self.assertTrue(self.quest in quests["available_quests"],
"User should be able to participate in this quest.")
# Test as a completion condition.
self.quest.accept(self.user)
self.quest.completion_conditions = "not approved_action(slug='test-activity')"
self.quest.save()
completed_quests = possibly_completed_quests(self.user)
self.assertTrue(self.quest not in completed_quests,
"User should not be able to complete the quest.")
self.quest.completion_conditions = "not approved_some_of(action_type='activity')"
self.quest.save()
completed_quests = possibly_completed_quests(self.user)
self.assertTrue(self.quest not in completed_quests,
"User should not be able to complete the quest.")
self.quest.completion_conditions = "approved_action(slug='test-activity')"
self.quest.save()
completed_quests = possibly_completed_quests(self.user)
self.assertTrue(self.quest in completed_quests, "User should have completed the quest.")
示例3: testActivityLog
def testActivityLog(self):
"""
Test that regular activities create the appropriate log.
"""
member = ActionMember(user=self.user, action=self.activity, approval_status='approved')
member.save()
# Check the points log for this user.
log = self.user.pointstransaction_set.all()[0]
self.assertTrue(log.message.startswith(self.activity.type.capitalize()))
示例4: testPopularCommitments
def testPopularCommitments(self):
"""Tests that we can retrieve the most popular commitments."""
commitment_member = ActionMember(user=self.user, action=self.commitment)
commitment_member.award_date = datetime.datetime.today()
commitment_member.approval_status = "approved"
commitment_member.save()
commitments = smartgrid.get_popular_actions("commitment", "approved")
self.assertEqual(commitments[0].title, self.commitment.title)
self.assertEqual(commitments[0].completions, 1, "Most popular commitment should have one completion.")
示例5: testDeleteRemovesPoints
def testDeleteRemovesPoints(self):
"""Test that deleting a commitment member after it is completed removes the user's
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()
commitment_member.award_date = datetime.datetime.today()
commitment_member.approval_status = "approved"
commitment_member.save()
award_date = commitment_member.award_date
commitment_member.delete()
# Verify nothing has changed.
profile = self.user.profile
self.assertTrue(
profile.last_awarded_submission() is None or
profile.last_awarded_submission() < award_date)
self.assertEqual(points, profile.points())
entry = self.user.profile.scoreboardentry_set.get(round_name=self.current_round)
self.assertEqual(round_points, entry.points)
self.assertTrue(
entry.last_awarded_submission is None or entry.last_awarded_submission < award_date)
示例6: complete_setup_activity
def complete_setup_activity(user):
"""complete the setup activity."""
# error out if we can't find to the activity.
activity = get_setup_activity()
members = ActionMember.objects.filter(user=user, action=activity)
if not members:
# if points not awarded, do so.
member = ActionMember(action=activity, user=user)
member.approval_status = "approved"
member.save()
示例7: complete
def complete(request, event):
"""complete the event and try to claim point."""
user = request.user
if request.method == "POST":
form = ActivityCodeForm(request.POST, request=request, action=event)
if form.is_valid():
# Approve the activity (confirmation code is validated in
# forms.ActivityTextForm.clean())
code = ConfirmationCode.objects.get(code=form.cleaned_data["response"].lower())
code.is_active = False
code.user = user
code.save()
try:
action_member = ActionMember.objects.get(user=user, action=event)
except ObjectDoesNotExist:
action_member = ActionMember(user=user, action=event)
action_member.approval_status = "approved"
value = event.point_value
action_member.social_email = form.cleaned_data["social_email"].lower()
try:
action_member.save()
except IntegrityError:
messages.error = 'Sorry, but it appears that you have already added this activity.'
return HttpResponseRedirect(
reverse("activity_task", args=(event.type, event.slug,)))
response = HttpResponseRedirect(
reverse("activity_task", args=(event.type, event.slug,)))
if value:
notification = "You just earned " + str(value) + " points."
response.set_cookie("task_notify", notification)
return response
# invalid form
# rebuild the form
form.form_title = "Get your points"
return render_to_response("task.html", {
"action": event,
"form": form,
"completed_count": 0,
"team_members": None,
"display_form": True,
"reminders": None,
}, context_instance=RequestContext(request))
return HttpResponseRedirect(reverse("activity_task", args=(event.type, event.slug,)))
示例8: signup
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
示例9: testRejectionNotifications
def testRejectionNotifications(self):
"""
Test that notifications are created by rejections and
are marked as read when the member changes back to pending.
"""
notifications = UserNotification.objects.count()
activity_member = ActionMember(user=self.user, action=self.activity,
submission_date=datetime.datetime.today())
activity_member.approval_status = "rejected"
activity_member.submission_date = datetime.datetime.today()
activity_member.save()
self.assertEqual(UserNotification.objects.count(), notifications + 1,
"New notification should have been created.")
notice = activity_member.notifications.all()[0]
self.assertTrue(notice.unread, "Notification should be unread.")
示例10: testCompletionAddsPoints
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))
示例11: testRejectedActivity
def testRejectedActivity(self):
"""
Test that a rejected activity submission posts a message.
"""
activity = test_utils.create_activity()
member = ActionMember(
action=activity,
user=self.user,
approval_status="rejected",
submission_date=datetime.datetime.today(),
)
member.save()
response = self.client.get(reverse("learn_index"))
self.assertContains(response, 'Your response to <a href="%s' % (
reverse("activity_task", args=(activity.type, activity.slug,)),
))
response = self.client.get(reverse("learn_index"))
self.assertNotContains(response, "notification-box")
示例12: signup
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,)))
示例13: testVariablePointAchievement
def testVariablePointAchievement(self):
"""Test that a variable point activity appears correctly in the my achievements list."""
activity = Activity(
title="Test activity",
slug="test-activity",
description="Variable points!",
duration=10,
point_range_start=5,
point_range_end=314160,
pub_date=datetime.datetime.today(),
expire_date=datetime.datetime.today() + datetime.timedelta(days=7),
confirm_type="text",
type="activity",
)
activity.save()
points = self.user.get_profile().points()
member = ActionMember(
user=self.user,
action=activity,
approval_status="approved",
)
member.points_awarded = 314159
member.save()
self.assertEqual(self.user.get_profile().points(), points + 314159,
"Variable number of points should have been awarded.")
# Kludge to change point value for the info bar.
profile = self.user.get_profile()
profile.add_points(3, datetime.datetime.today(), "test")
profile.save()
response = self.client.get(reverse("profile_index"))
self.assertContains(response,
reverse("activity_task", args=(activity.type, activity.slug,)))
# Note, this test may break if something in the page has the value 314159.
# Try finding another suitable number.
# print response.content
self.assertContains(response, "314159", count=5,
msg_prefix="314159 points should appear for the activity.")
示例14: testCommitmentAchievement
def testCommitmentAchievement(self):
"""Check that the user's commitment achievements are loaded."""
commitment = Commitment(
title="Test commitment",
description="A commitment!",
point_value=10,
type="commitment",
slug="test-commitment",
)
commitment.save()
# Test that profile page has a pending activity.
member = ActionMember(user=self.user, action=commitment)
member.save()
response = self.client.get(reverse("profile_index"))
self.assertContains(response,
reverse("activity_task", args=(commitment.type, commitment.slug,)))
self.assertContains(response, "In Progress")
self.assertContains(response, "Commitment:")
self.assertNotContains(response, "You have nothing in progress or pending.")
# Test that the profile page has a rejected activity
member.award_date = datetime.datetime.today()
member.save()
response = self.client.get(reverse("profile_index"))
self.assertContains(response,
reverse("activity_task", args=(commitment.type, commitment.slug,)))
self.assertNotContains(response, "You have not been awarded anything yet!")
self.assertNotContains(response, "In Progress")
示例15: testApproveAddsPoints
def testApproveAddsPoints(self):
"""Test for verifying that approving a user awards them 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
round_last_awarded = entry.last_awarded_submission
activity_points = self.activity.point_value
activity_member = ActionMember(user=self.user, action=self.activity)
activity_member.save()
# Verify that nothing has changed.
self.assertEqual(points, self.user.profile.points())
entry = self.user.profile.scoreboardentry_set.get(round_name=self.current_round)
self.assertEqual(round_points, entry.points)
self.assertEqual(round_last_awarded, entry.last_awarded_submission)
activity_member.approval_status = "approved"
activity_member.save()
# Verify overall score changed.
new_points = self.user.profile.points()
self.assertEqual(new_points - points, activity_points)
# Verify round score changed.
entry = self.user.profile.scoreboardentry_set.get(round_name=self.current_round)
self.assertEqual(round_points + activity_points, entry.points)
self.assertTrue(abs(
activity_member.submission_date - entry.last_awarded_submission) < datetime.timedelta(
minutes=1))