tables
This commit is contained in:
parent
ecf065db2b
commit
e5ef19ffe4
@ -1,9 +1,10 @@
|
|||||||
import django_tables2 as tables
|
import django_tables2 as tables
|
||||||
from django.utils.html import format_html
|
from django.utils.html import format_html
|
||||||
from django.utils.translation import gettext as _
|
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):
|
class ImageUrlColumn(tables.Column):
|
||||||
@ -17,7 +18,11 @@ class RecipeTableSmall(tables.Table):
|
|||||||
id = tables.LinkColumn('edit_recipe', args=[A('id')])
|
id = tables.LinkColumn('edit_recipe', args=[A('id')])
|
||||||
name = tables.LinkColumn('view_recipe', args=[A('id')])
|
name = tables.LinkColumn('view_recipe', args=[A('id')])
|
||||||
all_tags = tables.Column(
|
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:
|
class Meta:
|
||||||
model = Recipe
|
model = Recipe
|
||||||
@ -26,16 +31,25 @@ class RecipeTableSmall(tables.Table):
|
|||||||
|
|
||||||
|
|
||||||
class RecipeTable(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')])
|
name = tables.LinkColumn('view_recipe', args=[A('id')])
|
||||||
all_tags = tables.Column(
|
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()
|
image = ImageUrlColumn()
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = Recipe
|
model = Recipe
|
||||||
template_name = 'recipes_table.html'
|
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):
|
class KeywordTable(tables.Table):
|
||||||
@ -71,9 +85,13 @@ class ImportLogTable(tables.Table):
|
|||||||
@staticmethod
|
@staticmethod
|
||||||
def render_status(value):
|
def render_status(value):
|
||||||
if value == 'SUCCESS':
|
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:
|
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:
|
class Meta:
|
||||||
model = SyncLog
|
model = SyncLog
|
||||||
@ -90,7 +108,9 @@ class SyncTable(tables.Table):
|
|||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def render_storage(value):
|
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:
|
class Meta:
|
||||||
model = Sync
|
model = Sync
|
||||||
@ -100,7 +120,9 @@ class SyncTable(tables.Table):
|
|||||||
|
|
||||||
class RecipeImportTable(tables.Table):
|
class RecipeImportTable(tables.Table):
|
||||||
id = tables.LinkColumn('new_recipe_import', args=[A('id')])
|
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:
|
class Meta:
|
||||||
model = RecipeImport
|
model = RecipeImport
|
||||||
@ -118,13 +140,19 @@ class ShoppingListTable(tables.Table):
|
|||||||
|
|
||||||
|
|
||||||
class InviteLinkTable(tables.Table):
|
class InviteLinkTable(tables.Table):
|
||||||
link = tables.TemplateColumn("<a href='{% url 'view_signup' record.uuid %}' >" + _('Link') + "</a>")
|
link = tables.TemplateColumn(
|
||||||
delete = tables.TemplateColumn("<a href='{% url 'delete_invite_link' record.id %}' >" + _('Delete') + "</a>")
|
"<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:
|
class Meta:
|
||||||
model = InviteLink
|
model = InviteLink
|
||||||
template_name = 'generic/table_template.html'
|
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):
|
class ViewLogTable(tables.Table):
|
||||||
|
Loading…
Reference in New Issue
Block a user