added share functionality. changed random recipe selection to prevent repeating duplicate choices.
This commit is contained in:
parent
ac17b84a7a
commit
df684f591a
@ -675,6 +675,11 @@ class AutoPlanViewSet(viewsets.ViewSet):
|
|||||||
end_date = serializer.validated_data['end_date']
|
end_date = serializer.validated_data['end_date']
|
||||||
meal_type = MealType.objects.get(pk=serializer.validated_data['meal_type_id'])
|
meal_type = MealType.objects.get(pk=serializer.validated_data['meal_type_id'])
|
||||||
servings = serializer.validated_data['servings']
|
servings = serializer.validated_data['servings']
|
||||||
|
shared = serializer.get_initial().get('shared', None)
|
||||||
|
shared_pks = list()
|
||||||
|
if shared is not None:
|
||||||
|
for i in range(len(shared)):
|
||||||
|
shared_pks.append(shared[i]['id'])
|
||||||
|
|
||||||
days = (end_date - start_date).days + 1
|
days = (end_date - start_date).days + 1
|
||||||
recipes = Recipe.objects.all()
|
recipes = Recipe.objects.all()
|
||||||
@ -688,7 +693,7 @@ class AutoPlanViewSet(viewsets.ViewSet):
|
|||||||
|
|
||||||
for i in range(0, days):
|
for i in range(0, days):
|
||||||
day = start_date + datetime.timedelta(i)
|
day = start_date + datetime.timedelta(i)
|
||||||
recipe = random.choice(recipes)
|
recipe = recipes[i % len(recipes)]
|
||||||
args = {'recipe': recipe, 'servings': servings, 'title': recipe.name,
|
args = {'recipe': recipe, 'servings': servings, 'title': recipe.name,
|
||||||
'created_by': request.user,
|
'created_by': request.user,
|
||||||
'meal_type': meal_type,
|
'meal_type': meal_type,
|
||||||
@ -698,7 +703,10 @@ class AutoPlanViewSet(viewsets.ViewSet):
|
|||||||
meal_plans.append(m)
|
meal_plans.append(m)
|
||||||
|
|
||||||
MealPlan.objects.bulk_create(meal_plans)
|
MealPlan.objects.bulk_create(meal_plans)
|
||||||
|
|
||||||
for m in meal_plans:
|
for m in meal_plans:
|
||||||
|
m.shared.set(shared_pks)
|
||||||
|
|
||||||
if request.data.get('addshopping', False) and request.data.get('recipe', None):
|
if request.data.get('addshopping', False) and request.data.get('recipe', None):
|
||||||
SLR = RecipeShoppingEditor(user=request.user, space=request.space)
|
SLR = RecipeShoppingEditor(user=request.user, space=request.space)
|
||||||
SLR.create(mealplan=m, servings=servings)
|
SLR.create(mealplan=m, servings=servings)
|
||||||
|
@ -371,7 +371,8 @@ export default {
|
|||||||
servings: 1,
|
servings: 1,
|
||||||
date: Date.now(),
|
date: Date.now(),
|
||||||
startDay: null,
|
startDay: null,
|
||||||
endDay: null
|
endDay: null,
|
||||||
|
shared: []
|
||||||
},
|
},
|
||||||
showDate: new Date(),
|
showDate: new Date(),
|
||||||
plan_entries: [],
|
plan_entries: [],
|
||||||
|
@ -32,6 +32,21 @@
|
|||||||
<b-form-input class="w-25 m-2 mb-0" :value = "AutoPlan.servings" :type="'number'" @input="updateServings"></b-form-input>
|
<b-form-input class="w-25 m-2 mb-0" :value = "AutoPlan.servings" :type="'number'" @input="updateServings"></b-form-input>
|
||||||
<small tabindex="-1" class="m-2 mt-0 form-text text-muted">{{ $t("Servings") }}</small>
|
<small tabindex="-1" class="m-2 mt-0 form-text text-muted">{{ $t("Servings") }}</small>
|
||||||
</div>
|
</div>
|
||||||
|
<b-form-group class="mt-3">
|
||||||
|
<generic-multiselect
|
||||||
|
required
|
||||||
|
@change="AutoPlan.shared = $event.val"
|
||||||
|
parent_variable="entryEditing.shared"
|
||||||
|
:label="'display_name'"
|
||||||
|
:model="Models.USER_NAME"
|
||||||
|
style="flex-grow: 1; flex-shrink: 1; flex-basis: 0"
|
||||||
|
v-bind:placeholder="$t('Share')"
|
||||||
|
:limit="10"
|
||||||
|
:multiple="true"
|
||||||
|
:initial_selection="AutoPlan.shared"
|
||||||
|
></generic-multiselect>
|
||||||
|
<small tabindex="-1" class="form-text text-muted">{{ $t("Share") }}</small>
|
||||||
|
</b-form-group>
|
||||||
|
|
||||||
<div class="">
|
<div class="">
|
||||||
<div class="row m-3 mb-0">
|
<div class="row m-3 mb-0">
|
||||||
@ -61,6 +76,7 @@ import Vue from "vue"
|
|||||||
import {BootstrapVue} from "bootstrap-vue"
|
import {BootstrapVue} from "bootstrap-vue"
|
||||||
import GenericMultiselect from "@/components/GenericMultiselect"
|
import GenericMultiselect from "@/components/GenericMultiselect"
|
||||||
import {ApiMixin} from "@/utils/utils"
|
import {ApiMixin} from "@/utils/utils"
|
||||||
|
import {useUserPreferenceStore} from "@/stores/UserPreferenceStore";
|
||||||
|
|
||||||
const { ApiApiFactory } = require("@/utils/openapi/api")
|
const { ApiApiFactory } = require("@/utils/openapi/api")
|
||||||
const { StandardToasts } = require("@/utils/utils")
|
const { StandardToasts } = require("@/utils/utils")
|
||||||
@ -89,7 +105,8 @@ export default {
|
|||||||
servings: 1,
|
servings: 1,
|
||||||
date: Date.now(),
|
date: Date.now(),
|
||||||
startDay: null,
|
startDay: null,
|
||||||
endDay: null
|
endDay: null,
|
||||||
|
shared: []
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@ -104,6 +121,9 @@ export default {
|
|||||||
this.AutoPlan.servings = 1
|
this.AutoPlan.servings = 1
|
||||||
this.AutoPlan.startDay = new Date()
|
this.AutoPlan.startDay = new Date()
|
||||||
this.AutoPlan.endDay = this.current_period.periodEnd
|
this.AutoPlan.endDay = this.current_period.periodEnd
|
||||||
|
useUserPreferenceStore().getData().then(userPreference => {
|
||||||
|
this.AutoPlan.shared = userPreference.plan_share
|
||||||
|
})
|
||||||
},
|
},
|
||||||
sortMealTypes() {
|
sortMealTypes() {
|
||||||
this.meal_types.forEach(function (element, index) {
|
this.meal_types.forEach(function (element, index) {
|
||||||
|
Loading…
Reference in New Issue
Block a user