Ejemplo n.º 1
0
    def get(self, boker_id):

        boker = Boker.get_by_id(int(boker_id))
        if boker:
            deferred.defer(update_num_view, str(boker.key()))

            # Check post type, Video or Photo
            if boker.video_id and boker.video_source:
                self.template = 'video.html'
                if self.current_user is not None:
                    user = User.get_by_key_name(self.current_user['id'])
                    can_like = not Like.already_like(user, boker)
                else:
                    can_like = False
            else:
                active_contest = Contest.active_contest()
                if active_contest:
                    is_nominee = Contest.is_nominee(boker)

                if self.current_user is not None:
                    user = User.get_by_key_name(self.current_user['id'])
                    can_vote = not Vote.already_vote(user)
                    can_like = not Like.already_like(user, boker)
                else:
                    can_vote = False
                    can_like = False
                    
                querystring = self.request.GET

            return self.render_response(self.template, locals())
        else:
            self.abort(404)
Ejemplo n.º 2
0
    def post(self, boker_id):
        action = self.request.get('action')
        boker = Boker.get_by_id(int(boker_id))
        user = User.get_by_key_name(self.current_user['id'])

        if boker and user and action == 'vote':
            # Avoid multi votes
            if not Vote.already_vote(user):
                vote = Vote(contest=Contest.active_contest(), user=user, boker=boker)
                vote.put()

                # Upate boker vote score
                boker.num_vote += 1
                boker.save()

                # Trigger post action
                user_access_token = self.current_user['access_token']
                boker_url = settings.APP_DOMAIN + self.uri_for('boker_view', boker_id=boker_id)
                deferred.defer(publish_vote_action, user_access_token, boker_url)

                self.redirect(self.uri_for('boker_view', boker_id=boker_id)+'?vote=1')
        self.redirect(self.uri_for('boker_view', boker_id=boker_id))