This commit is contained in:
Tobias Lindenberg 2021-01-10 13:15:01 +01:00
parent ecf065db2b
commit e5ef19ffe4

View File

@ -1,9 +1,10 @@
import django_tables2 as tables
from django.utils.html import format_html
from django.utils.translation import gettext as _
from django_tables2.utils import A # alias for Accessor
from django_tables2.utils import A
from .models import *
from .models import (CookLog, InviteLink, Keyword, Recipe, RecipeImport,
ShoppingList, Storage, Sync, SyncLog, ViewLog)
class ImageUrlColumn(tables.Column):
@ -17,7 +18,11 @@ class RecipeTableSmall(tables.Table):
id = tables.LinkColumn('edit_recipe', args=[A('id')])
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'}})
attrs={
'td': {'class': 'd-none d-lg-table-cell'},
'th': {'class': 'd-none d-lg-table-cell'}
}
)
class Meta:
model = Recipe
@ -26,16 +31,25 @@ class RecipeTableSmall(tables.Table):
class RecipeTable(tables.Table):
edit = tables.TemplateColumn("<a style='color: inherit' href='{% url 'edit_recipe' record.id %}' >" + _('Edit') + "</a>")
edit = tables.TemplateColumn(
"<a style='color: inherit' href='{% url 'edit_recipe' record.id %}' >" + _('Edit') + "</a>" # noqa: E501
)
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'}})
attrs={
'td': {'class': 'd-none d-lg-table-cell'},
'th': {'class': 'd-none d-lg-table-cell'}
}
)
image = ImageUrlColumn()
class Meta:
model = Recipe
template_name = 'recipes_table.html'
fields = ('id', 'name', 'all_tags', 'image', 'instructions', 'working_time', 'waiting_time', 'internal')
fields = (
'id', 'name', 'all_tags', 'image', 'instructions',
'working_time', 'waiting_time', 'internal'
)
class KeywordTable(tables.Table):
@ -71,9 +85,13 @@ class ImportLogTable(tables.Table):
@staticmethod
def render_status(value):
if value == 'SUCCESS':
return format_html('<span class="badge badge-success">%s</span>' % value)
return format_html(
'<span class="badge badge-success">%s</span>' % value
)
else:
return format_html('<span class="badge badge-danger">%s</span>' % value)
return format_html(
'<span class="badge badge-danger">%s</span>' % value
)
class Meta:
model = SyncLog
@ -90,7 +108,9 @@ class SyncTable(tables.Table):
@staticmethod
def render_storage(value):
return format_html('<span class="badge badge-success">%s</span>' % value)
return format_html(
'<span class="badge badge-success">%s</span>' % value
)
class Meta:
model = Sync
@ -100,7 +120,9 @@ class SyncTable(tables.Table):
class RecipeImportTable(tables.Table):
id = tables.LinkColumn('new_recipe_import', args=[A('id')])
delete = tables.TemplateColumn("<a href='{% url 'delete_recipe_import' record.id %}' >" + _('Delete') + "</a>")
delete = tables.TemplateColumn(
"<a href='{% url 'delete_recipe_import' record.id %}' >" + _('Delete') + "</a>" # noqa: E501
)
class Meta:
model = RecipeImport
@ -118,13 +140,19 @@ class ShoppingListTable(tables.Table):
class InviteLinkTable(tables.Table):
link = tables.TemplateColumn("<a href='{% url 'view_signup' record.uuid %}' >" + _('Link') + "</a>")
delete = tables.TemplateColumn("<a href='{% url 'delete_invite_link' record.id %}' >" + _('Delete') + "</a>")
link = tables.TemplateColumn(
"<a href='{% url 'view_signup' record.uuid %}' >" + _('Link') + "</a>"
)
delete = tables.TemplateColumn(
"<a href='{% url 'delete_invite_link' record.id %}' >" + _('Delete') + "</a>" # noqa: E501
)
class Meta:
model = InviteLink
template_name = 'generic/table_template.html'
fields = ('username', 'group', 'valid_until', 'created_by', 'created_at')
fields = (
'username', 'group', 'valid_until', 'created_by', 'created_at'
)
class ViewLogTable(tables.Table):