From 3420dcd07d4fd3c01644f932ab2b30a2ba3416dc Mon Sep 17 00:00:00 2001 From: Brendan Cazier Date: Mon, 1 Jun 2020 12:36:47 -0500 Subject: [PATCH] Made recipe images hyperlinked --- cookbook/tables.py | 18 ++++++++++++++---- cookbook/templates/recipes_table.html | 11 +---------- 2 files changed, 15 insertions(+), 14 deletions(-) diff --git a/cookbook/tables.py b/cookbook/tables.py index 1ee7b941d..68d89fb9b 100644 --- a/cookbook/tables.py +++ b/cookbook/tables.py @@ -5,12 +5,22 @@ from django_tables2.utils import A # alias for Accessor from .models import * +from django.utils.safestring import mark_safe +from django.templatetags.static import static -class ImageUrlColumn(tables.Column): +class ImageUrlColumn(tables.LinkColumn): def render(self, value): if value.url: - return value.url - return None + src = value.url + _class = '' + style = 'object-fit: cover;' + + else: + src = static("recipe_no_image.svg") + _class = 'd-none d-lg-block' + style = 'object-fit: inherit;' + + return mark_safe(f'{_(') class RecipeTableSmall(tables.Table): @@ -30,7 +40,7 @@ class RecipeTable(tables.Table): name = tables.LinkColumn('view_recipe', args=[A('id')]) all_tags = tables.Column( attrs={'td': {'class': 'd-none d-lg-table-cell'}, 'th': {'class': 'd-none d-lg-table-cell'}}) - image = ImageUrlColumn() + image = ImageUrlColumn('view_recipe', args=[A('id')]) class Meta: model = Recipe diff --git a/cookbook/templates/recipes_table.html b/cookbook/templates/recipes_table.html index dabd7e656..228a5018e 100644 --- a/cookbook/templates/recipes_table.html +++ b/cookbook/templates/recipes_table.html @@ -14,16 +14,7 @@
- {% if row.cells.image|length > 1 %} - {% trans 'Recipe Image' %} - {% else %} - {% trans 'Recipe Image' %} - - {% endif %} + {{ row.cells.image }}