Esempio n. 1
0
 def get(self):
     user = User.get_by_id(self.session.get('user_id'))
     print self.session.get('user_id')
     print user.shopping_list
     print type(user.shopping_list)
     save_cache = Save_cache.get_by_id(DEFAULT_Save_Cache_NAME)
     if not save_cache:
         save_cache = Save_cache(id=DEFAULT_Save_Cache_NAME)
     shopping_dict = []
     for item in user.shopping_list:
         item_dict = {'todoText':item, 'done':False}
         shopping_dict.append(item_dict)
     tmp_recipes_list = []
     for recipe_id in user.tmp_recipes:
         recipe = Recipe.get_by_id(long(recipe_id))
         recipe_dict = {'photo':'http://placehold.it/700x400',
                        'name':recipe.name,
                        'tags':recipe.tags,
                        'id':str(recipe.key.id()),
                        }
         if len(recipe.photos)>0:
             recipe_dict['photo'] = images.get_serving_url(recipe.photos[0].blob_key)
         tmp_recipes_list.append(recipe_dict)
     template = JINJA_ENVIRONMENT.get_template('template/shopping_page.html')
     template_values = {
         'shopping_dict':json.dumps(shopping_dict),
         'tmp_recipes':tmp_recipes_list,
         'keywords':json.dumps(save_cache.save_cache),
     }
     self.response.write(template.render(template_values))
Esempio n. 2
0
    def get(self):
        recipe_id = self.request.get('recipe_id')
        recipe = Recipe.get_by_id(long(recipe_id))
        save_cache = Save_cache.get_by_id(DEFAULT_Save_Cache_NAME)
        if not save_cache:
            save_cache = Save_cache(id=DEFAULT_Save_Cache_NAME)
        photo_urls = []
        for i in xrange(len(recipe.photos)):
            photo_urls.append(images.get_serving_url(recipe.photos[0].blob_key))
        user = User.get_by_id(self.session.get('user_id'))

        template = JINJA_ENVIRONMENT.get_template('template/edit_page.html')
        template_values = {
            'recipe_id':recipe_id,
            'recipe_name':recipe.name,
            'photo_urls':photo_urls,
            'author':user.user_name,
            'description':recipe.description,
            'ingredients':recipe.ingredients,
            'directions':recipe.directions,
            'estimate_time':recipe.estimate_time.strftime('%H:%M'),
            'portion':recipe.portion,
            'tags':json.dumps(recipe.tags),
            'keywords':json.dumps(save_cache.save_cache),
        }
        self.response.write(template.render(template_values))
Esempio n. 3
0
    def get(self):
        user_id = self.session.get('user_id')
        print user_id
        print 'ooooooooooooo'
        save_cache = Save_cache.get_by_id(DEFAULT_Save_Cache_NAME)
        if not save_cache:
            save_cache = Save_cache(id=DEFAULT_Save_Cache_NAME)
        user = User.get_by_id(user_id)
        my_recipes_list = []
        recipe_query = Recipe.query(Recipe.author == user_id)
        my_recipes = recipe_query.fetch()
        for recipe in my_recipes:
            print recipe
            recipe_dict = {'photo':'http://placehold.it/700x400',
                           'name':recipe.name,
                           'tags':recipe.tags,
                           'id':str(recipe.key.id()),
                           }
            if len(recipe.photos)>0:
                recipe_dict['photo'] = images.get_serving_url(recipe.photos[0].blob_key)
            my_recipes_list.append(recipe_dict)

        favorite_recipes_list = []
        for recipe_id in user.favorite_recipes:
            recipe = Recipe.get_by_id(long(recipe_id))
            recipe_dict = {'photo':'http://placehold.it/700x400',
                           'name':recipe.name,
                           'tags':recipe.tags,
                           'id':str(recipe.key.id()),
                           }
            if len(recipe.photos)>0:
                recipe_dict['photo'] = images.get_serving_url(recipe.photos[0].blob_key)
            favorite_recipes_list.append(recipe_dict)
        wish_recipes_list = []
        for recipe_id in user.wish_recipes:
            recipe = Recipe.get_by_id(long(recipe_id))
            recipe_dict = {'photo':'http://placehold.it/700x400',
                           'name':recipe.name,
                           'tags':recipe.tags,
                           'id':str(recipe.key.id()),
                           }
            if len(recipe.photos)>0:
                recipe_dict['photo'] = images.get_serving_url(recipe.photos[0].blob_key)
            wish_recipes_list.append(recipe_dict)
        template = JINJA_ENVIRONMENT.get_template('template/recipebox_page.html')
        template_values = {
            'my_recipes':my_recipes_list,
            'favorite_recipes':favorite_recipes_list,
            'wish_recipes':wish_recipes_list,
            'keywords':json.dumps(save_cache.save_cache),
        }
        self.response.write(template.render(template_values))
