本文整理汇总了Python中taiga.projects.votes.services.add_vote函数的典型用法代码示例。如果您正苦于以下问题:Python add_vote函数的具体用法?Python add_vote怎么用?Python add_vote使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了add_vote函数的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: upvote
def upvote(self, request, pk=None):
obj = self.get_object()
self.check_permissions(request, "upvote", obj)
self.pre_conditions_on_save(obj)
services.add_vote(obj, user=request.user)
return response.Ok()
示例2: upvote
def upvote(self, request, pk=None):
issue = get_object_or_404(models.Issue, pk=pk)
self.check_permissions(request, 'upvote', issue)
votes_service.add_vote(issue, user=request.user)
return response.Ok()
示例3: test_add_vote
def test_add_vote():
project = f.ProjectFactory()
project_type = ContentType.objects.get_for_model(project)
user = f.UserFactory()
votes_qs = models.Votes.objects.filter(content_type=project_type, object_id=project.id)
votes.add_vote(project, user)
assert votes_qs.get().count == 1
votes.add_vote(project, user) # add_vote must be idempotent
assert votes_qs.get().count == 1
示例4: test_user_story_voters_retrieve
def test_user_story_voters_retrieve(client, data):
add_vote(data.public_user_story, data.project_owner)
public_url = reverse('userstory-voters-detail', kwargs={"resource_id": data.public_user_story.pk,
"pk": data.project_owner.pk})
add_vote(data.private_user_story1, data.project_owner)
private_url1 = reverse('userstory-voters-detail', kwargs={"resource_id": data.private_user_story1.pk,
"pk": data.project_owner.pk})
add_vote(data.private_user_story2, data.project_owner)
private_url2 = reverse('userstory-voters-detail', kwargs={"resource_id": data.private_user_story2.pk,
"pk": data.project_owner.pk})
add_vote(data.blocked_user_story, data.project_owner)
blocked_url = reverse('userstory-voters-detail', kwargs={"resource_id": data.blocked_user_story.pk,
"pk": data.project_owner.pk})
users = [
None,
data.registered_user,
data.project_member_without_perms,
data.project_member_with_perms,
data.project_owner
]
results = helper_test_http_method(client, 'get', public_url, None, users)
assert results == [200, 200, 200, 200, 200]
results = helper_test_http_method(client, 'get', private_url1, None, users)
assert results == [200, 200, 200, 200, 200]
results = helper_test_http_method(client, 'get', private_url2, None, users)
assert results == [401, 403, 403, 200, 200]
results = helper_test_http_method(client, 'get', blocked_url, None, users)
assert results == [401, 403, 403, 200, 200]
示例5: test_issue_voters_retrieve
def test_issue_voters_retrieve(client, data):
add_vote(data.public_issue, data.project_owner)
public_url = reverse('issue-voters-detail', kwargs={"issue_id": data.public_issue.pk, "pk": data.project_owner.pk})
add_vote(data.private_issue1, data.project_owner)
private_url1 = reverse('issue-voters-detail', kwargs={"issue_id": data.private_issue1.pk, "pk": data.project_owner.pk})
add_vote(data.private_issue2, data.project_owner)
private_url2 = reverse('issue-voters-detail', kwargs={"issue_id": data.private_issue2.pk, "pk": data.project_owner.pk})
users = [
None,
data.registered_user,
data.project_member_without_perms,
data.project_member_with_perms,
data.project_owner
]
results = helper_test_http_method(client, 'get', public_url, None, users)
assert results == [200, 200, 200, 200, 200]
results = helper_test_http_method(client, 'get', private_url1, None, users)
assert results == [200, 200, 200, 200, 200]
results = helper_test_http_method(client, 'get', private_url2, None, users)
assert results == [401, 403, 403, 200, 200]
示例6: create_votes
def create_votes(self, obj):
for i in range(self.sd.int(*NUM_VOTES)):
user=self.sd.db_object_from_queryset(User.objects.all())
add_vote(obj, user)
示例7: create_votes
def create_votes(self, obj, project):
for i in range(self.sd.int(*NUM_VOTES)):
voting_user=self.sd.db_object_from_queryset(project.members.all())
add_vote(obj, voting_user)
示例8: _add_voter
def _add_voter(self, permission, request, pk=None):
obj = self.get_object()
self.check_permissions(request, permission, obj)
services.add_vote(obj, user=request.user)
return response.Ok()
示例9: upvote
def upvote(self, request, pk=None):
issue = self.get_object()
votes_service.add_vote(issue, user=request.user)
return Response(status=status.HTTP_200_OK)