Merge pull request #497 from smilerz/recipe_description

Recipe description
This commit is contained in:
vabene1111 2021-03-18 23:23:35 +01:00 committed by GitHub
commit 6ab8d6bd0d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 44 additions and 23 deletions

File diff suppressed because one or more lines are too long

View File

@ -47,7 +47,7 @@ class RecipeTable(tables.Table):
model = Recipe
template_name = 'recipes_table.html'
fields = (
'id', 'name', 'all_tags', 'image', 'instructions',
'id', 'name', 'all_tags', 'description', 'image', 'instructions',
'working_time', 'waiting_time', 'internal'
)

View File

@ -46,6 +46,16 @@
<input class="form-control" id="id_name" v-model="recipe.name">
</div>
</div>
<div class="row">
<div class="col-12">
<label for="id_description">
{% trans 'Description' %}
</label>
<textarea id="id_description" class="form-control" v-model="recipe.description"
maxlength="512"></textarea>
</div>
</div>
<br/>
<div class="row">
@ -90,19 +100,6 @@
</div>
</div>
<div class="row">
<div class="col-12">
<label for="id_description">
{% trans 'Description' %}
</label>
<textarea id="id_description" class="form-control" v-model="recipe.description"
maxlength="512"></textarea>
</div>
</div>
<template v-if="recipe !== undefined">
<div class="row" v-if="recipe.nutrition" style="margin-top: 1vh">
<div class="col-md-12">

View File

@ -11,13 +11,13 @@
{% block table %}
<table {% render_attrs table.attrs class="table" %}>
{% for row in table.paginated_rows %}
<div class="card" style="margin-top: 2px;">
<div class="card" style="margin-top: 1px;">
<div class="row no-gutters">
<div class="col-md-4">
<a href="{% url 'view_recipe' row.cells.id %}">
{% if row.cells.image|length > 1 %}
<img src=" {{ row.cells.image }}" alt="{% trans 'Recipe Image' %}"
class="card-img" style="object-fit: cover;height: 130px">
class="card-img" style="object-fit:cover;height: 160px">
{% else %}
<img src="{% static 'assets/recipe_no_image.svg' %}"
alt="{% trans 'Recipe Image' %}"
@ -31,10 +31,15 @@
<div class="card-body">
<div class="d-flex">
<div class="flex-fill">
<h5 class="card-title">{{ row.cells.name }}
<h5 class="card-title p-0 m-0">{{ row.cells.name }}
{% recipe_rating row.record request.user as rating %}
{{ rating|safe }}
</h5>
{%if row.record.description|length > 0 %}
<p class="card-subtitle p-0 m-0 text-muted" style="height:3em; overflow:hidden;">
{{ row.cells.description }}
</p>
{% endif %}
<p class="card-text{% if not row.record.keywords %} d-none d-lg-block{% endif %}">
{% for x in row.record.keywords.all %}
<span class="badge badge-pill badge-light">{{ x }}</span>
@ -80,6 +85,10 @@
onclick="openCookLogModal({{ row.record.pk }})"><i
class="fas fa-clipboard-list fa-fw"></i> {% trans 'Log Cooking' %}
</button>
<a class="dropdown-item"
href="{% url 'delete_recipe' row.record.pk %}"><i
class="fas fa-trash fa-fw"></i> {% trans 'Delete' %}
</a>
</div>
</div>

View File

@ -58,6 +58,12 @@
<input id="id_name" class="form-control" v-model="recipe_data.name">
</div>
<div class="form-group">
<label for="id_description">{% trans 'Recipe Description' %}</label>
<textarea id="id_description" class="form-control" v-model="recipe_data.description"
rows="4"></textarea>
</div>
<div class="row">
<div class="col col-md-6" v-if="recipe_data.image !== ''">
<img v-bind:src="recipe_data.image" alt="{% trans 'Recipe Image' %}"
@ -351,6 +357,14 @@
})
},
importRecipe: function () {
if (this.recipe_data.name.length > 128) {
this.makeToast(gettext('Error'), gettext('Recipe name is longer than 128 characters'), 'danger')
return;
}
if (this.recipe_data.description.length > 512) {
this.makeToast(gettext('Error'), gettext('Recipe description is longer than 512 characters'), 'danger')
return;
}
if (this.importing_recipe) {
this.makeToast(gettext('Error'), gettext('Already importing the selected recipe, please wait!'), 'danger')
return;

View File

@ -113,6 +113,7 @@ def import_url(request):
recipe = Recipe.objects.create(
name=data['name'],
description=data['description'],
waiting_time=data['cookTime'],
working_time=data['prepTime'],
servings=data['servings'],

View File

@ -11,16 +11,16 @@
</div>
</div>
<div style="text-align: center">
<keywords :recipe="recipe"></keywords>
</div>
<div class="row" style="margin-top: 8px">
<div class="my-auto">
<div class="col-12" style="text-align: center">
<i>{{ recipe.description }}</i>
</div>
</div>
<div style="text-align: center">
<keywords :recipe="recipe"></keywords>
</div>
<hr/>
<div class="row">
<div class="col col-md-3">