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 drf_writable_nested import WritableNestedModelSerializer, UniqueFieldsMixin
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 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
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 Meta:
model = User
@ -60,10 +78,11 @@ class FoodSerializer(UniqueFieldsMixin, serializers.ModelSerializer):
class IngredientSerializer(WritableNestedModelSerializer):
food = FoodSerializer()
unit = UnitSerializer()
amount = CustomDecimalField()
class Meta:
model = Ingredient
fields = '__all__'
fields = ('id', 'food', 'unit', 'amount', 'note', 'order')
class StepSerializer(WritableNestedModelSerializer):

View File

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