示例#1
0
def recipes():
    """
    Set up some recipes explicitly during a test
    """
    author = u'cory'
    url = urlify(u'weird sandwich', author)
    r1 = recipe.Recipe(name=u'weird sandwich', author=author, urlKey=url).save()
    url = urlify(u'weird soup', author)
    r2 = recipe.Recipe(name=u'weird soup', author=author, urlKey=url).save()
    return (r1, r2)
示例#2
0
 def _recipes(self):
     """
     Set up some recipes explicitly during a test
     """
     author = u'cory'
     url = urlify(u'weird sandwich', author)
     r1 = recipe.Recipe(name=u'weird sandwich', author=author, urlKey=url).save()
     url = urlify(u'weird soup', author)
     r2 = recipe.Recipe(name=u'weird soup', author=author, urlKey=url).save()
     return (r1, r2)
示例#3
0
 def test_urlify(self):
     """
     Do I produce punycode output for the inputs?
     """
     helloThere = u'你好'
     self.assertEqual(urlify(u'asdf', helloThere, u'69'),
             'asdf--69-nm2mf94f')
示例#4
0
    def test_render(self):
        """
        Do I produce a json array from a query?
        """
        author = u'cory'
        
        u = user.User(email="*****@*****.**")
        u.save()

        url = urlify(u'delicious sandwich', author)
        recipe.Recipe(name=u'delicious sandwich', author=author, urlKey=url, user=u).save()
        url = urlify(u'delicious soup', author)
        recipe.Recipe(name=u'delicious soup', author=author, urlKey=url, user=u).save()

        qs = recipe.Recipe.objects()
        expected = ('[{"recipeYield": null, "tags": [], "name": "delicious sandwich", "author": "cory", "instructions": [], "ingredients": [], "urlKey": "delicious-sandwich-cory-", "user": {"roles": [], "givenName": null, "email": "*****@*****.**", "familyName": null}}, ' 
                     '{"recipeYield": null, "tags": [], "name": "delicious soup", "author": "cory", "instructions": [], "ingredients": [], "urlKey": "delicious-soup-cory-", "user": {"roles": [], "givenName": null, "email": "*****@*****.**", "familyName": null}}]')
        assert rendering.RenderableQuerySet(qs).render(None) == expected
示例#5
0
文件: recipe.py 项目: corydodt/Noms
    def fromMicrodata(cls, microdata, userEmail): 
        """ 
        Create a recipe object from microdata
        """ 
        self = cls()
        self.name = clean(microdata.name)
        self.author = clean(microdata.author.name) 
        self.user = User.objects(email=userEmail).first()
        self.urlKey = urlify(self.user.email, self.name)
        for i in microdata.props['ingredients']: 
            self.ingredients.append(clean(i))

        array = microdata.props['recipeInstructions'][0].split('\n')
        for i in array: 
            i = clean(i)
            if i: 
                self.instructions.append(i)
        return self 
示例#6
0
文件: server.py 项目: corydodt/Noms
    def createRecipeSave(self, request): # pragma: nocover
                                         # I suspect this is going to
                                         # drastically change when the chrome
                                         # extension branch lands, so i'm not
                                         # testing it.
        """
        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.author = data['author']
        recipe.urlKey = urlify(recipe.user, recipe.name)
        for i in data['ingredients']:
            recipe.ingredients.append(i)
        for i in data['instructions']:
            recipe.instructions.append(i)

        recipe.save()
示例#7
0
    def fromMicrodata(cls, microdata, userEmail):
        """
        Create a recipe object from microdata
        """
        self = cls()
        self.name = clean(microdata.name)
        if microdata.author:
            self.author = clean(microdata.author.name)
        else:
            self.author = USER().anonymous.givenName
        self.user = User.objects.get(email=userEmail)
        self.urlKey = urlify(self.user.email, self.name)
        for i in microdata.props['ingredients']:
            self.ingredients.append(clean(i))

        array = microdata.props['recipeInstructions'][0].split('\n')
        for i in array:
            i = clean(i)
            if i:
                self.instructions.append(i)
        return self
示例#8
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)
示例#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() 
示例#10
0
def test_urlify():
    """
    Do I produce punycode output for the inputs?
    """
    helloThere = u'你好'
    assert urlify(u'asdf', helloThere, u'69') == 'asdf--69-nm2mf94f'
示例#11
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()