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) super(Category, self).save(*args, **kwargs)
def get_default_category():
def get_default_category_id():
try: try:
default, created = Category.objects.get_or_create(name=Category.default_name, default, created = Category.objects.get_or_create(name=Category.default_name,
alt_name=Category.default_alt_name, alt_name=Category.default_alt_name,
codename=Category.default_codename, codename=Category.default_codename,
color=Category.default_color) color=Category.default_color)
return default.id return default
except: except:
return None return None
def get_default_category_id():
cat = Category.get_default_category()
if cat:
return cat.id
else:
return None
def css_class(self): def css_class(self):
return "cat-" + str(self.id) return "cat-" + str(self.id)

View File

@ -73,17 +73,14 @@
{% if events|length == 0 %} {% if events|length == 0 %}
<p class="remarque">Il n'y a pas d'événement le {{ day }}</p> <p class="remarque">Il n'y a pas d'événement le {{ day }}</p>
{% else %} {% else %}
{% regroup events by category as events_by_category %}
<nav> <nav>
<ul> <ul>
{% for category in events_by_category %} {% for category in categories %}
{% with category.grouper.id|stringformat:"i" as idcat %} {% with category.0.name as idcat %}
{% with filter.get_url_without_filters|add:"?category="|add:idcat as cat_url %} {% with filter.get_url_without_filters|add:"?category="|add:idcat as cat_url %}
{% with category.list|length as nb %}
<li> <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> </li>
{% endwith %}
{% endwith %} {% endwith %}
{% endwith %} {% endwith %}
{% endfor %} {% endfor %}

View File

@ -10,6 +10,7 @@ from django.core.exceptions import PermissionDenied
from django.http import HttpResponseRedirect, HttpResponse, HttpResponseNotFound from django.http import HttpResponseRedirect, HttpResponse, HttpResponseNotFound
from django.urls import reverse from django.urls import reverse
import urllib import urllib
from collections import Counter
from .forms import EventSubmissionForm, EventForm, BatchImportationForm, FixDuplicates, SelectEventInList, MergeDuplicates, RecurrentImportForm, CategorisationRuleImportForm, ModerationQuestionForm, ModerationAnswerForm, ModerateForm, CategorisationForm 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) filter = EventFilter(request.GET, get_event_qs(request), request=request)
cday = CalendarDay(day, filter) 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) return render(request, 'agenda_culturel/page-day.html', context)