diff --git a/cookbook/templates/recipe_view.html b/cookbook/templates/recipe_view.html index 8a7007dd7..917f73c43 100644 --- a/cookbook/templates/recipe_view.html +++ b/cookbook/templates/recipe_view.html @@ -48,7 +48,8 @@ {% block content %}
-

{{ recipe.name }} {{ recipe.name }} {{ rating|safe }}

@@ -64,7 +65,8 @@ data-placement="top" title="{% trans 'Add to Mealplan' %}"> + data-placement="top" title="{% trans 'Log Cooking' %}"> + @@ -102,6 +104,10 @@ class="badge badge-secondary"> {% trans 'Waiting time ca.' %} {{ recipe.waiting_time }} min {% endif %} + {% recipe_last recipe request.user as last %} + {% if last %} + {% trans 'Last cooked' %} {{ last|date }} + {% endif %} {% if recipe.waiting_time and recipe.waiting_time != 0 or recipe.working_time and recipe.working_time != 0 %}
@@ -382,7 +388,7 @@ }); function roundToTwo(num) { - return +(Math.round(num + "e+2") + "e-2"); + return +(Math.round(num + "e+2") + "e-2"); } function reloadIngredients() { diff --git a/cookbook/templates/recipes_table.html b/cookbook/templates/recipes_table.html index 0966db4fc..a7ce5223b 100644 --- a/cookbook/templates/recipes_table.html +++ b/cookbook/templates/recipes_table.html @@ -20,14 +20,17 @@ {% else %} {% trans 'Recipe Image' %} + class="card-img d-none d-lg-block" + style="object-fit: inherit; height: 10vh"> {% endif %} -
-
{{ row.cells.name }}
+
{{ row.cells.name }} + {% recipe_rating row.record request.user as rating %} + {{ rating|safe }} +

{{ row.cells.all_tags }}

@@ -41,11 +44,17 @@ {% trans 'Waiting time ca.' %} {{ row.cells.waiting_time }} min - {% endif %}{% if not row.record.internal %} - {% trans 'External' %} - {% endif %} + {% endif %} + {% if not row.record.internal %} + {% trans 'External' %} + {% endif %} + {% recipe_last row.record request.user as last %} + {% if last %} + {% trans 'Last cooked' %} {{ last|date }} + {% endif %} {{ row.cells.edit }} - {% trans 'Log' %} + {% trans 'Log' %}

diff --git a/cookbook/templatetags/custom_tags.py b/cookbook/templatetags/custom_tags.py index 99453b92e..d9ce7d25b 100644 --- a/cookbook/templatetags/custom_tags.py +++ b/cookbook/templatetags/custom_tags.py @@ -1,12 +1,13 @@ -from django import template -import markdown as md import bleach -from bleach_whitelist import markdown_tags, markdown_attrs, all_styles, print_attrs +import markdown as md +from bleach_whitelist import markdown_tags, markdown_attrs +from django import template +from django.db.models import Avg from django.urls import reverse from cookbook.helper.mdx_attributes import MarkdownFormatExtension from cookbook.helper.mdx_urlize import UrlizeExtension -from cookbook.models import get_model_name +from cookbook.models import get_model_name, CookLog register = template.Library() @@ -29,6 +30,32 @@ def delete_url(model, pk): @register.filter() def markdown(value): tags = markdown_tags + ['pre', 'table', 'td', 'tr', 'th', 'tbody', 'style', 'thead'] - parsed_md = md.markdown(value, extensions=['markdown.extensions.fenced_code', 'tables', UrlizeExtension(), MarkdownFormatExtension()]) + parsed_md = md.markdown(value, extensions=['markdown.extensions.fenced_code', 'tables', UrlizeExtension(), MarkdownFormatExtension()]) markdown_attrs['*'] = markdown_attrs['*'] + ['class'] return bleach.clean(parsed_md, tags, markdown_attrs) + + +@register.simple_tag +def recipe_rating(recipe, user): + rating = recipe.cooklog_set.filter(created_by=user).aggregate(Avg('rating')) + if rating['rating__avg']: + + rating_stars = '' + for i in range(int(rating['rating__avg'])): + rating_stars = rating_stars + '' + + if rating['rating__avg'] % 1 >= 0.5: + rating_stars = rating_stars + '' + + return rating_stars + else: + return '' + + +@register.simple_tag +def recipe_last(recipe, user): + last = recipe.cooklog_set.filter(created_by=user).last() + if last: + return last.created_at + else: + return ''