From b4e119f7b6f7cc1d0c61ce85028365d23e50bdd4 Mon Sep 17 00:00:00 2001 From: Jean-Marie Favreau Date: Tue, 7 Nov 2023 19:05:08 +0100 Subject: [PATCH] =?UTF-8?q?on=20ajoute=20un=20affichage=20du=20fitre=20s?= =?UTF-8?q?=C3=A9lectionn=C3=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../templates/agenda_culturel/day-inc.html | 4 +- .../agenda_culturel/ephemeris-inc.html | 6 +-- .../templates/agenda_culturel/event-inc.html | 3 +- .../templates/agenda_culturel/filter-inc.html | 17 +++++++- .../templates/agenda_culturel/page-day.html | 10 +++-- .../templates/agenda_culturel/page-month.html | 8 ++-- .../templates/agenda_culturel/page-week.html | 10 ++--- src/agenda_culturel/templatetags/cat_extra.py | 8 +++- .../templatetags/event_extra.py | 2 +- src/agenda_culturel/views.py | 39 ++++++++++--------- 10 files changed, 66 insertions(+), 41 deletions(-) diff --git a/src/agenda_culturel/templates/agenda_culturel/day-inc.html b/src/agenda_culturel/templates/agenda_culturel/day-inc.html index e58e345..b4ca7c8 100644 --- a/src/agenda_culturel/templates/agenda_culturel/day-inc.html +++ b/src/agenda_culturel/templates/agenda_culturel/day-inc.html @@ -8,7 +8,7 @@
-

{{ day.date | date:"l j" }}

+

{{ day.date | date:"l j" }}

{% if day.events %} {% if resume %} @@ -38,7 +38,7 @@
diff --git a/src/agenda_culturel/templatetags/cat_extra.py b/src/agenda_culturel/templatetags/cat_extra.py index 08b618b..6970c41 100644 --- a/src/agenda_culturel/templatetags/cat_extra.py +++ b/src/agenda_culturel/templatetags/cat_extra.py @@ -85,7 +85,7 @@ def css_categories(): return mark_safe(result) @register.filter -def small_cat(category, url=None, contrast=True): +def small_cat(category, url=None, contrast=True, close_url=None): name = Category.default_name if category is None else category.name css_class = Category.default_css_class if category is None else category.css_class() @@ -101,4 +101,8 @@ def circle_cat(category): if category is None: return mark_safe('') else: - return mark_safe('') \ No newline at end of file + return mark_safe('') + +@register.filter +def small_cat_close(category, close_url=None, contrast=True): + return small_cat(category, close_url=close_url, contrast=contrast) \ No newline at end of file diff --git a/src/agenda_culturel/templatetags/event_extra.py b/src/agenda_culturel/templatetags/event_extra.py index 2f2786e..06f1402 100644 --- a/src/agenda_culturel/templatetags/event_extra.py +++ b/src/agenda_culturel/templatetags/event_extra.py @@ -21,4 +21,4 @@ def can_show_start_time(event): @register.filter def need_complete_display(event, display): - return event.end_day and event.end_day != event.start_day and (event.start_time or event.end_time or display == "in list by day") \ No newline at end of file + return event.end_day and event.end_day != event.start_day and (event.start_time or event.end_time or display == "in list by day") diff --git a/src/agenda_culturel/views.py b/src/agenda_culturel/views.py index 97e4f2c..492441c 100644 --- a/src/agenda_culturel/views.py +++ b/src/agenda_culturel/views.py @@ -2,6 +2,8 @@ from django.shortcuts import render, get_object_or_404 from django.views.generic import ListView, DetailView, FormView from django.views.generic.edit import CreateView, UpdateView, DeleteView from django.contrib.auth.mixins import LoginRequiredMixin +from django.http import QueryDict + from .forms import EventSubmissionModelForm from .celery import create_event_from_submission @@ -164,12 +166,11 @@ class EventFilter(django_filters.FilterSet): tags = django_filters.MultipleChoiceFilter(choices=[(t, t) for t in Event.get_all_tags()], lookup_expr='icontains', field_name="tags") category = django_filters.ModelMultipleChoiceFilter(field_name="category__id", to_field_name='id', queryset=Category.objects.all()) - def __init__(self, *args, **kwargs): - super().__init__(*args, **kwargs) - if len(args) > 0: - self.url = EventFilter.build_get_url(args[0]) - else: - self.url = "" + + + def filter_queryset(self, queryset): + # TODO + return super().filter_queryset(queryset) class Meta: @@ -178,16 +179,20 @@ class EventFilter(django_filters.FilterSet): field_labels = { 'category': "Catégories", "tags": "Étiquettes" } def get_url(self): - return self.url + if isinstance(self.form.data, QueryDict): + return self.form.data.urlencode() + else: + print(self.form.data) + return "" - def build_get_url(get, first = "?"): - result = "" - for p in get: - if p in EventFilter.Meta.fields: - for v in get.getlist(p): - result += first if len(result) == 0 else "&" - result += str(p) + "=" + str(v) - return result + def get_categories(self): + return self.form.cleaned_data["category"] + + def get_tags(self): + return self.form.cleaned_data["tags"] + + def is_active(self): + return len(self.form.cleaned_data["category"]) != 0 or len(self.form.cleaned_data["tags"]) != 0 def home(request): @@ -200,7 +205,6 @@ def month_view(request, year = None, month = None): if month is None: month = now.month - filtering_url = EventFilter.build_get_url(request.GET) filter = EventFilter(request.GET, queryset=Event.objects.all()) cmonth = CalendarMonth(year, month, filter) @@ -216,7 +220,6 @@ def week_view(request, year = None, week = None): if week is None: week = now.isocalendar()[1] - filtering_url = EventFilter.build_get_url(request.GET) filter = EventFilter(request.GET, queryset=Event.objects.all()) cweek = CalendarWeek(year, week, filter) @@ -234,8 +237,6 @@ def day_view(request, year = None, month = None, day = None): day = now.day day = date(year, month, day) - - filtering_url = EventFilter.build_get_url(request.GET) filter = EventFilter(request.GET, Event.objects.all()) events = filter.qs.filter(start_day__lte=day, start_day__gte=day).order_by("start_day", "start_time")