本文整理汇总了Python中apps.widgets.smartgrid.models.ActionMember.save方法的典型用法代码示例。如果您正苦于以下问题:Python ActionMember.save方法的具体用法?Python ActionMember.save怎么用?Python ActionMember.save使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类apps.widgets.smartgrid.models.ActionMember
的用法示例。
在下文中一共展示了ActionMember.save方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: testDeleteRemovesPoints
# 需要导入模块: from apps.widgets.smartgrid.models import ActionMember [as 别名]
# 或者: from apps.widgets.smartgrid.models.ActionMember import save [as 别名]
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)
示例2: testCommitmentAchievement
# 需要导入模块: from apps.widgets.smartgrid.models import ActionMember [as 别名]
# 或者: from apps.widgets.smartgrid.models.ActionMember import save [as 别名]
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")
示例3: testCompletionAddsPoints
# 需要导入模块: from apps.widgets.smartgrid.models import ActionMember [as 别名]
# 或者: from apps.widgets.smartgrid.models.ActionMember import save [as 别名]
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))
示例4: testApproveAddsPoints
# 需要导入模块: from apps.widgets.smartgrid.models import ActionMember [as 别名]
# 或者: from apps.widgets.smartgrid.models.ActionMember import save [as 别名]
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))
示例5: testPopularActivities
# 需要导入模块: from apps.widgets.smartgrid.models import ActionMember [as 别名]
# 或者: from apps.widgets.smartgrid.models.ActionMember import save [as 别名]
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)
示例6: testCompletedActivity
# 需要导入模块: from apps.widgets.smartgrid.models import ActionMember [as 别名]
# 或者: from apps.widgets.smartgrid.models.ActionMember import save [as 别名]
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.")
示例7: testActivityLog
# 需要导入模块: from apps.widgets.smartgrid.models import ActionMember [as 别名]
# 或者: from apps.widgets.smartgrid.models.ActionMember import save [as 别名]
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()))
示例8: testPopularCommitments
# 需要导入模块: from apps.widgets.smartgrid.models import ActionMember [as 别名]
# 或者: from apps.widgets.smartgrid.models.ActionMember import save [as 别名]
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.")
示例9: testHasCommitment
# 需要导入模块: from apps.widgets.smartgrid.models import ActionMember [as 别名]
# 或者: from apps.widgets.smartgrid.models.ActionMember import save [as 别名]
def testHasCommitment(self):
"""Tests that has_action works for a commitment in progress."""
commitment = Commitment(
title="Test commitment",
type="commitment",
name="Test",
slug="test-commitment",
description="A commitment!",
point_value=10,
)
commitment.save()
# Test as an unlock condition.
self.quest.unlock_conditions = "submitted_action(slug='test-commitment')"
self.quest.save()
self.assertTrue(self.quest not in get_quests(self.user),
"User should not be able to participate in this quest.")
member = ActionMember(user=self.user, action=commitment)
member.save()
self.assertTrue(submitted_action(self.user, slug='test-commitment'),
"User should have a commitment in progress.")
self.assertTrue(submitted_some_of(self.user, action_type="commitment"),
"User should have a commitment in progress.")
self.assertTrue(self.quest in get_quests(self.user)["available_quests"],
"User should be able to participate in this quest.")
self.quest.unlock_conditions = "submitted_some_of(action_type='commitment')"
self.quest.save()
self.assertTrue(self.quest in get_quests(self.user)["available_quests"],
"User should be able to participate in this quest.")
member.award_date = datetime.datetime.today()
member.save()
self.assertTrue(submitted_action(self.user, slug='test-commitment'),
"User should have a completed commitment.")
self.assertTrue(submitted_some_of(self.user, action_type="commitment"),
"User should have a completed commitment.")
# Test as a completion condition
self.quest.accept(self.user)
self.quest.completion_conditions = "not submitted_action(slug='test-commitment')"
self.quest.save()
self.assertTrue(self.quest not in possibly_completed_quests(self.user),
"User should not be able to complete this quest.")
self.quest.completion_conditions = "not submitted_some_of(action_type='commitment')"
self.quest.save()
self.assertTrue(self.quest not in possibly_completed_quests(self.user),
"User should not be able to complete this quest.")
self.quest.completion_conditions = "submitted_action(slug='test-commitment')"
self.quest.save()
self.assertTrue(self.quest in possibly_completed_quests(self.user),
"User should be able to complete this quest.")
示例10: complete_setup_activity
# 需要导入模块: from apps.widgets.smartgrid.models import ActionMember [as 别名]
# 或者: from apps.widgets.smartgrid.models.ActionMember import save [as 别名]
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()
示例11: complete
# 需要导入模块: from apps.widgets.smartgrid.models import ActionMember [as 别名]
# 或者: from apps.widgets.smartgrid.models.ActionMember import save [as 别名]
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,)))
示例12: signup
# 需要导入模块: from apps.widgets.smartgrid.models import ActionMember [as 别名]
# 或者: from apps.widgets.smartgrid.models.ActionMember import save [as 别名]
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
示例13: testActivityAchievement
# 需要导入模块: from apps.widgets.smartgrid.models import ActionMember [as 别名]
# 或者: from apps.widgets.smartgrid.models.ActionMember import save [as 别名]
def testActivityAchievement(self):
"""Check that the user's activity achievements are loaded."""
activity = Activity(
title="Test activity",
slug="test-activity",
description="Testing!",
duration=10,
point_value=10,
pub_date=datetime.datetime.today(),
expire_date=datetime.datetime.today() + datetime.timedelta(days=7),
confirm_type="text",
type="activity",
is_canopy=False
)
activity.save()
# Test that profile page has a pending activity.
member = ActionMember(user=self.user,
action=activity,
approval_status="approved")
member.save()
response = self.client.get(reverse("profile_index"))
self.assertContains(response,
reverse("activity_task", args=(activity.type, activity.slug,)))
self.assertContains(response, "Test activity")
# Test adding an event to catch a bug.
event = Event(
title="Test event",
slug="test-event",
description="Testing!",
duration=10,
point_value=10,
pub_date=datetime.datetime.today(),
expire_date=datetime.datetime.today() + datetime.timedelta(days=7),
type="event",
)
event.save()
member = ActionMember(user=self.user, action=event, approval_status="pending")
member.save()
response = self.client.get(reverse("profile_index"))
self.assertContains(response,
reverse("activity_task", args=(activity.type, activity.slug,)))
self.assertContains(response, "Pending")
self.assertContains(response, "Activity:")
self.assertContains(response, "Event:")
self.assertNotContains(response, "You have nothing in progress or pending.")
示例14: testNumTasksCompletedWithType
# 需要导入模块: from apps.widgets.smartgrid.models import ActionMember [as 别名]
# 或者: from apps.widgets.smartgrid.models.ActionMember import save [as 别名]
def testNumTasksCompletedWithType(self):
"""test task completed."""
activity = Activity(
type="activity",
name="Test",
slug="test",
title="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 activities
member = ActionMember(user=self.user, action=activity, approval_status="pending")
member.save()
self.assertFalse(approved_some_of(self.user, 1, action_type="activity"),
"User with pending activity should not have completed a task.")
# Test within context of a quest
self.quest.unlock_conditions = "approved_some_of(1, action_type='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.")
# Check that the user can now add the quest.
member.approval_status = "approved"
member.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 = "approved_some_of(2, 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_some_of(1, action_type='activity')"
self.quest.save()
completed_quests = possibly_completed_quests(self.user)
self.assertTrue(self.quest in completed_quests, "User should have completed the quest.")
示例15: testRejectionNotifications
# 需要导入模块: from apps.widgets.smartgrid.models import ActionMember [as 别名]
# 或者: from apps.widgets.smartgrid.models.ActionMember import save [as 别名]
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.")