mirror of
https://gitlab.com/animath/si/plateforme-corres2math.git
synced 2025-06-23 02:38:21 +02:00
Load result data in tables
This commit is contained in:
21
apps/registration/tables.py
Normal file
21
apps/registration/tables.py
Normal file
@ -0,0 +1,21 @@
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
import django_tables2 as tables
|
||||
|
||||
from .models import Registration
|
||||
|
||||
|
||||
class RegistrationTable(tables.Table):
|
||||
last_name = tables.LinkColumn(
|
||||
'registration:user_detail',
|
||||
args=[tables.A("user_id")],
|
||||
verbose_name=lambda: _("last name").capitalize(),
|
||||
accessor="user__last_name",
|
||||
)
|
||||
|
||||
class Meta:
|
||||
attrs = {
|
||||
'class': 'table table condensed table-striped',
|
||||
}
|
||||
model = Registration
|
||||
fields = ('last_name', 'user__first_name', 'user__email', 'type',)
|
||||
template_name = 'django_tables2/bootstrap4.html'
|
0
apps/registration/templatetags/__init__.py
Normal file
0
apps/registration/templatetags/__init__.py
Normal file
26
apps/registration/templatetags/search_results_tables.py
Normal file
26
apps/registration/templatetags/search_results_tables.py
Normal file
@ -0,0 +1,26 @@
|
||||
from django import template
|
||||
from django_tables2 import Table
|
||||
from participation.models import Participation, Team, Video
|
||||
from participation.tables import ParticipationTable, TeamTable, VideoTable
|
||||
|
||||
from ..models import Registration
|
||||
from ..tables import RegistrationTable
|
||||
|
||||
|
||||
def search_table(results):
|
||||
model_class = results[0].object.__class__
|
||||
if issubclass(model_class, Registration):
|
||||
table_class = RegistrationTable
|
||||
elif issubclass(model_class, Team):
|
||||
table_class = TeamTable
|
||||
elif issubclass(model_class, Participation):
|
||||
table_class = ParticipationTable
|
||||
elif issubclass(model_class, Video):
|
||||
table_class = VideoTable
|
||||
else:
|
||||
table_class = Table
|
||||
return table_class([result.object for result in results], prefix=model_class._meta.model_name)
|
||||
|
||||
|
||||
register = template.Library()
|
||||
register.filter("search_table", search_table)
|
Reference in New Issue
Block a user