예제 #1
0
파일: vote_api.py 프로젝트: allmywant/anno
    def vote_list(self, request):
        """
        Exposes an API endpoint to retrieve a list of vote.
        """
        limit = 10
        if request.limit is not None:
            limit = request.limit

        curs = None
        if request.cursor is not None:
            try:
                curs = Cursor(urlsafe=request.cursor)
            except BadValueError:
                raise endpoints.BadRequestException('Invalid cursor %s.' % request.cursor)

        if curs is not None:
            votes, next_curs, more = Vote.query().fetch_page(limit, start_cursor=curs)
        else:
            votes, next_curs, more = Vote.query().fetch_page(limit)

        items = [entity.to_message() for entity in votes]
        if more:
            return VoteListMessage(vote_list=items, cursor=next_curs.urlsafe(), has_more=more)
        else:
            return VoteListMessage(vote_list=items, has_more=more)
예제 #2
0
    def get(self):

        product_id = self.get_argument("product_id", "")

        vote = Vote()
        response = vote.GetVotes(product_id)

        self.write(json_util.dumps(response))
예제 #3
0
    def get(self):

        user_id = self.get_argument("user_id", "")
        product_id = self.get_argument("product_id", "")

        vote = Vote()
        response = vote.IfVoted(user_id, product_id)

        self.write(json_util.dumps(response))
예제 #4
0
파일: util.py 프로젝트: mschwalb/photobout
def make_photo_dict(photo, email):
    photo_dict = {}
    owner = User.get_by_key_name(photo.owner_email)
    photo_dict['image'] = photo.image_url
    photo_dict['owner_email'] = photo.owner_email
    photo_dict['owner_first_name'] = owner.first_name
    photo_dict['owner_last_name'] = owner.last_name
    photo_dict['num_votes'] = Vote.count(photo)
    photo_dict['num_comments'] = len(Comment.for_(photo))
    photo_dict['is_voted'] = Vote.is_voted(email, photo)
    photo_dict['profile_picture'] = owner.profile_picture
    return photo_dict
예제 #5
0
파일: util.py 프로젝트: mschwalb/photobout
def set_winner(bout):
    bout.change_status(2)
    participants = sorted(Photo.for_(bout), key=lambda x: Vote.count(x), reverse=True)
    if len(participants) > 0:
        max_vote_count = Vote.count(participants[0])
        if max_vote_count > 0:
            for participant in participants:
                current_vote_count = Vote.count(participant)
                if current_vote_count == max_vote_count:
                    winner = User.get_by_key_name(participant.owner_email)
                    Winner.create(winner, bout)
                    Notification.create('winner', winner, winner.email, bout)
                elif current_vote_count < max_vote_count:
                    break
예제 #6
0
파일: bouts.py 프로젝트: mschwalb/photobout
 def get(self):
     response = []
     bout_id = long(self.request.get('bout_id'))
     bout = Bout.get_by_id(bout_id)
     for rank, photo in enumerate(sorted(Photo.for_(bout), key=lambda x: Vote.count(x), reverse=True), start=1):
         user_dict = {}
         owner = User.get_by_key_name(photo.owner_email)
         user_dict['votes'] = Vote.count(photo)
         user_dict['rank'] = rank
         user_dict['email'] = photo.owner_email
         user_dict['first_name'] = owner.first_name
         user_dict['last_name'] = owner.last_name
         user_dict['profile_picture'] = owner.profile_picture
         response.append(user_dict)
     self.response.write(json.dumps(response))
예제 #7
0
파일: anno_api.py 프로젝트: topcircler/anno
    def anno_my_stuff(self, request):
        """
        Exposes an API endpoint to return all my anno list.
        """
        user = auth_user(self.request_state.headers)
        anno_list = Anno.query_anno_by_author(user)
        vote_list = Vote.query_vote_by_author(user)
        for vote in vote_list:
            anno = Anno.get_by_id(vote.anno_key.id())
            if anno is not None:
                anno_list.append(anno)
        flag_list = Flag.query_flag_by_author(user)
        for flag in flag_list:
            anno = Anno.get_by_id(flag.anno_key.id())
            if anno is not None:
                anno_list.append(anno)
        followup_list = FollowUp.query_followup_by_author(user)
        for followup in followup_list:
            anno = Anno.get_by_id(followup.anno_key.id())
            if anno is not None:
                anno_list.append(anno)
        anno_set = list(set(anno_list))

        anno_message_list = []
        for anno in anno_set:
            anno_message_list.append(anno.to_response_message())
        return AnnoListMessage(anno_list=anno_message_list)
