Exemple #1
0
 def deleteRecipe(self, request, urlKey):
     """
     Delete a recipe from the recipe form
     """
     recipe = Recipe.objects(urlKey=urlKey).first()
     if recipe:
         recipe.delete()
         return OK()
     else:
         return ERROR(message="Recipe not found")
Exemple #2
0
 def saveRecipe(self, request, urlKey):
     """
     Save a recipe from the recipe edit form
     """
     data = json.load(request.content)
     recipe = Recipe.objects(urlKey=urlKey).first()
     for k in data.keys():
         if k not in ['user']:
             setattr(recipe, k, data[k])
     recipe.save()
     return OK()
Exemple #3
0
    def createRecipeSave(self, request):
        """
        Save recipes
        """
        data = json.load(request.content)
        data = {k.encode('utf-8'): v for (k, v) in data.items()}
        recipe = Recipe()
        recipe.name = data['name']
        recipe.recipeYield = str(data.get('recipeYield'))
        recipe.user = ICurrentUser(request)
        recipe.urlKey = urlify(recipe.user.email, recipe.name)
        if Recipe.objects(urlKey=recipe.urlKey).first():
            return ERROR(message=ResponseMsg.renameRecipe)

        recipe.author = data.get('author', USER().anonymous.givenName)
        for field in ['tags', 'ingredients', 'instructions']:
            if data.get(field):
                for i in data[field]:
                    recipe[field].append(i)

        recipe.save()
        return OK(message=recipe.urlKey)
Exemple #4
0
 def getRecipe(self, request, urlKey):
     """
     Return a specific recipe from its urlKey
     """
     return Recipe.objects(urlKey=urlKey).first()
Exemple #5
0
 def recipeList(self, request):
     """
     List all recipes
     """
     # we are only sending limited information to the client because of security risk
     return Recipe.objects()
Exemple #6
0
# """
# Modify the recipe objects by adding an urlKey
# """

from mongoengine import connect

from noms import DATABASE_NAME, urlify 
from noms.recipe import Recipe


connect(db=DATABASE_NAME)  

recipes = Recipe.objects() 
for n in recipes: 
  n.urlKey = urlify(n.user, n.name) 
  n.save() 
Exemple #7
0
 def getRecipe(self, request, urlKey):
     """
     Return a specific recipe from its urlKey
     """
     return Recipe.objects(urlKey=urlKey).first()
Exemple #8
0
 def recipeList(self, request):
     """
     List all recipes
     """
     return Recipe.objects()
Exemple #9
0
# """
# Modify the recipe objects by adding an urlKey
# """

from mongoengine import connect

from noms import DATABASE_NAME, urlify
from noms.recipe import Recipe

connect(db=DATABASE_NAME)

recipes = Recipe.objects()
for n in recipes:
    n.urlKey = urlify(n.user, n.name)
    n.save()