mirror of
https://github.com/ae-utbm/sith.git
synced 2026-10-25 11:49:33 +00:00
display club past news
This commit is contained in:
1 parent
32c30da0fc
commit
1e189f7b2b
3 files changed
+110
-1
No files matched your search
@@ -0,0 +1,79 @@
|
|||||||
|
{% extends "core/base.jinja" %}
|
||||||
|
|
||||||
|
{% block content %}
|
||||||
|
{% if club.has_rights_in_club(user) %}
|
||||||
|
<a class="btn btn-blue" href="{{ url("com:news_new") }}">
|
||||||
|
<i class="fa fa-plus"></i> {% trans %}Create news{% endtrans %}
|
||||||
|
</a>
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
|
{% for semester_code, semester_events in events %}
|
||||||
|
<h3>{{ semester_code }}</h3>
|
||||||
|
{% for event in semester_events %}
|
||||||
|
<details class="accordion">
|
||||||
|
<summary>{{ event.title }}</summary>
|
||||||
|
<div class="accordion-content">
|
||||||
|
|
||||||
|
{# Events that occur weekly from the start to the end of the semester
|
||||||
|
would take a lot of space if shown by default.
|
||||||
|
Thus, if the event has more than one date, those are
|
||||||
|
hidden by a details element.
|
||||||
|
If there is only one date, it is directly displayed. #}
|
||||||
|
{% set dates = event.dates.all()|list %}
|
||||||
|
{% if dates|length == 1 %}
|
||||||
|
<em>
|
||||||
|
<time datetime="{{ dates[0].start_date.isoformat(timespec="seconds") }}">
|
||||||
|
{{ dates[0].start_date|localtime|date(DATETIME_FORMAT) }},
|
||||||
|
{{ dates[0].start_date|localtime|time(DATETIME_FORMAT) }}
|
||||||
|
</time> -
|
||||||
|
<time datetime="{{ dates[0].end_date.isoformat(timespec="seconds") }}">
|
||||||
|
{{ dates[0].end_date|localtime|date(DATETIME_FORMAT) }},
|
||||||
|
{{ dates[0].end_date|localtime|time(DATETIME_FORMAT) }}
|
||||||
|
</time>
|
||||||
|
</em>
|
||||||
|
{% else %}
|
||||||
|
<details>
|
||||||
|
<summary>
|
||||||
|
{% trans trimmed nb_occurrences=dates|length %}
|
||||||
|
Dates ({{ nb_occurrences }} occurrences)
|
||||||
|
{% endtrans %}
|
||||||
|
</summary>
|
||||||
|
<ul>
|
||||||
|
{% for d in dates %}
|
||||||
|
<li>
|
||||||
|
<time datetime="{{ d.start_date.isoformat(timespec="seconds") }}">
|
||||||
|
{{ d.start_date|localtime|date(DATETIME_FORMAT) }},
|
||||||
|
{{ d.start_date|localtime|time(DATETIME_FORMAT) }}
|
||||||
|
</time> -
|
||||||
|
<time datetime="{{ d.end_date.isoformat(timespec="seconds") }}">
|
||||||
|
{{ d.end_date|localtime|date(DATETIME_FORMAT) }},
|
||||||
|
{{ d.end_date|localtime|time(DATETIME_FORMAT) }}
|
||||||
|
</time>
|
||||||
|
</li>
|
||||||
|
{% endfor %}
|
||||||
|
</ul>
|
||||||
|
</details>
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
|
<h4>{% trans %}Permalink{% endtrans %}</h4>
|
||||||
|
<p>{{ request.build_absolute_uri(event.get_absolute_url())|urlize }}</p>
|
||||||
|
|
||||||
|
<h4>{% trans %}Summary{% endtrans %}</h4>
|
||||||
|
{% if event.summary %}
|
||||||
|
{{ event.summary|markdown }}
|
||||||
|
{% else %}
|
||||||
|
<p><em>{% trans %}No summary{% endtrans %}</em></p>
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
|
<h4>{% trans %}Description{% endtrans %}</h4>
|
||||||
|
{% if event.content %}
|
||||||
|
{{ event.content|markdown }}
|
||||||
|
{% else %}
|
||||||
|
<p><em>{% trans %}No detailed description{% endtrans %}</em></p>
|
||||||
|
{% endif %}
|
||||||
|
</div>
|
||||||
|
</details>
|
||||||
|
{% endfor %}
|
||||||
|
<br />
|
||||||
|
{% endfor %}
|
||||||
|
{% endblock %}
|
||||||
@@ -31,6 +31,7 @@ from club.views import (
|
|||||||
ClubListView,
|
ClubListView,
|
||||||
ClubMailingView,
|
ClubMailingView,
|
||||||
ClubMembersView,
|
ClubMembersView,
|
||||||
|
ClubNewsView,
|
||||||
ClubOldMembersView,
|
ClubOldMembersView,
|
||||||
ClubPageEditView,
|
ClubPageEditView,
|
||||||
ClubPageHistView,
|
ClubPageHistView,
|
||||||
@@ -136,4 +137,5 @@ urlpatterns = [
|
|||||||
PosterDeleteView.as_view(),
|
PosterDeleteView.as_view(),
|
||||||
name="poster_delete",
|
name="poster_delete",
|
||||||
),
|
),
|
||||||
|
path("<int:club_id>/news/", ClubNewsView.as_view(), name="news_list"),
|
||||||
]
|
]
|
||||||
+29
-1
@@ -37,6 +37,7 @@ from django.contrib.messages.views import SuccessMessageMixin
|
|||||||
from django.core.exceptions import NON_FIELD_ERRORS, PermissionDenied, ValidationError
|
from django.core.exceptions import NON_FIELD_ERRORS, PermissionDenied, ValidationError
|
||||||
from django.core.paginator import InvalidPage, Paginator
|
from django.core.paginator import InvalidPage, Paginator
|
||||||
from django.db.models import F, Prefetch, Q, Sum
|
from django.db.models import F, Prefetch, Q, Sum
|
||||||
|
from django.db.models.expressions import OuterRef, Subquery
|
||||||
from django.db.models.functions import Length
|
from django.db.models.functions import Length
|
||||||
from django.http import Http404, StreamingHttpResponse
|
from django.http import Http404, StreamingHttpResponse
|
||||||
from django.shortcuts import get_object_or_404, redirect
|
from django.shortcuts import get_object_or_404, redirect
|
||||||
@@ -71,7 +72,7 @@ from club.models import (
|
|||||||
MailingSubscription,
|
MailingSubscription,
|
||||||
Membership,
|
Membership,
|
||||||
)
|
)
|
||||||
from com.models import Poster
|
from com.models import NewsDate, Poster
|
||||||
from com.views import (
|
from com.views import (
|
||||||
PosterCreateBaseView,
|
PosterCreateBaseView,
|
||||||
PosterDeleteBaseView,
|
PosterDeleteBaseView,
|
||||||
@@ -80,6 +81,7 @@ from com.views import (
|
|||||||
)
|
)
|
||||||
from core.auth.mixins import CanEditMixin, PermissionOrClubBoardRequiredMixin
|
from core.auth.mixins import CanEditMixin, PermissionOrClubBoardRequiredMixin
|
||||||
from core.models import Page, PageRev
|
from core.models import Page, PageRev
|
||||||
|
from core.utils import get_semester_code
|
||||||
from core.views import BasePageEditView, DetailFormView, UseFragmentsMixin
|
from core.views import BasePageEditView, DetailFormView, UseFragmentsMixin
|
||||||
from core.views.mixins import (
|
from core.views.mixins import (
|
||||||
AllowFragment,
|
AllowFragment,
|
||||||
@@ -935,3 +937,29 @@ class PosterDeleteView(ClubTabsMixin, PosterDeleteBaseView):
|
|||||||
|
|
||||||
def get_success_url(self):
|
def get_success_url(self):
|
||||||
return reverse_lazy("club:poster_list", kwargs={"club_id": self.club.id})
|
return reverse_lazy("club:poster_list", kwargs={"club_id": self.club.id})
|
||||||
|
|
||||||
|
|
||||||
|
class ClubNewsView(PermissionRequiredMixin, DetailView):
|
||||||
|
pk_url_kwarg = "club_id"
|
||||||
|
model = Club
|
||||||
|
permission_required = "club.view_club"
|
||||||
|
template_name = "club/club_news_list.jinja"
|
||||||
|
|
||||||
|
def get_context_data(self, **kwargs: Any):
|
||||||
|
events = list(
|
||||||
|
self.object.news.viewable_by(self.request.user)
|
||||||
|
.annotate(
|
||||||
|
first_date=Subquery(
|
||||||
|
NewsDate.objects.filter(news_id=OuterRef("pk"))
|
||||||
|
.order_by("start_date")
|
||||||
|
.values("start_date")[:1]
|
||||||
|
),
|
||||||
|
)
|
||||||
|
.prefetch_related("dates")
|
||||||
|
.order_by("-first_date")
|
||||||
|
)
|
||||||
|
return super().get_context_data(**kwargs) | {
|
||||||
|
"events": itertools.groupby(
|
||||||
|
events, key=lambda event: get_semester_code(event.first_date.date())
|
||||||
|
)
|
||||||
|
}
|
||||||
Reference in new issue
Block a user