On ajoute le principe qu'un tag puisse être une sous-catégorie
This commit is contained in:
parent
af297b5d25
commit
8e552f2574
19
src/agenda_culturel/migrations/0100_tag_category.py
Normal file
19
src/agenda_culturel/migrations/0100_tag_category.py
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
# Generated by Django 4.2.9 on 2024-11-02 10:54
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
import django.db.models.deletion
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('agenda_culturel', '0099_update_categories'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='tag',
|
||||||
|
name='category',
|
||||||
|
field=models.ForeignKey(default=None, help_text='This tags corresponds to a sub-category of the given category', null=True, on_delete=django.db.models.deletion.SET_NULL, to='agenda_culturel.category', verbose_name='Category'),
|
||||||
|
),
|
||||||
|
]
|
@ -155,6 +155,9 @@ class Category(models.Model):
|
|||||||
def css_class(self):
|
def css_class(self):
|
||||||
return "cat-" + str(self.id)
|
return "cat-" + str(self.id)
|
||||||
|
|
||||||
|
def get_absolute_url(self):
|
||||||
|
return reverse('home') + '?catgory=' + str(self.pk)
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return self.name
|
return self.name
|
||||||
|
|
||||||
@ -183,6 +186,15 @@ class Tag(models.Model):
|
|||||||
default=True,
|
default=True,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
category = models.ForeignKey(
|
||||||
|
Category,
|
||||||
|
verbose_name=_("Category"),
|
||||||
|
help_text=_("This tags corresponds to a sub-category of the given category"),
|
||||||
|
null=True,
|
||||||
|
default=None,
|
||||||
|
on_delete=models.SET_NULL,
|
||||||
|
)
|
||||||
|
|
||||||
def get_absolute_url(self):
|
def get_absolute_url(self):
|
||||||
return reverse("view_tag", kwargs={"t": self.name})
|
return reverse("view_tag", kwargs={"t": self.name})
|
||||||
|
|
||||||
|
@ -35,10 +35,12 @@
|
|||||||
|
|
||||||
{% if object %}
|
{% if object %}
|
||||||
<p>{{ object.description|safe }}</p>
|
<p>{{ object.description|safe }}</p>
|
||||||
|
<p>{% if object.category %}Cette étiquette est une sous-catégorie de {{ object.category| small_cat:object.category.get_absolute_url }}{% endif %}</p>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
{% include 'agenda_culturel/paginator.html' %}
|
<footer>
|
||||||
|
{% include 'agenda_culturel/paginator.html' %}
|
||||||
|
</footer>
|
||||||
</article>
|
</article>
|
||||||
|
|
||||||
{% for event in paginator_filter %}
|
{% for event in paginator_filter %}
|
||||||
|
@ -9,6 +9,10 @@
|
|||||||
|
|
||||||
{% block fluid %}{% endblock %}
|
{% block fluid %}{% endblock %}
|
||||||
|
|
||||||
|
{% block entete_header %}
|
||||||
|
{% css_categories %}
|
||||||
|
{% endblock %}
|
||||||
|
|
||||||
|
|
||||||
{% block content %}
|
{% block content %}
|
||||||
{% with cache_timeout=user.is_authenticated|yesno:"30,600" %}
|
{% with cache_timeout=user.is_authenticated|yesno:"30,600" %}
|
||||||
@ -25,7 +29,8 @@
|
|||||||
<header><a href="{% url 'view_tag' tag.name %}" role="button" class="small-cat">{{ tag.name }}</a></header>
|
<header><a href="{% url 'view_tag' tag.name %}" role="button" class="small-cat">{{ tag.name }}</a></header>
|
||||||
<div>
|
<div>
|
||||||
{{ tag.description|safe }}
|
{{ tag.description|safe }}
|
||||||
</div>
|
<p>{% if tag.category %}Cette étiquette est une sous-catégorie de {{ tag.category| small_cat:tag.category.get_absolute_url }}{% endif %}</p>
|
||||||
|
</div>
|
||||||
</article>
|
</article>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
|
||||||
|
@ -3,12 +3,14 @@ from django.utils.safestring import mark_safe
|
|||||||
from django.urls import reverse_lazy
|
from django.urls import reverse_lazy
|
||||||
from agenda_culturel.models import Tag
|
from agenda_culturel.models import Tag
|
||||||
from .utils_extra import *
|
from .utils_extra import *
|
||||||
|
from .cat_extra import *
|
||||||
|
|
||||||
register = template.Library()
|
register = template.Library()
|
||||||
|
|
||||||
|
|
||||||
def t_button(tag, url, strike=False):
|
def t_button(tag, url, strike=False, category=None):
|
||||||
strike_class = " strike" if strike else ""
|
strike_class = " strike" if strike else ""
|
||||||
|
cat = "" if category is None else circle_cat(category) + ' '
|
||||||
if not url is None:
|
if not url is None:
|
||||||
return mark_safe(
|
return mark_safe(
|
||||||
'<a href="'
|
'<a href="'
|
||||||
@ -16,6 +18,7 @@ def t_button(tag, url, strike=False):
|
|||||||
+ '" role="button" class="small-cat'
|
+ '" role="button" class="small-cat'
|
||||||
+ strike_class
|
+ strike_class
|
||||||
+ '">'
|
+ '">'
|
||||||
|
+ cat
|
||||||
+ tag
|
+ tag
|
||||||
+ "</a>"
|
+ "</a>"
|
||||||
)
|
)
|
||||||
@ -24,6 +27,7 @@ def t_button(tag, url, strike=False):
|
|||||||
'<span role="button" class="small-cat'
|
'<span role="button" class="small-cat'
|
||||||
+ strike_class
|
+ strike_class
|
||||||
+ '">'
|
+ '">'
|
||||||
|
+ cat
|
||||||
+ tag
|
+ tag
|
||||||
+ "</span>"
|
+ "</span>"
|
||||||
)
|
)
|
||||||
@ -54,6 +58,10 @@ def show_suggested_tags(filter):
|
|||||||
|
|
||||||
for t in tags:
|
for t in tags:
|
||||||
if filter.tag_exists(t.name) and not filter.is_selected_tag(t.name):
|
if filter.tag_exists(t.name) and not filter.is_selected_tag(t.name):
|
||||||
result += ' ' + t_button(t.name, filter.get_url_add_tag(t.name))
|
if not filter.has_category() or t.category is None or filter.get_categories()[0] == t.category:
|
||||||
|
if filter.has_category():
|
||||||
|
result += ' ' + t_button(t.name, filter.get_url_add_tag(t.name), category=t.category)
|
||||||
|
else:
|
||||||
|
result += ' ' + t_button(t.name, filter.get_url_add_tag(t.name, t.category), category=t.category)
|
||||||
|
|
||||||
return mark_safe(result)
|
return mark_safe(result)
|
||||||
|
@ -309,6 +309,9 @@ class EventFilter(django_filters.FilterSet):
|
|||||||
|
|
||||||
def get_categories(self):
|
def get_categories(self):
|
||||||
return self.get_cleaned_data("category")
|
return self.get_cleaned_data("category")
|
||||||
|
|
||||||
|
def has_category(self):
|
||||||
|
return "category" in self.form.cleaned_data and len(self.get_cleaned_data("category")) > 0
|
||||||
|
|
||||||
def get_tags(self):
|
def get_tags(self):
|
||||||
return self.get_cleaned_data("tags")
|
return self.get_cleaned_data("tags")
|
||||||
@ -393,11 +396,13 @@ class EventFilter(django_filters.FilterSet):
|
|||||||
def is_selected_tag(self, tag):
|
def is_selected_tag(self, tag):
|
||||||
return "tags" in self.form.cleaned_data and tag in self.form.cleaned_data["tags"]
|
return "tags" in self.form.cleaned_data and tag in self.form.cleaned_data["tags"]
|
||||||
|
|
||||||
def get_url_add_tag(self, tag, full_path = None):
|
def get_url_add_tag(self, tag, category=None):
|
||||||
if full_path is None:
|
full_path = self.request.get_full_path()
|
||||||
full_path = self.request.get_full_path()
|
|
||||||
|
|
||||||
result = full_path + ('&' if '?' in full_path else '?') + 'tags=' + str(tag)
|
result = full_path + ('&' if '?' in full_path else '?') + 'tags=' + str(tag)
|
||||||
|
|
||||||
|
if not category is None:
|
||||||
|
result = self.get_url_add_categories([category.pk], result)
|
||||||
return result
|
return result
|
||||||
|
|
||||||
def tag_exists(self, tag):
|
def tag_exists(self, tag):
|
||||||
@ -2084,14 +2089,14 @@ class PlaceFromEventCreateView(PlaceCreateView):
|
|||||||
class TagUpdateView(PermissionRequiredMixin, SuccessMessageMixin, UpdateView):
|
class TagUpdateView(PermissionRequiredMixin, SuccessMessageMixin, UpdateView):
|
||||||
model = Tag
|
model = Tag
|
||||||
permission_required = "agenda_culturel.change_tag"
|
permission_required = "agenda_culturel.change_tag"
|
||||||
fields = ["name", "description", "principal"]
|
fields = ["name", "description", "principal", "category"]
|
||||||
success_message = _("The tag has been successfully updated.")
|
success_message = _("The tag has been successfully updated.")
|
||||||
|
|
||||||
|
|
||||||
class TagCreateView(PermissionRequiredMixin, SuccessMessageMixin, CreateView):
|
class TagCreateView(PermissionRequiredMixin, SuccessMessageMixin, CreateView):
|
||||||
model = Tag
|
model = Tag
|
||||||
permission_required = "agenda_culturel.add_tag"
|
permission_required = "agenda_culturel.add_tag"
|
||||||
fields = ["name", "description", "principal"]
|
fields = ["name", "description", "principal", "category"]
|
||||||
success_message = _("The tag has been successfully created.")
|
success_message = _("The tag has been successfully created.")
|
||||||
|
|
||||||
def get_initial(self, *args, **kwargs):
|
def get_initial(self, *args, **kwargs):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user