Esempio n. 1
0
 def handle(self, *args, **options):
     if not options['menu'] and not options['recipes']:
         raise CommandError(
             "Please provide a menu name or a list or recipes.")
     if options['menu']:
         if options['recipes']:
             raise CommandError(
                 "Please provide a menu name or a list of recipes, but not both."
             )
         menu = Menu.objects.get(name__contains=options['menu'])
         if options['servings']:
             menu.servings = options['servings']
         menu.cooking_view()
     else:
         try:
             recipes = [
                 Recipe.get_by_name(name, ask_which=True)
                 for name in options['recipes']
             ]
         except (Recipe.DoesNotExist, Recipe.MultipleObjectsReturned) as e:
             raise CommandError(e)
         tempMenu = Menu(name="Menu", servings=options['servings'] or 1)
         tempMenu.save()
         tempMenu.recipes.set(recipes)
         tempMenu.cooking_view()
         tempMenu.delete()
Esempio n. 2
0
 def import_menu(self, data):
     r = [
         Recipe.get_by_name(name, ask_which=True)
         for name in data['recipes']
     ]
     self.m = Menu(name=data['name'], servings=data['servings'])
     self.m.save()
     self.m.recipes.set(r)
     self.log.info("Created menu {}".format(self.m))
Esempio n. 3
0
 def handle(self, *args, **options):
     try:
         menu = Menu(name=options['name'], servings=options['servings'])
         menu.save()
         for recipe_name in options['recipes']:
             menu.recipes.add(Recipe.get_by_name(recipe_name))
     except (Recipe.DoesNotExist, Recipe.MultipleObjectsReturned):
         menu.delete()
         raise CommandError("No recipe with name '{}'".format(recipe_name))
     except Recipe.MultipleObjectsReturned:
         menu.delete()
         raise CommandError(
             "Multiple recipes matched name '{}'".format(recipe_name))