Added Saffron export format

This commit is contained in:
Tiago Rascazzi 2022-01-03 13:28:21 -05:00
parent 56ee5671ea
commit 0aafd8d8b2
4 changed files with 53 additions and 7 deletions

View File

@ -140,7 +140,7 @@ class ImportExportBase(forms.Form):
NEXTCLOUD = 'NEXTCLOUD' NEXTCLOUD = 'NEXTCLOUD'
MEALIE = 'MEALIE' MEALIE = 'MEALIE'
CHOWDOWN = 'CHOWDOWN' CHOWDOWN = 'CHOWDOWN'
SAFRON = 'SAFRON' SAFFRON = 'SAFFRON'
CHEFTAP = 'CHEFTAP' CHEFTAP = 'CHEFTAP'
PEPPERPLATE = 'PEPPERPLATE' PEPPERPLATE = 'PEPPERPLATE'
RECIPEKEEPER = 'RECIPEKEEPER' RECIPEKEEPER = 'RECIPEKEEPER'
@ -157,7 +157,7 @@ class ImportExportBase(forms.Form):
type = forms.ChoiceField(choices=( type = forms.ChoiceField(choices=(
(DEFAULT, _('Default')), (PAPRIKA, 'Paprika'), (NEXTCLOUD, 'Nextcloud Cookbook'), (DEFAULT, _('Default')), (PAPRIKA, 'Paprika'), (NEXTCLOUD, 'Nextcloud Cookbook'),
(MEALIE, 'Mealie'), (CHOWDOWN, 'Chowdown'), (SAFRON, 'Safron'), (CHEFTAP, 'ChefTap'), (MEALIE, 'Mealie'), (CHOWDOWN, 'Chowdown'), (SAFFRON, 'Saffron'), (CHEFTAP, 'ChefTap'),
(PEPPERPLATE, 'Pepperplate'), (RECETTETEK, 'RecetteTek'), (RECIPESAGE, 'Recipe Sage'), (DOMESTICA, 'Domestica'), (PEPPERPLATE, 'Pepperplate'), (RECETTETEK, 'RecetteTek'), (RECIPESAGE, 'Recipe Sage'), (DOMESTICA, 'Domestica'),
(MEALMASTER, 'MealMaster'), (REZKONV, 'RezKonv'), (OPENEATS, 'Openeats'), (RECIPEKEEPER, 'Recipe Keeper'), (MEALMASTER, 'MealMaster'), (REZKONV, 'RezKonv'), (OPENEATS, 'Openeats'), (RECIPEKEEPER, 'Recipe Keeper'),
(PLANTOEAT, 'Plantoeat'), (COOKBOOKAPP, 'CookBookApp'), (COPYMETHAT, 'CopyMeThat'), (PDF, 'PDF'), (PLANTOEAT, 'Plantoeat'), (COOKBOOKAPP, 'CookBookApp'), (COPYMETHAT, 'CopyMeThat'), (PDF, 'PDF'),

View File

@ -262,6 +262,17 @@ class Integration:
""" """
raise NotImplementedError('Method not implemented in integration') raise NotImplementedError('Method not implemented in integration')
def get_files_from_recipes(self, recipes, cookie):
"""
Takes a list of recipe object and converts it to a array containing each file.
Each file is represented as an array [filename, data] where data is a string of the content of the file.
:param recipe: Recipe object that should be converted
:returns:
[[filename, data], ...]
"""
raise NotImplementedError('Method not implemented in integration')
@staticmethod @staticmethod
def handle_exception(exception, log=None, message=''): def handle_exception(exception, log=None, message=''):
if log: if log:

View File

@ -5,7 +5,7 @@ from cookbook.integration.integration import Integration
from cookbook.models import Recipe, Step, Ingredient from cookbook.models import Recipe, Step, Ingredient
class Safron(Integration): class Saffron(Integration):
def get_recipe_from_file(self, file): def get_recipe_from_file(self, file):
ingredient_mode = False ingredient_mode = False
@ -58,4 +58,39 @@ class Safron(Integration):
return recipe return recipe
def get_file_from_recipe(self, recipe): def get_file_from_recipe(self, recipe):
raise NotImplementedError('Method not implemented in storage integration')
data = "Title: "+recipe.name if recipe.name else ""+"\n"
data += "Description: "+recipe.description if recipe.description else ""+"\n"
data += "Source: \n"
data += "Original URL: \n"
data += "Yield: "+str(recipe.servings)+"\n"
data += "Cookbook: \n"
data += "Section: \n"
data += "Image: \n"
recipeInstructions = []
recipeIngredient = []
for s in recipe.steps.all():
if s.type != Step.TIME:
recipeInstructions.append(s.instruction)
for i in s.ingredients.all():
recipeIngredient.append(f'{float(i.amount)} {i.unit} {i.food}')
data += "Ingredients: \n"
for ingredient in recipeIngredient:
data += ingredient+"\n"
data += "Instructions: \n"
for instruction in recipeInstructions:
data += instruction+"\n"
return recipe.name+'.txt', data
def get_files_from_recipes(self, recipes, cookie):
files = []
for r in recipes:
filename, data = self.get_file_from_recipe(r)
files.append([ filename, data ])
return files

View File

@ -27,7 +27,7 @@ from cookbook.integration.recipekeeper import RecipeKeeper
from cookbook.integration.recettetek import RecetteTek from cookbook.integration.recettetek import RecetteTek
from cookbook.integration.recipesage import RecipeSage from cookbook.integration.recipesage import RecipeSage
from cookbook.integration.rezkonv import RezKonv from cookbook.integration.rezkonv import RezKonv
from cookbook.integration.safron import Safron from cookbook.integration.saffron import Saffron
from cookbook.integration.pdfexport import PDFexport from cookbook.integration.pdfexport import PDFexport
from cookbook.models import Recipe, ImportLog, UserPreference from cookbook.models import Recipe, ImportLog, UserPreference
@ -43,8 +43,8 @@ def get_integration(request, export_type):
return Mealie(request, export_type) return Mealie(request, export_type)
if export_type == ImportExportBase.CHOWDOWN: if export_type == ImportExportBase.CHOWDOWN:
return Chowdown(request, export_type) return Chowdown(request, export_type)
if export_type == ImportExportBase.SAFRON: if export_type == ImportExportBase.SAFFRON:
return Safron(request, export_type) return Saffron(request, export_type)
if export_type == ImportExportBase.CHEFTAP: if export_type == ImportExportBase.CHEFTAP:
return ChefTap(request, export_type) return ChefTap(request, export_type)
if export_type == ImportExportBase.PEPPERPLATE: if export_type == ImportExportBase.PEPPERPLATE: