basic importing working
This commit is contained in:
parent
8cca272bb9
commit
976dd13a31
@ -113,7 +113,12 @@
|
||||
|
||||
<div class="form-group">
|
||||
<label for="id_all_keywords">{% trans 'All Keywords' %}</label><br/>
|
||||
<input id="id_all_keywords" type="checkbox" v-model="all_keywords"> {% trans 'Import all Keywords not only the ones already existing.' %}
|
||||
<input id="id_all_keywords" type="checkbox"
|
||||
v-model="all_keywords"> {% trans 'Import all Keywords not only the ones already existing.' %}
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<button type="button" @click="importRecipe()">{% trans 'Import' %}</button>
|
||||
</div>
|
||||
|
||||
<br/>
|
||||
@ -158,13 +163,42 @@
|
||||
console.log(err)
|
||||
})
|
||||
},
|
||||
importRecipe: function () {
|
||||
|
||||
let recipe_keywords = []
|
||||
for (k of this.recipe_data.keywords) {
|
||||
if (k.id !== "null") {
|
||||
recipe_keywords.push(Number.parseInt(k.id))
|
||||
}
|
||||
//TODO create non existent if checked
|
||||
}
|
||||
|
||||
let recipe = {
|
||||
name: this.recipe_data.name,
|
||||
instructions: this.recipe_data.recipeInstructions,
|
||||
keywords: recipe_keywords,
|
||||
created_by: {{ request.user.pk }},
|
||||
}
|
||||
|
||||
this.$http.post(`{% url 'api:recipe-list' %}`, recipe).then((response) => {
|
||||
let entry = response.data
|
||||
console.log(entry)
|
||||
|
||||
//TODO create some kind of endpoint for ingredients, units and recipe ingredients creation
|
||||
|
||||
location.href = "{% url 'view_recipe' 12345 %}".replace(/12345/, entry.id)
|
||||
}).catch((err) => {
|
||||
console.log("dragChanged create error", err);
|
||||
})
|
||||
|
||||
},
|
||||
getKeywords: function () {
|
||||
this.$http.get("{% url 'dal_keyword' %}").then((response) => {
|
||||
this.keywords = response.data.results;
|
||||
}).catch((err) => {
|
||||
console.log(err)
|
||||
})
|
||||
}
|
||||
},
|
||||
}
|
||||
});
|
||||
</script>
|
||||
|
@ -11,6 +11,8 @@ from cookbook.helper import dal
|
||||
router = routers.DefaultRouter()
|
||||
router.register(r'user-preference', api.UserPreferenceViewSet)
|
||||
router.register(r'recipe', api.RecipeViewSet)
|
||||
router.register(r'ingredient', api.IngredientViewSet)
|
||||
router.register(r'recipe-ingredient', api.RecipeIngredientSerializer)
|
||||
router.register(r'meal-plan', api.MealPlanViewSet)
|
||||
router.register(r'meal-type', api.MealTypeViewSet)
|
||||
router.register(r'view-log', api.ViewLogViewSet)
|
||||
|
@ -18,12 +18,12 @@ from rest_framework import viewsets, permissions
|
||||
from rest_framework.exceptions import APIException
|
||||
from rest_framework.mixins import RetrieveModelMixin, UpdateModelMixin, ListModelMixin
|
||||
|
||||
from cookbook.helper.permission_helper import group_required, CustomIsOwner, CustomIsAdmin
|
||||
from cookbook.helper.permission_helper import group_required, CustomIsOwner, CustomIsAdmin, CustomIsUser
|
||||
from cookbook.helper.recipe_url_import import find_recipe_json
|
||||
from cookbook.models import Recipe, Sync, Storage, CookLog, MealPlan, MealType, ViewLog, UserPreference, RecipeBook, Keyword
|
||||
from cookbook.models import Recipe, Sync, Storage, CookLog, MealPlan, MealType, ViewLog, UserPreference, RecipeBook, Keyword, RecipeIngredient, Ingredient
|
||||
from cookbook.provider.dropbox import Dropbox
|
||||
from cookbook.provider.nextcloud import Nextcloud
|
||||
from cookbook.serializer import MealPlanSerializer, MealTypeSerializer, RecipeSerializer, ViewLogSerializer, UserNameSerializer, UserPreferenceSerializer, RecipeBookSerializer
|
||||
from cookbook.serializer import MealPlanSerializer, MealTypeSerializer, RecipeSerializer, ViewLogSerializer, UserNameSerializer, UserPreferenceSerializer, RecipeBookSerializer, RecipeIngredientSerializer, IngredientSerializer
|
||||
|
||||
|
||||
class UserNameViewSet(viewsets.ModelViewSet):
|
||||
@ -122,7 +122,7 @@ class RecipeViewSet(viewsets.ModelViewSet):
|
||||
"""
|
||||
queryset = Recipe.objects.all()
|
||||
serializer_class = RecipeSerializer
|
||||
permission_classes = [permissions.IsAuthenticated]
|
||||
permission_classes = [permissions.IsAuthenticated] # TODO split read and write permission for meal plan guest
|
||||
|
||||
def get_queryset(self):
|
||||
queryset = Recipe.objects.all()
|
||||
@ -136,6 +136,18 @@ class RecipeViewSet(viewsets.ModelViewSet):
|
||||
return queryset
|
||||
|
||||
|
||||
class RecipeIngredientViewSet(viewsets.ModelViewSet):
|
||||
queryset = RecipeIngredient.objects.all()
|
||||
serializer_class = RecipeIngredientSerializer
|
||||
permission_classes = [CustomIsUser]
|
||||
|
||||
|
||||
class IngredientViewSet(viewsets.ModelViewSet):
|
||||
queryset = Ingredient.objects.all()
|
||||
serializer_class = IngredientSerializer
|
||||
permission_classes = [CustomIsUser]
|
||||
|
||||
|
||||
class ViewLogViewSet(viewsets.ModelViewSet):
|
||||
queryset = ViewLog.objects.all()
|
||||
serializer_class = ViewLogSerializer
|
||||
|
Loading…
Reference in New Issue
Block a user