Ejemplo n.º 1
0
    def post(self):
        upload = self.get_uploads()[0]
        recipe_id = self.request.get('recipe_id')
        recipe = Recipe.get_by_id(long(recipe_id))
        # # user_id = self.session.get('user_id')
        author_comments = self.request.get('author_comments')
        user_id = self.request.get('user_id')
        user = User.get_by_id(user_id)

        #img = images.resize(img, 200, 200)
        # if len(upload) >0:
        #     recipe.photos.append(Photo(
        #     blob_key = upload[0].key(),
        #     filename= upload[0].filename,
        # ))
        recipe.put()

        history = History()
        history.recipe_name = recipe.name
        history.author_comments = author_comments
        history.FromAndroid = True
        history.recipe_id = str(recipe.key.id())
        history.tags = recipe.tags
        history.recipe_author= user.user_name
        history.recipe_description= recipe.description
        history.recipe_authorID = user_id

        history.photos.append(Photo(
            blob_key = upload.key(),
            filename= "hi",
        ))
        # if len(upload) >0:
        #     history.photos.append(Photo(
        #         # blob_key = upload[0].key(),
        #         # filename= upload[0].filename,
        #         blob_key = upload.key(),
        #         filename= "hi",
        #     ))
        history.put()
        time.sleep(1)
Ejemplo n.º 2
0
    def post(self):
        upload = self.get_uploads('cover_image')
        name = self.request.get('recipe_name')
        author = self.request.get('user_id')
        recipe_query = Recipe.query(Recipe.name == name,Recipe.author == author)
        recipes = recipe_query.fetch(1)
        if len(recipes) >0:
            self.error(409)
            self.redirect('/error?error=1')
        else:
            recipe = Recipe()

            recipe.name = name
            if self.request.get('estimated_time') != "":
                tmp = time.strptime(self.request.get('estimated_time'),"%H:%M")
                recipe.estimate_time = datetime.time(hour=tmp.tm_hour,minute=tmp.tm_min)
            else:
                recipe.estimate_time =datetime.time(hour=0,minute=0)
            recipe.portion = int(self.request.get('portions'))
            recipe.description = self.request.get('description')

            ingredient_number = int(self.request.get('ingredient_number'))
            for i in xrange(ingredient_number):
                if self.request.get('ingredient'+str(i+1))!="":
                    recipe.ingredients.append(self.request.get('ingredient'+str(i+1)))

            direction_number = int(self.request.get('direction_number'))
            for i in xrange(direction_number):
                if self.request.get('direction'+str(i+1))!="":
                    recipe.directions.append(self.request.get('direction'+str(i+1)))
            if self.request.get('tag[]')!="":
                recipe.tags = json.loads(self.request.get('tag[]'))

            recipe.favorite_count = 0
            recipe.view_count = 0
            if len(upload) >0:
                recipe.photos.append(Photo(
                    blob_key = upload[0].key(),
                    filename= upload[0].filename,
                ))
            recipe.author = author

            recipe.put()
            history = History()
            history.recipe_name = name
            history.FromAndroid = False
            history.recipe_id = str(recipe.key.id())
            history.tags = json.loads(self.request.get('tag[]'))
            history.recipe_author=User.get_by_id(author).user_name
            history.recipe_description= self.request.get('description')
            history.recipe_authorID = author
            if len(upload) >0:
                history.photos.append(Photo(
                    blob_key = upload[0].key(),
                    filename= upload[0].filename,
                ))
            history.put()
            print history

            time.sleep(1)
            self.redirect('/viewpage?recipe_id='+str(recipe.key.id()))