27 lines
882 B
Python
27 lines
882 B
Python
|
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)
|