mirror of
https://gitlab.com/animath/si/plateforme-corres2math.git
synced 2025-02-06 10:52:59 +00:00
Load result data in tables
This commit is contained in:
parent
7fb811b87f
commit
144577bd89
@ -6,6 +6,7 @@ class ParticipationConfig(AppConfig):
|
|||||||
name = 'participation'
|
name = 'participation'
|
||||||
|
|
||||||
def ready(self):
|
def ready(self):
|
||||||
from participation.signals import create_team_participation, update_mailing_list
|
from participation.signals import create_team_participation, delete_related_videos, update_mailing_list
|
||||||
pre_save.connect(update_mailing_list, "participation.Team")
|
pre_save.connect(update_mailing_list, "participation.Team")
|
||||||
|
pre_delete.connect(delete_related_videos, "participation.Participation")
|
||||||
post_save.connect(create_team_participation, "participation.Team")
|
post_save.connect(create_team_participation, "participation.Team")
|
||||||
|
@ -22,4 +22,3 @@ class VideoIndex(indexes.ModelSearchIndex, indexes.Indexable):
|
|||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = Video
|
model = Video
|
||||||
|
|
||||||
|
70
apps/participation/tables.py
Normal file
70
apps/participation/tables.py
Normal file
@ -0,0 +1,70 @@
|
|||||||
|
from django.utils.translation import gettext_lazy as _
|
||||||
|
import django_tables2 as tables
|
||||||
|
|
||||||
|
from .models import Team
|
||||||
|
|
||||||
|
|
||||||
|
# noinspection PyTypeChecker
|
||||||
|
class TeamTable(tables.Table):
|
||||||
|
name = tables.LinkColumn(
|
||||||
|
'participation:team_detail',
|
||||||
|
args=[tables.A("id")],
|
||||||
|
verbose_name=lambda: _("name").capitalize(),
|
||||||
|
)
|
||||||
|
|
||||||
|
problem = tables.Column(
|
||||||
|
accessor="participation__problem",
|
||||||
|
verbose_name=lambda: _("problem number").capitalize(),
|
||||||
|
)
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
attrs = {
|
||||||
|
'class': 'table table condensed table-striped',
|
||||||
|
}
|
||||||
|
model = Team
|
||||||
|
fields = ('name', 'trigram', 'problem',)
|
||||||
|
template_name = 'django_tables2/bootstrap4.html'
|
||||||
|
|
||||||
|
|
||||||
|
# noinspection PyTypeChecker
|
||||||
|
class ParticipationTable(tables.Table):
|
||||||
|
name = tables.LinkColumn(
|
||||||
|
'participation:participation_detail',
|
||||||
|
args=[tables.A("id")],
|
||||||
|
verbose_name=lambda: _("name").capitalize(),
|
||||||
|
accessor="team__name",
|
||||||
|
)
|
||||||
|
|
||||||
|
trigram = tables.Column(
|
||||||
|
verbose_name=lambda: _("trigram").capitalize(),
|
||||||
|
accessor="team__trigram",
|
||||||
|
)
|
||||||
|
|
||||||
|
problem = tables.Column(
|
||||||
|
verbose_name=lambda: _("problem number").capitalize(),
|
||||||
|
)
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
attrs = {
|
||||||
|
'class': 'table table condensed table-striped',
|
||||||
|
}
|
||||||
|
model = Team
|
||||||
|
fields = ('name', 'trigram', 'problem',)
|
||||||
|
template_name = 'django_tables2/bootstrap4.html'
|
||||||
|
|
||||||
|
|
||||||
|
class VideoTable(tables.Table):
|
||||||
|
participation_name = tables.LinkColumn(
|
||||||
|
'participation:participation_detail',
|
||||||
|
args=[tables.A("participation__pk")],
|
||||||
|
verbose_name=lambda: _("name").capitalize(),
|
||||||
|
accessor="participation__name",
|
||||||
|
)
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
attrs = {
|
||||||
|
'class': 'table table condensed table-striped',
|
||||||
|
}
|
||||||
|
model = Team
|
||||||
|
fields = ('participation_name', 'link',)
|
||||||
|
template_name = 'django_tables2/bootstrap4.html'
|
@ -1,12 +1,11 @@
|
|||||||
import os
|
|
||||||
from io import BytesIO
|
from io import BytesIO
|
||||||
|
import os
|
||||||
from zipfile import ZipFile
|
from zipfile import ZipFile
|
||||||
|
|
||||||
from django.core.mail import send_mail
|
|
||||||
|
|
||||||
from corres2math.lists import get_sympa_client
|
from corres2math.lists import get_sympa_client
|
||||||
from django.contrib.auth.mixins import LoginRequiredMixin
|
from django.contrib.auth.mixins import LoginRequiredMixin
|
||||||
from django.core.exceptions import PermissionDenied
|
from django.core.exceptions import PermissionDenied
|
||||||
|
from django.core.mail import send_mail
|
||||||
from django.db import transaction
|
from django.db import transaction
|
||||||
from django.http import HttpResponse
|
from django.http import HttpResponse
|
||||||
from django.template.loader import render_to_string
|
from django.template.loader import render_to_string
|
||||||
|
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)
|
@ -1,6 +1,6 @@
|
|||||||
{% extends 'base.html' %}
|
{% extends 'base.html' %}
|
||||||
|
|
||||||
{% load crispy_forms_filters highlight i18n %}
|
{% load crispy_forms_filters highlight i18n search_results_tables django_tables2 %}
|
||||||
|
|
||||||
{% block content %}
|
{% block content %}
|
||||||
<h2>{% trans "Search" %}</h2>
|
<h2>{% trans "Search" %}</h2>
|
||||||
@ -19,11 +19,9 @@
|
|||||||
{% regroup page.object_list by model_name as categories %}
|
{% regroup page.object_list by model_name as categories %}
|
||||||
{% for category in categories %}
|
{% for category in categories %}
|
||||||
<h4>{% trans category.grouper|capfirst %}</h4>
|
<h4>{% trans category.grouper|capfirst %}</h4>
|
||||||
{% for result in category.list %}
|
{% with table=category.list|search_table %}
|
||||||
<p>
|
{% render_table table %}
|
||||||
<a href="{{ result.object.get_absolute_url }}">{{ result.object }}</a>
|
{% endwith %}
|
||||||
</p>
|
|
||||||
{% endfor %}
|
|
||||||
{% empty %}
|
{% empty %}
|
||||||
<p>{% trans "No results found." %}</p>
|
<p>{% trans "No results found." %}</p>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user