mirror of
https://gitlab.crans.org/bde/nk20
synced 2025-06-21 01:48:21 +02:00
Wrapped apps
This commit is contained in:
72
apps/wrapped/tables.py
Normal file
72
apps/wrapped/tables.py
Normal file
@ -0,0 +1,72 @@
|
||||
# Copyright (C) 2018-2024 by BDE ENS Paris-Saclay
|
||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
from django.utils import timezone
|
||||
from django.utils.html import escape
|
||||
from django.utils.safestring import mark_safe
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
from note_kfet.middlewares import get_current_request
|
||||
import django_tables2 as tables
|
||||
from django_tables2 import A
|
||||
from permission.backends import PermissionBackend
|
||||
from note.templatetags.pretty_money import pretty_money
|
||||
|
||||
from .models import Wrapped, Bde
|
||||
|
||||
class WrappedTable(tables.Table):
|
||||
"""
|
||||
List all wrapped
|
||||
"""
|
||||
class Meta:
|
||||
attrs = {
|
||||
'class': 'table table-condensed table-striped table-hover',
|
||||
'id': 'wrapped_table'
|
||||
}
|
||||
row_attrs = {
|
||||
'class': lambda record: 'bg-danger' if not record.generated else '',
|
||||
}
|
||||
model = Wrapped
|
||||
template_name = 'django_tables2/bootstrap4.html'
|
||||
fields = ('note', 'bde', 'public', )
|
||||
|
||||
view = tables.LinkColumn(
|
||||
'wrapped:wrapped_detail',
|
||||
args=[A('pk')],
|
||||
|
||||
attrs={
|
||||
'td': {'class': 'col-sm-2'},
|
||||
'a': {
|
||||
'class': 'btn btn-sm btn-primary',
|
||||
'data-turbolinks': 'false',
|
||||
}
|
||||
},
|
||||
text=_('view the wrapped'),
|
||||
accessor='pk',
|
||||
verbose_name=_('View'),
|
||||
orderable=False,
|
||||
)
|
||||
|
||||
public = tables.Column(
|
||||
accessor="pk",
|
||||
orderable=False,
|
||||
attrs={
|
||||
"td": {
|
||||
"id": lambda record: "makepublic_"+ str(record.pk),
|
||||
"class" : 'col-sm-1',
|
||||
"data-toggle": "tooltip",
|
||||
"title": lambda record:
|
||||
(_("Click to make this wrapped private") if record.public else
|
||||
_("Click to make this wrapped public")) if PermissionBackend.check_perm(
|
||||
get_current_request(), "wrapped.change_wrapped_public", record) else None,
|
||||
"onclick" : lambda record:
|
||||
'makepublic(' + str(record.id) + ', ' + str(not record.public).lower() + ')'
|
||||
if PermissionBackend.check_perm(get_current_request(), "wrapped.change_wrapped_public",
|
||||
record) else None
|
||||
}
|
||||
},
|
||||
)
|
||||
|
||||
def render_public(self, value, record):
|
||||
val = "✔" if record.public else "✖"
|
||||
return val
|
||||
|
Reference in New Issue
Block a user