예제 #8
0
파일: anno_api.py 프로젝트: usersource/anno
    def anno_get(self, request):
        """
        Exposes an API endpoint to get an anno detail by the specified id.
        """
        try:
            user = auth_user(self.request_state.headers)
        except Exception:
            user = None

        if request.id is None:
            raise endpoints.BadRequestException('id field is required.')

        anno = Anno.get_by_id(request.id)

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

        # set anno basic properties
        anno_resp_message = anno.to_response_message(user, list_message=False)

        # set anno association with followups
        followups = FollowUp.find_by_anno(anno)
        followup_messages = [ entity.to_message(team_key=request.team_key) for entity in followups ]
        anno_resp_message.followup_list = followup_messages

        # set anno association with votes/flags
        # if current user exists, then fetch vote/flag.
        if user is not None:
            anno_resp_message.is_my_vote = Vote.is_belongs_user(anno, user)
            anno_resp_message.is_my_flag = Flag.is_belongs_user(anno, user)

            # update last_read of UserAnnoState
            UserAnnoState.update_last_read(user=user, anno=anno)

        return anno_resp_message
예제 #9
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')
예제 #10
0
파일: anno.py 프로젝트: usersource/anno
    def to_dashboard_response_message(self, user):
        user_message = None
        if self.creator is not None:
            user_info = self.creator.get()
            user_message = UserMessage(display_name=user_info.display_name,
                                       user_email=user_info.user_email,
                                       image_url=user_info.image_url)

        app = self.app.get() if self.app else None
        app_name = app.name if app else self.app_name
        app_version = app.version if app else self.app_version

        # set anno association with followups
        from model.follow_up import FollowUp
        followups = FollowUp.find_by_anno(self, True)
        followup_messages = [ entity.to_message(auth_user=user) for entity in followups ]

        from model.vote import Vote
        is_my_vote = Vote.is_belongs_user(self, user)

        from model.flag import Flag
        is_my_flag = Flag.is_belongs_user(self, user)

        mentions = []
        for tagged_user in self.tagged_users:
            tagged_user_info = User.get_by_id(int(tagged_user))
            is_auth_user = tagged_user_info.user_email == user.user_email
            mentions.append(AnnoMentionsResponseMessage(id=tagged_user_info.key.id(),
                                                        display_name=tagged_user_info.display_name,
                                                        user_email=tagged_user_info.user_email,
                                                        image_url=tagged_user_info.image_url,
                                                        is_auth_user=is_auth_user))

        team_notes_metadata = AnnoTeamNotesMetadataMessage(tags=parseTeamNotesForHashtags(self.team_notes),
                                                           mentions=mentions)

        engaged_users = Anno.getEngagedUsers(anno_id=self.key.id(), auth_user=user, include_auth_user=True)

        anno_message = AnnoDashboardResponseMessage(id=self.key.id(),
                                                    anno_text=self.anno_text,
                                                    device_model=self.device_model,
                                                    app_name=app_name,
                                                    app_version=app_version,
                                                    os_name=self.os_name,
                                                    os_version=self.os_version,
                                                    created=self.created,
                                                    creator=user_message,
                                                    draw_elements=self.draw_elements,
                                                    vote_count=self.vote_count,
                                                    flag_count=self.flag_count,
                                                    followup_count=self.followup_count,
                                                    followup_list=followup_messages,
                                                    is_my_vote=is_my_vote,
                                                    is_my_flag=is_my_flag,
                                                    team_notes_metadata=team_notes_metadata,
                                                    team_notes=self.team_notes,
                                                    engaged_users=engaged_users,
                                                    archived=self.archived)

        return anno_message
예제 #11
0
파일: vote_api.py 프로젝트: usersource/anno
    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()
