2020-03-27 18:02:22 +01:00
|
|
|
# Copyright (C) 2018-2020 by BDE ENS Paris-Saclay
|
|
|
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
|
|
|
|
|
|
|
from django.utils.translation import gettext_lazy as _
|
2020-03-27 21:18:27 +01:00
|
|
|
import django_tables2 as tables
|
|
|
|
from django_tables2 import A
|
2020-03-27 18:02:22 +01:00
|
|
|
|
|
|
|
from .models import Activity, Guest
|
|
|
|
|
|
|
|
|
|
|
|
class ActivityTable(tables.Table):
|
2020-03-27 21:18:27 +01:00
|
|
|
name = tables.LinkColumn(
|
|
|
|
'activity:activity_detail',
|
|
|
|
args=[A('pk'), ],
|
|
|
|
)
|
2020-03-27 18:02:22 +01:00
|
|
|
|
|
|
|
class Meta:
|
|
|
|
attrs = {
|
|
|
|
'class': 'table table-condensed table-striped table-hover'
|
|
|
|
}
|
|
|
|
model = Activity
|
|
|
|
template_name = 'django_tables2/bootstrap4.html'
|
2020-03-27 21:18:27 +01:00
|
|
|
fields = ('name', 'activity_type', 'organizer', 'attendees_club', 'date_start', 'date_end', )
|
2020-03-27 18:02:22 +01:00
|
|
|
|
|
|
|
|
|
|
|
class GuestTable(tables.Table):
|
2020-03-27 21:18:27 +01:00
|
|
|
inviter = tables.LinkColumn(
|
|
|
|
'member:user_detail',
|
|
|
|
args=[A('inviter.user.pk'), ],
|
|
|
|
)
|
|
|
|
|
|
|
|
entry = tables.Column(
|
|
|
|
empty_values=(),
|
|
|
|
attrs={
|
|
|
|
"td": {
|
|
|
|
"class": lambda record: "" if record.entry else "validate btn btn-danger",
|
|
|
|
"onclick": lambda record: "" if record.entry else "remove_guest(" + str(record.pk) + ")"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
2020-03-27 18:02:22 +01:00
|
|
|
class Meta:
|
|
|
|
attrs = {
|
|
|
|
'class': 'table table-condensed table-striped table-hover'
|
|
|
|
}
|
|
|
|
model = Guest
|
|
|
|
template_name = 'django_tables2/bootstrap4.html'
|
2020-03-27 21:18:27 +01:00
|
|
|
fields = ("last_name", "first_name", "inviter", )
|
|
|
|
|
|
|
|
def render_entry(self, record):
|
|
|
|
if record.entry:
|
|
|
|
return str(record.date)
|
|
|
|
return _("remove").capitalize()
|