From 7c48c13dce07d8590e64bb1ba92570c64658a2ab Mon Sep 17 00:00:00 2001 From: Tiago Rascazzi Date: Sat, 8 Jan 2022 13:37:26 -0500 Subject: [PATCH] Added export from url args --- cookbook/templates/export.html | 2 +- cookbook/views/import_export.py | 6 ++---- vue/src/apps/ExportView/ExportView.vue | 24 +++++++++++++++++++++--- 3 files changed, 24 insertions(+), 8 deletions(-) diff --git a/cookbook/templates/export.html b/cookbook/templates/export.html index ca5148235..787fc81c0 100644 --- a/cookbook/templates/export.html +++ b/cookbook/templates/export.html @@ -24,7 +24,7 @@ {% render_bundle 'export_view' %} diff --git a/cookbook/views/import_export.py b/cookbook/views/import_export.py index c1530b000..6e0a7b3ed 100644 --- a/cookbook/views/import_export.py +++ b/cookbook/views/import_export.py @@ -143,14 +143,12 @@ def export_recipe(request): ) else: - form = ExportForm(space=request.space) recipe = request.GET.get('r') if recipe: if re.match(r'^([0-9])+$', recipe): - if recipe := Recipe.objects.filter(pk=int(recipe), space=request.space).first(): - form = ExportForm(initial={'recipes': recipe}, space=request.space) + recipe = Recipe.objects.filter(pk=int(recipe), space=request.space).first() - return render(request, 'export.html', {'form': form}) + return render(request, 'export.html', {'pk': recipe.pk}) @group_required('user') diff --git a/vue/src/apps/ExportView/ExportView.vue b/vue/src/apps/ExportView/ExportView.vue index 160cbe9e2..efe0538be 100644 --- a/vue/src/apps/ExportView/ExportView.vue +++ b/vue/src/apps/ExportView/ExportView.vue @@ -93,8 +93,7 @@ export default { components: {Multiselect}, data() { return { - import_id: window.EXPORT_ID, - import_info: undefined, + export_id: window.EXPORT_ID, loading: false, disabled_multiselect: false, @@ -107,11 +106,29 @@ export default { }, mounted() { - this.searchRecipes('') + this.insertRequested() + }, methods: { + insertRequested: function(){ + + let apiFactory = new ApiApiFactory() + + this.recipes_loading = true + + apiFactory.retrieveRecipe(this.export_id).then((response) => { + this.recipes_loading = false + this.recipe_list.push(response.data) + + }).catch((err) => { + console.log(err) + StandardToasts.makeStandardToast(StandardToasts.FAIL_FETCH) + }).then(e => this.searchRecipes('')) + }, + searchRecipes: function (query) { + let apiFactory = new ApiApiFactory() this.recipes_loading = true @@ -120,6 +137,7 @@ export default { apiFactory.listRecipes(query, undefined, undefined, undefined, undefined, undefined, undefined, undefined, undefined, undefined, undefined, undefined, 1, maxResultLenght).then((response) => { this.recipes = response.data.results; this.recipes_loading = false + }).catch((err) => { console.log(err) StandardToasts.makeStandardToast(StandardToasts.FAIL_FETCH)