예제 #12
0
파일: bouts.py 프로젝트: mschwalb/photobout
 def post(self):
     response = {}
     user = util.get_user_from_session()
     email = user.key().name()
     owner_email = self.request.get('owner_email')
     bout_id = long(self.request.get('bout_id'))
     bout = Bout.get_by_id(bout_id)
     photo = Photo.get_by_key_name(owner_email, parent=bout)
     if Vote.update(email, photo, bout):
         Notification.create('photo_vote', bout.owner, user.email, bout)
         message = "%s voted on your photo in the Bout %s."%(user.name, bout.name)
         util.send_push_notification(photo.user.email, message, bout.id)
         response = {"success": True, "voted": True}
     else:
         response = {"success": True, "voted": False}
     vote_count = Vote.count(photo)
     response["vote_count"] = vote_count
     self.response.write(json.dumps(response))
예제 #13
0
파일: vote_api.py 프로젝트: allmywant/anno
 def vote_get(self, request):
     """
     Exposes an API endpoint to get a vote.
     """
     if request.id is None:
         raise endpoints.BadRequestException('id field is required.')
     vote = Vote.get_by_id(request.id)
     if vote is None:
         raise endpoints.NotFoundException('No vote entity with the id "%s" exists.' % request.id)
     return vote.to_message()
예제 #14
0
파일: admin.py 프로젝트: abikounso/omikuji
    def show(self):
        labels = ['日本舞踊', '空手部', 'チームパートタイマーの栄光', 'ルーキーズ', '銀河鉄道', 'チョッキーズ']
        summary = []
        for i in range(len(labels)):
            set = [labels[i]]
            query = str(Vote.all().filter('type =', i + 1).count())
            set.append(query)
            summary.append(set)

        self.labels = labels
        self.summary = summary
예제 #15
0
파일: bouts.py 프로젝트: mschwalb/photobout
 def post(self):
     user = util.get_user_from_session()
     bout_id = long(self.request.get('bout_id'))
     image_blob_key = str(self.get_uploads()[0].key())
     bout = Bout.get_by_id(bout_id)
     photo = Photo.for_bout_user(bout, user.email)
     if photo:
         votes = Vote.for_photo(photo)
         if len(votes) > 0:
             db.delete(votes)
     Photo.create(bout, user, image_blob_key)
     deferred.defer(send_add_photo_notifications, bout, user.email)
예제 #16
0
파일: anno.py 프로젝트: usersource/anno
    def delete(cls, anno):
        anno_id = "%d" % anno.key.id()

        # deleting UserAnnoState of anno
        from model.userannostate import UserAnnoState
        UserAnnoState.delete_by_anno(anno_key=anno.key)

        # deleting FollowUp of anno
        from model.follow_up import FollowUp
        FollowUp.delete_by_anno(anno_key=anno.key)

        # deleting Vote of anno
        from model.vote import Vote
        Vote.delete_by_anno(anno_key=anno.key)

        # deleting Flag of anno
        from model.flag import Flag
        Flag.delete_by_anno(anno_key=anno.key)

        anno.key.delete()
        index = search.Index(name=SearchIndexName.ANNO)
        index.delete(anno_id)
예제 #17
0
파일: vote_api.py 프로젝트: allmywant/anno
 def vote_delete(self, request):
     """
     Exposes an API endpoint to delete an existing vote.
     """
     if request.id is None and request.anno_id is None:
         raise endpoints.BadRequestException('id or anno_id field is required.')
     if request.id is not None:
         vote = Vote.get_by_id(request.id)
         if vote is None:
             raise endpoints.NotFoundException('No vote entity with the id "%s" exists.' % request.id)
         anno = vote.anno_key.get()
         vote.key.delete()
         anno.vote_count -= 1
         anno.put()
     elif request.anno_id is not None:
         user = User.find_user_by_email(get_endpoints_current_user().email())
         anno = Anno.get_by_id(request.anno_id)
         for key in Vote.query(Vote.anno_key == anno.key, Vote.creator == user.key).iter(keys_only=True):
             key.delete()
             anno.vote_count -= 1
             anno.put()
     return message_types.VoidMessage()
    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()
