Ejemplo n.º 1
0
 def favorite_for_company(self, request):
     user = endpoints.get_current_user()
     query = Favorite.query(ancestor=main.get_parent_key(user)).filter(Favorite.company_entity_key == request.company_entity_key)
     
     returnFavorite = Favorite(message="null")
     
     for favorite in query:
         returnFavorite = favorite
         break
     
     return returnFavorite
Ejemplo n.º 2
0
    def favorite_for_company(self, request):
        user = endpoints.get_current_user()
        query = Favorite.query(ancestor=main.get_parent_key(user)).filter(
            Favorite.company_entity_key == request.company_entity_key)

        returnFavorite = Favorite(message="null")

        for favorite in query:
            returnFavorite = favorite
            break

        return returnFavorite
Ejemplo n.º 3
0
 def company_list_favorite(self, query):
     # list of companies with favorite boolean attached to favorites
     user = endpoints.get_current_user()
     
     for company in query:
         company.favorite = False
         
         key = ndb.Key(urlsafe=company.entityKey)
         favQuery = Favorite.query(ancestor=main.get_parent_key(user)).filter(Favorite.company_entity_key == key)
         
         for favorite in favQuery:
             company.favorite = True
        
     return query
Ejemplo n.º 4
0
    def company_list_favorite(self, query):
        # list of companies with favorite boolean attached to favorites
        user = endpoints.get_current_user()

        for company in query:
            company.favorite = False

            key = ndb.Key(urlsafe=company.entityKey)
            favQuery = Favorite.query(
                ancestor=main.get_parent_key(user)).filter(
                    Favorite.company_entity_key == key)

            for favorite in favQuery:
                company.favorite = True

        return query
Ejemplo n.º 5
0
    def company_insert_favorite(self, request):
        user = endpoints.get_current_user()
        favBool = request.favorite
        key = ndb.Key(urlsafe=request.entityKey)

        query_favorite = Favorite.query(
            ancestor=main.get_parent_key(user)).filter(
                Favorite.company_entity_key == key)

        my_favorite = Favorite(parent=main.get_parent_key(user),
                               company_entity_key=key)

        found = False

        logging.info(favBool)

        for item in query_favorite:
            logging.info("favorite logged")
            my_favorite = item
            found = True

        logging.info(my_favorite)

        if favBool:

            logging.info("favorite bool = True")

            if not found:

                logging.info("creating favorite")
                #                 my_favorite = Favorite(parent=main.get_parent_key(user), company_entity_key=key)
                my_favorite.put()
        else:

            if found:
                logging.info("delete")
                my_favorite.key.delete()

        return request
Ejemplo n.º 6
0
    def company_insert_favorite(self, request):
        user = endpoints.get_current_user()
        favBool = request.favorite
        key = ndb.Key(urlsafe=request.entityKey)
        
        query_favorite = Favorite.query(ancestor=main.get_parent_key(user)).filter(Favorite.company_entity_key == key)
        
        my_favorite = Favorite(parent=main.get_parent_key(user), company_entity_key=key)
        
        found = False
        
        logging.info(favBool)
        
        for item in query_favorite:
            logging.info("favorite logged")
            my_favorite = item
            found = True
        
        logging.info(my_favorite)
        
        if favBool:
            
            logging.info("favorite bool = True")
            
            if not found:
                
                logging.info("creating favorite")
#                 my_favorite = Favorite(parent=main.get_parent_key(user), company_entity_key=key)
                my_favorite.put()
        else:
            
            if found:
                logging.info("delete")
                my_favorite.key.delete()
            
        return request