fixed commas + desktop flex design

This commit is contained in:
vabene1111 2020-06-29 12:27:54 +02:00
parent 3a2ba773cf
commit 8b9c7daaae
2 changed files with 35 additions and 17 deletions

View File

@ -1,13 +1,31 @@
from django.contrib.auth.models import User from django.contrib.auth.models import User
from drf_writable_nested import WritableNestedModelSerializer, UniqueFieldsMixin from drf_writable_nested import WritableNestedModelSerializer, UniqueFieldsMixin
from rest_framework import serializers from rest_framework import serializers
from rest_framework.exceptions import APIException from rest_framework.exceptions import APIException, ValidationError
from rest_framework.fields import CurrentUserDefault from rest_framework.fields import CurrentUserDefault
from cookbook.models import MealPlan, MealType, Recipe, ViewLog, UserPreference, Storage, Sync, SyncLog, Keyword, Unit, Ingredient, Comment, RecipeImport, RecipeBook, RecipeBookEntry, ShareLink, CookLog, Food, Step from cookbook.models import MealPlan, MealType, Recipe, ViewLog, UserPreference, Storage, Sync, SyncLog, Keyword, Unit, Ingredient, Comment, RecipeImport, RecipeBook, RecipeBookEntry, ShareLink, CookLog, Food, Step
from cookbook.templatetags.custom_tags import markdown from cookbook.templatetags.custom_tags import markdown
class CustomDecimalField(serializers.Field):
"""
Custom decimal field to normalize useless decimal places and allow commas as decimal separators
"""
def to_representation(self, value):
return value.normalize()
def to_internal_value(self, data):
if type(data) == int or type(data) == float:
return data
elif type(data) == str:
try:
return float(data.replace(',', ''))
except ValueError:
raise ValidationError('A valid number is required')
class UserNameSerializer(serializers.ModelSerializer): class UserNameSerializer(serializers.ModelSerializer):
class Meta: class Meta:
model = User model = User
@ -60,10 +78,11 @@ class FoodSerializer(UniqueFieldsMixin, serializers.ModelSerializer):
class IngredientSerializer(WritableNestedModelSerializer): class IngredientSerializer(WritableNestedModelSerializer):
food = FoodSerializer() food = FoodSerializer()
unit = UnitSerializer() unit = UnitSerializer()
amount = CustomDecimalField()
class Meta: class Meta:
model = Ingredient model = Ingredient
fields = '__all__' fields = ('id', 'food', 'unit', 'amount', 'note', 'order')
class StepSerializer(WritableNestedModelSerializer): class StepSerializer(WritableNestedModelSerializer):

View File

@ -88,7 +88,7 @@
<div class="row"> <div class="row">
<div class="col-md-12" style="margin-top: 12px"> <div class="col-md-12" style="margin-top: 12px">
<div class="row" style="text-align: center"> <!--<div class="row" style="text-align: center">
<div class="col-md-1 no-gutters"> <div class="col-md-1 no-gutters">
<b><i class="fas fa-arrows-alt-v"></i></b> <b><i class="fas fa-arrows-alt-v"></i></b>
</div> </div>
@ -107,22 +107,21 @@
<div class="col-md-1"> <div class="col-md-1">
<i class="fa fa-trash"></i> <i class="fa fa-trash"></i>
</div> </div>
</div> </div>-->
<draggable :list="step.ingredients" group="ingredients" <draggable :list="step.ingredients" group="ingredients"
:empty-insert-threshold="10" handle=".handle" @sort="sortStep(step)"> :empty-insert-threshold="10" handle=".handle" @sort="sortStep(step)">
<div class="card" v-for="ingredient, index in step.ingredients" :key="ingredient.id" <div class="col-md-12" v-for="ingredient, index in step.ingredients" :key="ingredient.id"
style="margin-top: 8px"> style="margin-top: 8px">
<div class="card-body" style="padding: 8px"> <div class="d-flex align-items-center ">
<div class="row d-flex"> <div class="flex-grow-0">
<div class="col-md-1 small-padding"
style="vertical-align: middle!important; width: 50%!important;text-align: center">
<button type="button" class="btn btn-lg shadow-none"><i <button type="button" class="btn btn-lg shadow-none"><i
class="fas fa-arrows-alt-v handle"></i></button> class="fas fa-arrows-alt-v handle"></i></button>
</div> </div>
<div class="col-md-2 small-padding"> <div class="flex-grow-2">
<input class="form-control" v-model="ingredient.amount"> <input class="form-control" v-model="ingredient.amount" type="number">
</div> </div>
<div class="col-md-3 small-padding"> <div class="col-3 small-padding">
<multiselect <multiselect
v-tabindex v-tabindex
ref="unit" ref="unit"
@ -142,7 +141,7 @@
</multiselect> </multiselect>
</div> </div>
<div class="col-md-3 small-padding"> <div class="col-3 small-padding">
<multiselect <multiselect
v-tabindex v-tabindex
ref="food" ref="food"
@ -161,15 +160,15 @@
@search-change="searchFoods"> @search-change="searchFoods">
</multiselect> </multiselect>
</div> </div>
<div class="col-md-2 small-padding"> <div class="flex-fill">
<input class="form-control" v-model="ingredient.note"> <input class="form-control" v-model="ingredient.note">
</div> </div>
<div class="col-md-1 small-padding d-flex align-items-middle justify-content-center" > <div class="flex-grow-0 small-padding">
<button type="button" class="btn btn-danger" <button type="button" class="btn btn-outline-danger btn-lg"
@click="removeIngredient(step, ingredient)"><i @click="removeIngredient(step, ingredient)"><i
class="fa fa-trash"></i></button> class="fa fa-trash"></i></button>
</div> </div>
</div>
</div> </div>
</div> </div>
</draggable> </draggable>