From 16b357e11e512b1e55e119fb7117bef357db0e8c Mon Sep 17 00:00:00 2001 From: Tiago Rascazzi Date: Sat, 8 Jan 2022 14:44:28 -0500 Subject: [PATCH] Added printReady selector --- cookbook/integration/pdfexport.py | 2 +- cookbook/views/import_export.py | 5 +++-- vue/src/apps/ExportView/ExportView.vue | 7 ++++--- vue/src/apps/RecipeView/RecipeView.vue | 13 ++++++++++++- 4 files changed, 20 insertions(+), 7 deletions(-) diff --git a/cookbook/integration/pdfexport.py b/cookbook/integration/pdfexport.py index 9f500480..20c948a3 100644 --- a/cookbook/integration/pdfexport.py +++ b/cookbook/integration/pdfexport.py @@ -51,7 +51,7 @@ class PDFexport(Integration): await page.setCookie(cookies) await page.goto('http://'+cmd.default_addr+':'+cmd.default_port+'/view/recipe/'+str(recipe.id), {'waitUntil': 'domcontentloaded'}) - await page.waitForSelector('h3'); + await page.waitForSelector('#printReady'); files.append([recipe.name + '.pdf', await page.pdf(options)]) await page.close(); diff --git a/cookbook/views/import_export.py b/cookbook/views/import_export.py index 6e0a7b3e..9d8fec20 100644 --- a/cookbook/views/import_export.py +++ b/cookbook/views/import_export.py @@ -143,12 +143,13 @@ def export_recipe(request): ) else: + pk = '' recipe = request.GET.get('r') if recipe: if re.match(r'^([0-9])+$', recipe): - recipe = Recipe.objects.filter(pk=int(recipe), space=request.space).first() + pk = Recipe.objects.filter(pk=int(recipe), space=request.space).first().pk - return render(request, 'export.html', {'pk': recipe.pk}) + return render(request, 'export.html', {'pk': pk}) @group_required('user') diff --git a/vue/src/apps/ExportView/ExportView.vue b/vue/src/apps/ExportView/ExportView.vue index efe0538b..5db26da2 100644 --- a/vue/src/apps/ExportView/ExportView.vue +++ b/vue/src/apps/ExportView/ExportView.vue @@ -105,9 +105,10 @@ export default { } }, mounted() { - - this.insertRequested() - + if(this.export_id) + this.insertRequested() + else + this.searchRecipes('') }, methods: { diff --git a/vue/src/apps/RecipeView/RecipeView.vue b/vue/src/apps/RecipeView/RecipeView.vue index 7cf1932a..f4c25cd3 100644 --- a/vue/src/apps/RecipeView/RecipeView.vue +++ b/vue/src/apps/RecipeView/RecipeView.vue @@ -107,7 +107,7 @@
- +
@@ -246,6 +246,9 @@ export default { this.start_time = moment().format("yyyy-MM-DDTHH:mm") } + + if(recipe.image === null) this.printReady() + this.recipe = this.rootrecipe = recipe this.servings = this.servings_cache[this.rootrecipe.id] = recipe.servings this.loading = false @@ -272,6 +275,14 @@ export default { this.servings = this.servings_cache?.[e.id] ?? e.servings } }, + printReady: function(){ + const template = document.createElement("template"); + template.id = "printReady"; + document.body.appendChild(template); + }, + onImgLoad: function(){ + this.printReady() + }, }, }