Esempio n. 4
0
    def get(self):
        upload_url = blobstore.create_upload_url('/createrecipe')
        upload_url = str(upload_url)
        save_cache = Save_cache.get_by_id(DEFAULT_Save_Cache_NAME)
        if not save_cache:
            save_cache = Save_cache(id=DEFAULT_Save_Cache_NAME)

        print upload_url
        template = JINJA_ENVIRONMENT.get_template('template/create_page.html')
        template_values = {
            'upload_url':upload_url,
            'keywords':json.dumps(save_cache.save_cache),
        }
        self.response.write(template.render(template_values))
Esempio n. 5
0
    def get(self):
        save_cache = Save_cache.get_by_id(DEFAULT_Save_Cache_NAME)
        if not save_cache:
            save_cache = Save_cache(id=DEFAULT_Save_Cache_NAME)

        template = JINJA_ENVIRONMENT.get_template('template/error_page.html')
        error_code = self.request.get('error')
        error_msgs = {
            '1':"You tried to create a recipe whose name is the same as an existing one"
        }
        direct_page = {
            '1':'createpage'
        }
        template_values = {
            'error_msg':error_msgs[error_code],
            'direct_page':direct_page[error_code],
            'keywords':json.dumps(save_cache.save_cache),
        }
        self.response.write(template.render(template_values))
Esempio n. 6
0
    def get(self):
        recipe_id = self.request.get('recipe_id')
        print "-------------------"
        recipe = Recipe.get_by_id(long(recipe_id))

        recipe_query = History.query(History.recipe_authorID==self.session.get('user_id'))
        recipe_query_test = recipe_query.fetch()
        print recipe_query_test
        print 'yoyoyoyoyo'

        save_cache = Save_cache.get_by_id(DEFAULT_Save_Cache_NAME)
        if not save_cache:
            save_cache = Save_cache(id=DEFAULT_Save_Cache_NAME)
        photo_urls = []
        for i in xrange(len(recipe.photos)):
            photo_urls.append(images.get_serving_url(recipe.photos[i].blob_key))
        author = User.get_by_id(recipe.author)
        ingredients_list = []
        user = User.get_by_id(self.session.get('user_id'))
        shopping_list = user.shopping_list
        isAllInList = True
        for ingredient in recipe.ingredients:
            if ingredient in shopping_list:
                ingredients_list.append((ingredient,True))
            else:
                ingredients_list.append((ingredient,False))
                isAllInList = False
        isAuthor = False
        if user.user_id == author.user_id:
            isAuthor = True
        isFavorite = False
        if recipe_id in user.favorite_recipes:
            isFavorite = True
        isWish = False
        if recipe_id in user.wish_recipes:
            isWish = True
        comments_list = []
        for comment in recipe.comments:
            author2 = User.get_by_id(comment.author)
            time_str = comment.time.strftime("%B %d, %Y at %H:%M:%S")
            comment_dict = {
                'author':author2.user_name,
                'author_profile':author2.photo,
                'comment_text':comment.comment_text,
                'time': time_str,
            }
            comments_list.append(comment_dict)

        same_list = []
        recipe_name = Recipe.query(Recipe.name==recipe.name)
        for recipe2 in recipe_name:
            if User.get_by_id(recipe2.author).user_name is not author.user_name:
                same_dict = {
                    'author': User.get_by_id(recipe2.author).user_name,
                    'recipe_id': recipe2.key.id(),
                }
                same_list.append(same_dict)
        print author.user_name
        template = JINJA_ENVIRONMENT.get_template('template/view_page.html')
        template_values = {
            'recipe_id':recipe_id,
            'recipe_name':recipe.name,
            'keywords':json.dumps(save_cache.save_cache),
            'photo_urls':photo_urls,
            'author':author.user_name,
            'ingredients':ingredients_list,
            'directions':recipe.directions,
            'estimate_time':recipe.estimate_time,
            'portion':recipe.portion,
            'tags':recipe.tags,
            'isAllInList':isAllInList,
            'isFavorite':isFavorite,
            'isWish':isWish,
            'isAuthor':isAuthor,
            'comments_list':comments_list,
            'same_list':same_list,
            'same_list_len':len(same_list),
        }
        self.response.write(template.render(template_values))