예제 #19
0
파일: vote_api.py 프로젝트: usersource/anno
 def vote_delete(self, request):
     """
     Exposes an API endpoint to delete an existing vote.
     """
     user = auth_user(self.request_state.headers)
     anno = None
     if request.id is None and request.anno_id is None:
         raise endpoints.BadRequestException('id or anno_id field is required.')
     if request.id is not None:
         vote = Vote.get_by_id(request.id)
         if vote is None:
             raise endpoints.NotFoundException('No vote entity with the id "%s" exists.' % request.id)
         anno = vote.anno_key.get()
         vote.key.delete()
         anno.vote_count -= 1
         anno.put()
     elif request.anno_id is not None:
         anno = Anno.get_by_id(request.anno_id)
         for key in Vote.query(Vote.anno_key == anno.key, Vote.creator == user.key).iter(keys_only=True):
             key.delete()
             anno.vote_count -= 1
             anno.put()
     put_search_document(anno.generate_search_document(), SearchIndexName.ANNO)
     return message_types.VoidMessage()
예제 #20
0
파일: anno_api.py 프로젝트: usersource/anno
    def anno_search(self, request):
        """
        Exposes and API endpoint to search anno list.
        """
        user = auth_user(self.request_state.headers)

        if request.order_type is None:
            raise endpoints.BadRequestException('order_type field is required.')
        if request.order_type != 'recent' and request.order_type != 'active' and request.order_type != 'popular':
            raise endpoints.BadRequestException(
                'Invalid order_type field value, valid values are "recent", "active" and "popular"')

        app_set = None
        logging.info("only_my_apps=%s" % request.only_my_apps)
        if request.only_my_apps:
            app_set = set()
            for anno in Anno.query_anno_by_author(user):
                app_set.add(anno.app_name)
            for vote in Vote.query_vote_by_author(user):
                anno = Anno.get_by_id(vote.anno_key.id())
                if anno is not None:
                    app_set.add(anno.app_name)
            for flag in Flag.query_flag_by_author(user):
                anno = Anno.get_by_id(flag.anno_key.id())
                if anno is not None:
                    app_set.add(anno.app_name)
            for followup in FollowUp.query_followup_by_author(user):
                anno = Anno.get_by_id(followup.anno_key.id())
                if anno is not None:
                    app_set.add(anno.app_name)

        if request.order_type == 'popular':
            return Anno.query_by_popular(request.limit, request.offset,
                                         request.search_string, request.app_name, app_set, user)
        elif request.order_type == 'active':
            return Anno.query_by_active(request.limit, request.offset, request.search_string, request.app_name, app_set, user)
        else:
            return Anno.query_by_recent(request.limit, request.offset, request.search_string, request.app_name, app_set, user)
예제 #21
0
파일: util.py 프로젝트: mschwalb/photobout
def make_bout_dict(bout, email):
    bout_dict = {}
    bout_dict['id'] = bout.id
    bout_dict['name'] = bout.name
    bout_dict['description'] = bout.description
    bout_dict['time_left'] = bout.time_left_string
    bout_dict['ended'] = bout.ended
    bout_dict['photos'] = []
    user_in_session_photo = Photo.for_bout_user(bout, email)
    if user_in_session_photo:
        photo_dict = make_photo_dict(user_in_session_photo, email)
        bout_dict['photos'].append(photo_dict)
    for photo in sorted(Photo.for_(bout), key=lambda x: Vote.count(x), reverse=True):
        if photo.owner_email != email:
            photo_dict = make_photo_dict(photo, email)
            bout_dict['photos'].append(photo_dict)
    if bout.ended:
        bout_dict['winners'] = []
        winners = Winner.for_bout(bout)
        if len(winners) > 0:
            for winner in winners:
                bout_dict['winners'].append(winner.email)
    return bout_dict
예제 #22
0
파일: vote_api.py 프로젝트: allmywant/anno
    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()
