create default step + view time improvement

This commit is contained in:
vabene1111 2020-07-08 21:23:41 +02:00
parent b490673866
commit 1d2976b687
2 changed files with 7 additions and 5 deletions

View File

@ -233,7 +233,7 @@
{% endif %} {% endif %}
{% if s.name %}{{ s.name }}{% else %}{% trans 'Step' %} {% if s.name %}{{ s.name }}{% else %}{% trans 'Step' %}
{{ forloop.counter }}{% endif %} {{ forloop.counter }}{% endif %}
{% if s.type == 'TIME' %} {% if s.time != 0 %}
- {{ s.time }} {% trans 'Minutes' %} - {{ s.time }} {% trans 'Minutes' %}
{% endif %} {% endif %}
</div> </div>
@ -242,11 +242,8 @@
@change="updateTimes(recipe.steps[{{ forloop.counter0 }}])" @change="updateTimes(recipe.steps[{{ forloop.counter0 }}])"
v-model="recipe.steps[{{ forloop.counter0 }}].time_finished"> v-model="recipe.steps[{{ forloop.counter0 }}].time_finished">
</div> </div>
</div> </div>
</div> </div>
</div> </div>
<div class="row" v-if="recipe.steps[{{ forloop.counter0 }}].ingredients.length > 0" <div class="row" v-if="recipe.steps[{{ forloop.counter0 }}].ingredients.length > 0"
@ -471,6 +468,7 @@
data: { data: {
recipe: undefined, recipe: undefined,
has_ingredients: false, has_ingredients: false,
has_times: false,
ingredient_factor: 1, ingredient_factor: 1,
}, },
@ -487,6 +485,9 @@
if (step.ingredients.length > 0) { if (step.ingredients.length > 0) {
this.has_ingredients = true this.has_ingredients = true
} }
if (step.time !== 0) {
this.has_times = true
}
this.$set(step, 'time_finished', undefined) this.$set(step, 'time_finished', undefined)
for (let i of step.ingredients) { for (let i of step.ingredients) {
this.$set(i, 'checked', false) this.$set(i, 'checked', false)

View File

@ -11,7 +11,7 @@ from django.views.generic import CreateView
from cookbook.forms import ImportRecipeForm, RecipeImport, KeywordForm, Storage, StorageForm, InternalRecipeForm, \ from cookbook.forms import ImportRecipeForm, RecipeImport, KeywordForm, Storage, StorageForm, InternalRecipeForm, \
RecipeBookForm, MealPlanForm RecipeBookForm, MealPlanForm
from cookbook.helper.permission_helper import GroupRequiredMixin, group_required from cookbook.helper.permission_helper import GroupRequiredMixin, group_required
from cookbook.models import Keyword, Recipe, RecipeBook, MealPlan, ShareLink, MealType from cookbook.models import Keyword, Recipe, RecipeBook, MealPlan, ShareLink, MealType, Step
class RecipeCreate(GroupRequiredMixin, CreateView): class RecipeCreate(GroupRequiredMixin, CreateView):
@ -25,6 +25,7 @@ class RecipeCreate(GroupRequiredMixin, CreateView):
obj.created_by = self.request.user obj.created_by = self.request.user
obj.internal = True obj.internal = True
obj.save() obj.save()
obj.steps.add(Step.objects.create())
return HttpResponseRedirect(reverse('edit_recipe', kwargs={'pk': obj.pk})) return HttpResponseRedirect(reverse('edit_recipe', kwargs={'pk': obj.pk}))
def get_success_url(self): def get_success_url(self):