Beispiel #1
0
    def post(self):
        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:
            recipe = recipes[0]
        else:
            recipe = Recipe()
            recipe.favorite_count = 0
            recipe.view_count = 0
            recipe.name = name
            recipe.author = author
            recipe_query = Recipe.query(Recipe.name==name)
            recipes = recipe_query.fetch(1)
            recipe.photos = recipes[0].photos

        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')

        recipe.ingredients = []
        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)))

        recipe.directions = []
        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.put()
        time.sleep(1)
        self.redirect('/viewpage?recipe_id='+str(recipe.key.id()))
Beispiel #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()))