Added export from url args

This commit is contained in:
Tiago Rascazzi
2022-01-08 13:37:26 -05:00
parent 68eccd3c05
commit 7c48c13dce
3 changed files with 24 additions and 8 deletions

View File

@@ -24,7 +24,7 @@
<script type="application/javascript"> <script type="application/javascript">
window.EXPORT_ID = {{pk}}; window.EXPORT_ID = {{pk}};
window.CUSTOM_LOCALE = '{{ request.LANGUAGE_CODE }}' window.CUSTOM_LOCALE = '{{ request.LANGUAGE_CODE }}';
</script> </script>
{% render_bundle 'export_view' %} {% render_bundle 'export_view' %}

View File

@@ -143,14 +143,12 @@ def export_recipe(request):
) )
else: else:
form = ExportForm(space=request.space)
recipe = request.GET.get('r') recipe = request.GET.get('r')
if recipe: if recipe:
if re.match(r'^([0-9])+$', recipe): if re.match(r'^([0-9])+$', recipe):
if recipe := Recipe.objects.filter(pk=int(recipe), space=request.space).first(): recipe = Recipe.objects.filter(pk=int(recipe), space=request.space).first()
form = ExportForm(initial={'recipes': recipe}, space=request.space)
return render(request, 'export.html', {'form': form}) return render(request, 'export.html', {'pk': recipe.pk})
@group_required('user') @group_required('user')

View File

@@ -93,8 +93,7 @@ export default {
components: {Multiselect}, components: {Multiselect},
data() { data() {
return { return {
import_id: window.EXPORT_ID, export_id: window.EXPORT_ID,
import_info: undefined,
loading: false, loading: false,
disabled_multiselect: false, disabled_multiselect: false,
@@ -107,11 +106,29 @@ export default {
}, },
mounted() { mounted() {
this.searchRecipes('') this.insertRequested()
}, },
methods: { 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) { searchRecipes: function (query) {
let apiFactory = new ApiApiFactory() let apiFactory = new ApiApiFactory()
this.recipes_loading = true 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) => { 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 = response.data.results;
this.recipes_loading = false this.recipes_loading = false
}).catch((err) => { }).catch((err) => {
console.log(err) console.log(err)
StandardToasts.makeStandardToast(StandardToasts.FAIL_FETCH) StandardToasts.makeStandardToast(StandardToasts.FAIL_FETCH)