améioration des catégories d'un jour

This commit is contained in:
Jean-Marie Favreau 2024-04-22 13:03:19 +02:00
parent a43eb28e75
commit d59f434c0f
3 changed files with 19 additions and 10 deletions

View File

@ -83,18 +83,25 @@ class Category(models.Model):
super(Category, self).save(*args, **kwargs)
def get_default_category_id():
def get_default_category():
try:
default, created = Category.objects.get_or_create(name=Category.default_name,
alt_name=Category.default_alt_name,
codename=Category.default_codename,
color=Category.default_color)
return default.id
return default
except:
return None
def get_default_category_id():
cat = Category.get_default_category()
if cat:
return cat.id
else:
return None
def css_class(self):
return "cat-" + str(self.id)

View File

@ -73,17 +73,14 @@
{% if events|length == 0 %}
<p class="remarque">Il n'y a pas d'événement le {{ day }}</p>
{% else %}
{% regroup events by category as events_by_category %}
<nav>
<ul>
{% for category in events_by_category %}
{% with category.grouper.id|stringformat:"i" as idcat %}
{% for category in categories %}
{% with category.0.name as idcat %}
{% with filter.get_url_without_filters|add:"?category="|add:idcat as cat_url %}
{% with category.list|length as nb %}
<li>
<a class="small-cat contrast selected" role="button" href="{{ cat_url }}"><span class="cat {{ category.grouper.css_class }}"></span>{{ category.grouper.name }}&nbsp;: {{ category.list|length }}</a>
<a class="small-cat contrast selected" role="button" href="{{ cat_url }}"><span class="cat {{ category.0.css_class }}"></span>{{ idcat }}&nbsp;: {{ category.1 }}</a>
</li>
{% endwith %}
{% endwith %}
{% endwith %}
{% endfor %}

View File

@ -10,6 +10,7 @@ from django.core.exceptions import PermissionDenied
from django.http import HttpResponseRedirect, HttpResponse, HttpResponseNotFound
from django.urls import reverse
import urllib
from collections import Counter
from .forms import EventSubmissionForm, EventForm, BatchImportationForm, FixDuplicates, SelectEventInList, MergeDuplicates, RecurrentImportForm, CategorisationRuleImportForm, ModerationQuestionForm, ModerationAnswerForm, ModerateForm, CategorisationForm
@ -201,7 +202,11 @@ def day_view(request, year = None, month = None, day = None):
filter = EventFilter(request.GET, get_event_qs(request), request=request)
cday = CalendarDay(day, filter)
context = {"day": day, "events": cday.get_events(), "filter": filter}
categories = Counter([e.category if e.category is not None else Category.get_default_category() for e in cday.get_events()])
categories = [(k, v) for k, v in categories.items()]
categories.sort(key=lambda k: -k[1])
context = {"day": day, "events": cday.get_events(), "filter": filter, "categories": categories}
return render(request, 'agenda_culturel/page-day.html', context)