예제 #23
0
def setup():
    user_1 = User.create('email1', 'firstname1', 'lastname1', 'password1')
    tp_user_1 = ThirdPartyUser(key_name='FB', parent=user_1)
    tp_user_1.network_id = '359059317608175'
    tp_user_1.put()
    user_2 = User.create('email2', 'firstname2', 'lasstname2', 'password2')
    tp_user_2 = ThirdPartyUser(key_name='FB', parent=user_2)
    tp_user_2.network_id = '359059317608175'
    tp_user_2.put()
    bout_1 = Bout.create(user_1, 'bout1', 'desc1', 1, 1)
    util.schedule_end(bout_1)
    photo_1 = Photo.create(bout_1, user_1, 'image_blob_key_1')
    photo_2 = Photo.create(bout_1, user_2, 'image_blob_key_2')
    bout_2 = Bout.create(user_2, 'bout2', 'desc2', 1, 2)
    util.schedule_end(bout_2)
    Vote.create('email1', photo_1)
    Vote.create('email2', photo_1)
    Vote.create('email2', photo_2)
    #photo_add, photo_vote, comment_add, winner, invited
    Notification.create('photo_add', bout_1.owner, user_2.email, bout_1)
    Notification.create('photo_vote', bout_1.owner, user_2.email, bout_1)
    Notification.create('comment_add', bout_1.owner, user_2.email, bout_1)
    Notification.create('winner', user_1, user_2.email, bout_1)
    Notification.create('invited', user_1, user_2.email, bout_1)
    #Winner.create(user_1, bout_1)
    Comment(parent=photo_1, user=user_1, message='message1', timestamp=datetime.datetime.now()).put()
    Comment(parent=photo_1, user=user_2, message='message2', timestamp=datetime.datetime.now()).put()
    Comment(parent=photo_2, user=user_1, message='message3', timestamp=datetime.datetime.now()).put()
    Comment(parent=photo_2, user=user_1, message='message4', timestamp=datetime.datetime.now()).put()
    Comment(parent=photo_2, user=user_2, message='message5', timestamp=datetime.datetime.now()).put()
    Comment(parent=photo_2, user=user_1, message='message6', timestamp=datetime.datetime.now()).put()
    Comment(parent=photo_2, user=user_2, message='message7', timestamp=datetime.datetime.now()).put()
    Comment(parent=photo_2, user=user_2, message='message8', timestamp=datetime.datetime.now()).put()
    Comment(parent=photo_2, user=user_2, message='message9', timestamp=datetime.datetime.now()).put()
    Follower.create('email1', user_2)
    Following.create(user_1, 'email2')
예제 #24
0
    def get(self, category, name, color):

        category = category.replace("_", "&")
        name = name.replace("_", "&")
        color = color.replace("_", "&")
        tag = self.get_argument("tag", "")

        id_bodega = cellar_id
        cellar = Cellar()
        res_cellar = cellar.GetWebCellar()

        if "success" in res_cellar:
            id_bodega = res_cellar["success"]

        # sku = self.get_argument("sku","")
        prod = Product()

        response_obj = prod.GetProductCatNameColor(category, name, color)

        if "error" in response_obj:
            self.render("beauty_error.html",
                        message="Producto no encontrado, error:{}".format(
                            response_obj["error"]))
        else:

            tallas_disponibles = []

            prod.size_id = sorted(prod.size_id, reverse=True)

            for s in prod.size_id:

                kardex = Kardex()
                response_obj = kardex.FindKardex(prod.sku, id_bodega, s)

                if "success" in response_obj:

                    # print kardex.balance_units

                    if kardex.balance_units > 0:

                        _size = Size()
                        _size.id = s
                        res_name = _size.initById()

                        if "success" in res_name:
                            tallas_disponibles.append({
                                "id":
                                _size.id,
                                "name":
                                _size.name,
                                "stock":
                                kardex.balance_units
                            })
                        elif debugMode:
                            print res_name["error"]
                elif debugMode:
                    print response_obj["error"]

            prod.size = tallas_disponibles[::-1]

            vote = Vote()

            res = vote.GetVotes(prod.id)
            votos = 0

            prod_name = prod.name

            try:
                prod_name = name.split("&")[0]
            except:
                pass

            # print "prod_name:{}".format(prod_name)

            combinaciones = prod.GetCombinations(id_bodega, prod_name)

            tag = Tag()
            res_tags = tag.GetTagsByProductId(prod.id)

            if "success" in res_tags:
                relacionados = prod.GetRandom(id_bodega, res_tags["success"])

            if "success" in res:
                votos = res["success"]

            self.render("store/detalle-producto.html",
                        data=prod,
                        combinations=combinaciones,
                        related=relacionados,
                        votos=votos,
                        tag=tag)
예제 #25
0
파일: admin.py 프로젝트: abikounso/omikuji
 def index(self):
     query = Vote.all()
     query.order('name')
     self.result = query
예제 #26
0
파일: vote.py 프로젝트: abikounso/omikuji
 def index(self):
     query = Vote.all()
     self.result = query
예제 #27
0
파일: admin.py 프로젝트: abikounso/omikuji
 def destroy(self):
     query = Vote.all()
     for r in query:
         r.delete()
     self.redirect('/admin')