Esempio n. 7
0
    def get(self):

        # recipe_query = History.query(History.recipe_authorID==self.session.get('user_id'))
        recipe_query = History.query()
        recipe_query_all_tmp = recipe_query.fetch()
        recipe_query_all= sorted(recipe_query_all_tmp, key=lambda contract: (contract.create_time.strftime("%Y-%m-%d %H:%M:%S")), reverse=True)
        print recipe_query_all

        print 'yoyoyoyoyo'

        save_cache = Save_cache.get_by_id(DEFAULT_Save_Cache_NAME)
        if not save_cache:
            save_cache = Save_cache(id=DEFAULT_Save_Cache_NAME)



        history_list = []
        for tmp in recipe_query_all:
            if tmp.FromAndroid == False:
                FromAndroid =0
            else:
                FromAndroid =1

            if len(tmp.tags)==0:
                tmp.tags.append('Delicious')
                tmp.tags.append('YUMMY')
            print tmp.recipe_id
            # avatar = images.resize(tmp.photos[0], 32, 32)
            print type(tmp.create_time.strftime)

            if not tmp.recipe_id:
                # tmp.recipe_id = '5302669702856704'
                tmp.recipe_id = '5629499534213120'
            if not tmp.author_comments:
                tmp.author_comments = 'its good'

            recipe = Recipe.get_by_id(long(tmp.recipe_id))

            comments_list = []
            if tmp.FromAndroid == False:
                for comment in recipe.comments:
                    author2 = User.get_by_id(comment.author)
                    time_str = comment.time.strftime("%B %d, %Y at %H:%M:%S")
                    comment_dict = {
                        'author':author2.user_name,
                        'author_profile':author2.photo,
                        'comment_text':comment.comment_text,
                        'time': time_str,
                    }
                    comments_list.append(comment_dict)
            else:
                for comment in tmp.comments:
                    author2 = User.get_by_id(comment.author)
                    time_str = comment.time.strftime("%B %d, %Y at %H:%M:%S")
                    comment_dict = {
                        'author':author2.user_name,
                        'author_profile':author2.photo,
                        'comment_text':comment.comment_text,
                        'time': time_str,
                    }
                    comments_list.append(comment_dict)

            recipe_dict = {'recipe_author': tmp.recipe_author,
                           'recipe_name':  tmp.recipe_name,
                           'comments': tmp.comments,
                           'comments_author': tmp.comments_author,
                           'author_comments': tmp.author_comments,
                           'comments_list': comments_list,
                           'recipe_authorID':tmp.recipe_authorID,
                           'tags': tmp.tags,
                           'id': tmp.recipe_id,
                           'FromAndroid': FromAndroid,
                           'create_time':  tmp.create_time.strftime("%Y-%m-%d %H:%M:%S"),
                           'user_photo': User.get_by_id(tmp.recipe_authorID).photo,
                           'photo': images.get_serving_url(tmp.photos[0].blob_key),
                           'recipe_description':  tmp.recipe_description,
                           }
            history_list.append(recipe_dict)


        template = JINJA_ENVIRONMENT.get_template('template/timeline.html')
        template_values = {
            'history_list':history_list,
            'keywords':json.dumps(save_cache.save_cache),
        }
        self.response.write(template.render(template_values))