示例#1
0
    def vote_insert(self, request):
        """
        Exposes an API endpoint to insert a vote for the current user.
        """
        user = auth_user(self.request_state.headers)

        anno = Anno.get_by_id(request.anno_id)
        if anno is None:
            raise endpoints.NotFoundException('No anno entity with the id "%s" exists.' % request.id)

        vote = Vote()
        vote.anno_key = anno.key
        vote.creator = user.key
        if request.created is not None:
            vote.created = request.created
        vote.put()

        anno.vote_count += 1
        anno.last_update_time = datetime.datetime.now()
        anno.last_activity = 'vote'
        anno.last_update_type = 'create'
        anno.put()

        # update user anno state
        UserAnnoState.insert(user=user, anno=anno, type=AnnoActionType.UPVOTED)

        # update vote in search document
        put_search_document(anno.generate_search_document(), SearchIndexName.ANNO)

        return vote.to_message()
示例#2
0
文件: vote.py 项目: abikounso/omikuji
 def create(self):
     input_name = self.params.get('name', None)
     input_type = self.params.get('type', None)
     if input_name == "" or input_type == None:
         VoteController.notice = '全ての項目は必須入力です!'
         self.redirect('/vote/new')
     elif Vote.all().filter('name =', input_name).count() > 0:
         VoteController.notice = 'この名前はすでに使われています!'
         self.redirect('/vote/new')
     else:
         r = Vote(
             name = input_name,
             type = int(input_type),
         )
         r.put()
         self.redirect('/vote')
    def _process_votes(self, session, new_user, modified_voters, **kwargs):
        for idea in session.ideas:
            for user in modified_voters:
                vote_id = ("vote_" + str(idea.key()) + "_" + str(user.key()))
                vote = idea.votes.filter("user ="******"No")
                if ("new_vote_" + str(idea.key())) in kwargs:
                    new_vote.yes_no = kwargs["new_vote_" + str(idea.key())]
                new_vote.put()
示例#4
0
    def vote_insert(self, request):
        """
        Exposes an API endpoint to insert a vote for the current user.
        """
        user = handle_user(request.user_email)

        anno = Anno.get_by_id(request.anno_id)
        if anno is None:
            raise endpoints.NotFoundException('No anno entity with the id "%s" exists.' % request.id)

        vote = Vote()
        vote.anno_key = anno.key
        vote.creator = user.key
        if request.created is not None:
            vote.created = request.created
        vote.put()

        anno.vote_count += 1
        anno.last_update_time = datetime.datetime.now()
        anno.last_activity = 'vote'
        anno.put()
        return vote.to_message()