some small meal plan fixes

This commit is contained in:
vabene1111
2021-09-23 13:57:47 +02:00
parent 5c85369120
commit ea472158f9
5 changed files with 28 additions and 9 deletions

View File

@ -0,0 +1,18 @@
# Generated by Django 3.2.7 on 2021-09-23 11:38
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('cookbook', '0154_auto_20210922_1705'),
]
operations = [
migrations.AddField(
model_name='mealtype',
name='default',
field=models.BooleanField(blank=True, default=False),
),
]

View File

@ -598,6 +598,7 @@ class MealType(models.Model, PermissionModelMixin):
order = models.IntegerField(default=0) order = models.IntegerField(default=0)
icon = models.CharField(max_length=16, blank=True, null=True) icon = models.CharField(max_length=16, blank=True, null=True)
color = models.CharField(max_length=7, blank=True, null=True) color = models.CharField(max_length=7, blank=True, null=True)
default = models.BooleanField(default=False, blank=True)
created_by = models.ForeignKey(User, on_delete=models.CASCADE) created_by = models.ForeignKey(User, on_delete=models.CASCADE)
space = models.ForeignKey(Space, on_delete=models.CASCADE) space = models.ForeignKey(Space, on_delete=models.CASCADE)

View File

@ -64,7 +64,7 @@ class SpacedModelSerializer(serializers.ModelSerializer):
return super().create(validated_data) return super().create(validated_data)
class MealTypeSerializer(SpacedModelSerializer): class MealTypeSerializer(SpacedModelSerializer, WritableNestedModelSerializer):
def create(self, validated_data): def create(self, validated_data):
validated_data['created_by'] = self.context['request'].user validated_data['created_by'] = self.context['request'].user
@ -73,7 +73,7 @@ class MealTypeSerializer(SpacedModelSerializer):
class Meta: class Meta:
list_serializer_class = SpaceFilterSerializer list_serializer_class = SpaceFilterSerializer
model = MealType model = MealType
fields = ('id', 'name', 'order', 'icon', 'color', 'created_by') fields = ('id', 'name', 'order', 'icon', 'color', 'default', 'created_by')
read_only_fields = ('created_by',) read_only_fields = ('created_by',)
@ -561,7 +561,7 @@ class MealPlanSerializer(SpacedModelSerializer, WritableNestedModelSerializer):
recipe = RecipeOverviewSerializer(required=False, allow_null=True) recipe = RecipeOverviewSerializer(required=False, allow_null=True)
recipe_name = serializers.ReadOnlyField(source='recipe.name') recipe_name = serializers.ReadOnlyField(source='recipe.name')
meal_type = MealTypeSerializer() meal_type = MealTypeSerializer()
meal_type_name = serializers.ReadOnlyField(source='meal_type.name') meal_type_name = serializers.ReadOnlyField(source='meal_type.name') # TODO deprecate once old meal plan was removed
note_markdown = serializers.SerializerMethodField('get_note_markdown') note_markdown = serializers.SerializerMethodField('get_note_markdown')
servings = CustomDecimalField() servings = CustomDecimalField()

View File

@ -46,7 +46,8 @@
<table class="table table-sm table-striped table-responsive-sm" style=" table-layout:fixed;"> <table class="table table-sm table-striped table-responsive-sm" style=" table-layout:fixed;">
<thead class="thead-dark" style="background-image: url({% static 'assets/header.svg' %});"> <thead class="thead-dark" style="background-image: url({% static 'assets/header.svg' %});">
<tr> <tr>
<th class="thead-blank" v-for="d in dates" style="width: 14.2%; text-align: center;">[[formatDateDayname(d)]]<br/>[[formatDateDay(d)]]. <th class="thead-blank" v-for="d in dates" style="width: 14.2%; text-align: center;">
[[formatDateDayname(d)]]<br/>[[formatDateDay(d)]].
<button class="btn btn-sm btn-outline-secondary shadow-none" @click="addDayToShopping(d)"><i <button class="btn btn-sm btn-outline-secondary shadow-none" @click="addDayToShopping(d)"><i
class="fas fa-cart-plus fa-sm"></i></button> class="fas fa-cart-plus fa-sm"></i></button>
</th> </th>
@ -460,7 +461,7 @@
this.$set(mte, 'delete', false) this.$set(mte, 'delete', false)
} }
if (this.meal_types.length === 0){ if (this.meal_types.length === 0) {
this.makeToast(gettext('Information'), gettext('To use the meal plan please first create at least one meal plan type.'), 'warning') this.makeToast(gettext('Information'), gettext('To use the meal plan please first create at least one meal plan type.'), 'warning')
} }
}).catch((err) => { }).catch((err) => {
@ -552,8 +553,7 @@
let plan_entry = evt.added.element let plan_entry = evt.added.element
plan_entry.date = date plan_entry.date = date
plan_entry.meal_type.id = meal_type.id plan_entry.meal_type = meal_type
plan_entry.meal_type.name = meal_type.name
plan_entry.meal_type_name = meal_type.name plan_entry.meal_type_name = meal_type.name
if (plan_entry.is_new) { // its not a meal plan object if (plan_entry.is_new) { // its not a meal plan object
@ -585,7 +585,7 @@
this.makeToast(gettext('Error'), gettext('There was an error loading a resource!') + err.bodyText, 'danger') this.makeToast(gettext('Error'), gettext('There was an error loading a resource!') + err.bodyText, 'danger')
}) })
}, },
removeDuplicates: function(data, key) { removeDuplicates: function (data, key) {
return [ return [
...new Map(data.map(item => [key(item), item])).values() ...new Map(data.map(item => [key(item), item])).values()
] ]

View File

@ -105,7 +105,7 @@ def test_add(arg, request, u1_s2, recipe_1_s1, meal_type):
c = request.getfixturevalue(arg[0]) c = request.getfixturevalue(arg[0])
r = c.post( r = c.post(
reverse(LIST_URL), reverse(LIST_URL),
{'recipe': {'id': recipe_1_s1.id, 'name': recipe_1_s1.name, 'keywords': []}, 'meal_type': meal_type.id, {'recipe': {'id': recipe_1_s1.id, 'name': recipe_1_s1.name, 'keywords': []}, 'meal_type': {'id': meal_type.id, 'name': meal_type.name},
'date': (datetime.now()).strftime("%Y-%m-%d"), 'servings': 1, 'title': 'test'}, 'date': (datetime.now()).strftime("%Y-%m-%d"), 'servings': 1, 'title': 'test'},
content_type='application/json' content_type='application/json'
) )