Ajout de la gestion des catégories
This commit is contained in:
parent
a54010db02
commit
52745c4012
@ -1,5 +1,6 @@
|
|||||||
from django.contrib import admin
|
from django.contrib import admin
|
||||||
from .models import Event, EventSubmissionForm
|
from .models import Event, EventSubmissionForm, Category
|
||||||
|
|
||||||
admin.site.register(Event)
|
admin.site.register(Event)
|
||||||
admin.site.register(EventSubmissionForm)
|
admin.site.register(EventSubmissionForm)
|
||||||
|
admin.site.register(Category)
|
||||||
|
23
src/agenda_culturel/migrations/0003_category.py
Normal file
23
src/agenda_culturel/migrations/0003_category.py
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
# Generated by Django 4.2.1 on 2023-10-21 14:59
|
||||||
|
|
||||||
|
import colorfield.fields
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('agenda_culturel', '0002_eventsubmissionform_alter_event_reference_urls'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.CreateModel(
|
||||||
|
name='Category',
|
||||||
|
fields=[
|
||||||
|
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||||
|
('name', models.CharField(help_text='Category name', max_length=512, verbose_name='Name')),
|
||||||
|
('codename', models.CharField(help_text='Short name of the category', max_length=3, verbose_name='Short name')),
|
||||||
|
('color', colorfield.fields.ColorField(default='#CCCCCCC', help_text='Color used as background for the category', image_field=None, max_length=25, samples=None, verbose_name='Color')),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
]
|
19
src/agenda_culturel/migrations/0004_alter_category_color.py
Normal file
19
src/agenda_culturel/migrations/0004_alter_category_color.py
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
# Generated by Django 4.2.1 on 2023-10-21 19:18
|
||||||
|
|
||||||
|
import colorfield.fields
|
||||||
|
from django.db import migrations
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('agenda_culturel', '0003_category'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='category',
|
||||||
|
name='color',
|
||||||
|
field=colorfield.fields.ColorField(default='#FFFFFF', help_text='Color used as background for the category', image_field=None, max_length=25, samples=None, verbose_name='Color'),
|
||||||
|
),
|
||||||
|
]
|
@ -0,0 +1,17 @@
|
|||||||
|
# Generated by Django 4.2.1 on 2023-10-21 19:30
|
||||||
|
|
||||||
|
from django.db import migrations
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('agenda_culturel', '0004_alter_category_color'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AlterModelOptions(
|
||||||
|
name='category',
|
||||||
|
options={'verbose_name': 'Category', 'verbose_name_plural': 'Categories'},
|
||||||
|
),
|
||||||
|
]
|
@ -3,11 +3,52 @@ from django.contrib.postgres.fields import ArrayField
|
|||||||
from django.utils.translation import gettext_lazy as _
|
from django.utils.translation import gettext_lazy as _
|
||||||
from django.template.defaultfilters import slugify # new
|
from django.template.defaultfilters import slugify # new
|
||||||
from django.urls import reverse
|
from django.urls import reverse
|
||||||
|
from colorfield.fields import ColorField
|
||||||
|
|
||||||
from django.template.defaultfilters import date as _date
|
from django.template.defaultfilters import date as _date
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
|
||||||
|
|
||||||
|
class Category(models.Model):
|
||||||
|
|
||||||
|
COLOR_PALETTE = [
|
||||||
|
("#ea5545", "color 1"),
|
||||||
|
("#f46a9b", "color 2"),
|
||||||
|
("#ef9b20", "color 3"),
|
||||||
|
("#edbf33", "color 4"),
|
||||||
|
("#ede15b", "color 5"),
|
||||||
|
("#bdcf32", "color 6"),
|
||||||
|
("#87bc45", "color 7"),
|
||||||
|
("#27aeef", "color 8"),
|
||||||
|
("#b33dc6", "color 9")]
|
||||||
|
|
||||||
|
name = models.CharField(verbose_name=_('Name'), help_text=_('Category name'), max_length=512)
|
||||||
|
codename = models.CharField(verbose_name=_('Short name'), help_text=_('Short name of the category'), max_length=3)
|
||||||
|
color = ColorField(verbose_name=_('Color'), help_text=_('Color used as background for the category'), blank=True, null=True)
|
||||||
|
|
||||||
|
def save(self, *args, **kwargs):
|
||||||
|
if self.color is None:
|
||||||
|
existing_colors = [c.color for c in Category.objects.all()]
|
||||||
|
if len(existing_colors) > len(Category.COLOR_PALETTE):
|
||||||
|
self.color = "#CCCCCC"
|
||||||
|
else:
|
||||||
|
for c, n in Category.COLOR_PALETTE:
|
||||||
|
if c not in existing_colors:
|
||||||
|
self.color = c
|
||||||
|
break
|
||||||
|
if self.color is None:
|
||||||
|
self.color = "#CCCCCC"
|
||||||
|
|
||||||
|
super(Category, self).save(*args, **kwargs)
|
||||||
|
|
||||||
|
|
||||||
|
def __str__(self):
|
||||||
|
return self.name + " (" + self.codename + ")"
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
verbose_name = _('Category')
|
||||||
|
verbose_name_plural = _('Categories')
|
||||||
|
|
||||||
class Event(models.Model):
|
class Event(models.Model):
|
||||||
|
|
||||||
class STATUS(models.TextChoices):
|
class STATUS(models.TextChoices):
|
||||||
|
@ -36,6 +36,8 @@ INSTALLED_APPS = [
|
|||||||
"django.contrib.staticfiles",
|
"django.contrib.staticfiles",
|
||||||
"corsheaders",
|
"corsheaders",
|
||||||
"agenda_culturel",
|
"agenda_culturel",
|
||||||
|
"colorfield",
|
||||||
|
'django_extensions',
|
||||||
]
|
]
|
||||||
|
|
||||||
MIDDLEWARE = [
|
MIDDLEWARE = [
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
{% extends "agenda_culturel/page.html" %}
|
{% extends "agenda_culturel/page_events.html" %}
|
||||||
|
|
||||||
{% block title %}{{ object.title }}{% endblock %}
|
{% block title %}{{ object.title }}{% endblock %}
|
||||||
|
|
||||||
{% block content %}
|
{% block events %}
|
||||||
|
|
||||||
<h1>{{ object.title }}</h1>
|
<h1>{{ object.title }}</h1>
|
||||||
<p>Date : {{ object.start_day }}</p>
|
<p>Date : {{ object.start_day }}</p>
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
{% extends "agenda_culturel/page.html" %}
|
{% extends "agenda_culturel/page_event.html" %}
|
||||||
|
|
||||||
{% block title %}Accueil{% endblock %}
|
{% block title %}Accueil{% endblock %}
|
||||||
|
|
||||||
{% block content %}
|
{% block events %}
|
||||||
<h1>Événements</h1>
|
<h1>Événements</h1>
|
||||||
<ul>
|
<ul>
|
||||||
{% for event in object_list %}
|
{% for event in object_list %}
|
||||||
|
@ -0,0 +1,24 @@
|
|||||||
|
{% extends "agenda_culturel/page.html" %}
|
||||||
|
|
||||||
|
{% block content %}
|
||||||
|
<header>
|
||||||
|
<div id="display-mode">
|
||||||
|
TODO
|
||||||
|
</div>
|
||||||
|
<div id="categories">
|
||||||
|
{% for cat in categories %}
|
||||||
|
{% if category == cat %}
|
||||||
|
<span style="background: {{ cat.color }}">{{ cat }}</span>
|
||||||
|
{% else %}
|
||||||
|
<a href="{% url 'view_mode_cat' selected_mode cat.pk %}" style="background: {{ cat.color }}">{{ cat }}</a>
|
||||||
|
{% endif %}
|
||||||
|
{% endfor %}
|
||||||
|
</div>
|
||||||
|
</header>
|
||||||
|
<section>
|
||||||
|
{% block events %}{% endblock %}
|
||||||
|
</section>
|
||||||
|
<footer id="tags">
|
||||||
|
TODO
|
||||||
|
</footer>
|
||||||
|
{% endblock %}
|
@ -16,7 +16,19 @@
|
|||||||
{% endblock %}
|
{% endblock %}
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<div id="full_content" class="{% block classe_principale %}{% endblock %}">
|
<div id="full_content" class="{% block main_class %}{% endblock %}">
|
||||||
{% block content %}{% endblock %}
|
<header>
|
||||||
|
|
||||||
|
</header>
|
||||||
|
<aside>
|
||||||
|
<!-- -->
|
||||||
|
</aside>
|
||||||
|
<section>
|
||||||
|
{% block content %}{% endblock %}
|
||||||
|
</section>
|
||||||
|
<footer>
|
||||||
|
|
||||||
|
</footer>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
</body>
|
</body>
|
@ -7,9 +7,12 @@ from django.urls import path, include, re_path
|
|||||||
|
|
||||||
from .views import *
|
from .views import *
|
||||||
|
|
||||||
|
modes = '|'.join([dm.name for dm in DisplayMode]) + ")"
|
||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
path("", EventListView.as_view(), name="home"),
|
path("", home, name="home"),
|
||||||
re_path(r'^(?P<mode>' + '|'.join([dm.value for dm in DisplayModes]) + ')/$', view_interval, name='view_interval'),
|
re_path(r'^(?P<mode>' + modes + '/$', view_mode, name='view_mode'),
|
||||||
|
re_path(r'^(?P<mode>' + modes + '/(?P<cat_id>\d+)/$', view_mode_cat, name='view_mode_cat'),
|
||||||
path("event/<int:pk>-<extra>", EventDetailView.as_view(), name="view_event"),
|
path("event/<int:pk>-<extra>", EventDetailView.as_view(), name="view_event"),
|
||||||
path("proposer", EventSubmissionFormView.as_view(), name="event_submission_form"),
|
path("proposer", EventSubmissionFormView.as_view(), name="event_submission_form"),
|
||||||
path("admin/", admin.site.urls),
|
path("admin/", admin.site.urls),
|
||||||
|
@ -1,32 +1,44 @@
|
|||||||
from django.shortcuts import render
|
from django.shortcuts import render, get_object_or_404
|
||||||
from django.views.generic import ListView, DetailView, FormView
|
from django.views.generic import ListView, DetailView, FormView
|
||||||
|
|
||||||
from .forms import EventSubmissionModelForm
|
from .forms import EventSubmissionModelForm
|
||||||
from .celery import create_event_from_submission
|
from .celery import create_event_from_submission
|
||||||
|
|
||||||
from .models import Event
|
from .models import Event, Category
|
||||||
from django.utils import timezone
|
from django.utils import timezone
|
||||||
from enum import StrEnum
|
from enum import StrEnum
|
||||||
|
|
||||||
from django.utils.translation import gettext as _
|
from django.utils.translation import gettext as _
|
||||||
|
|
||||||
|
|
||||||
class DisplayModes(StrEnum):
|
class DisplayMode(StrEnum):
|
||||||
this_week = _("this_week")
|
this_week = _("this week")
|
||||||
this_weekend = _("this_weekend")
|
this_weekend = _("this weekend")
|
||||||
next_week = _("next_week")
|
next_week = _("next week")
|
||||||
this_month = _("this_month")
|
this_month = _("this month")
|
||||||
next_month = _("next_month")
|
next_month = _("next month")
|
||||||
|
|
||||||
def view_interval(request, mode):
|
|
||||||
|
|
||||||
context = {}
|
|
||||||
return render(request, 'agenda_culturel/list.html', context)
|
|
||||||
|
|
||||||
|
|
||||||
class EventListView(ListView):
|
def home(request):
|
||||||
model = Event
|
# TODO: si on est au début de la semaine, on affiche la semaine en entier
|
||||||
template_name = "agenda_culturel/home.html"
|
# sinon, on affiche le week-end
|
||||||
|
# sauf si on est dimanche après 23h, on affiche la semaine prochaine
|
||||||
|
return view_mode(request, DisplayMode.this_week)
|
||||||
|
|
||||||
|
|
||||||
|
def view_mode(request, mode):
|
||||||
|
categories = Category.objects.all()
|
||||||
|
context = {"modes": list(DisplayMode), "selected_mode": mode, "categories": categories}
|
||||||
|
# TODO: select matching events
|
||||||
|
return render(request, 'agenda_culturel/page-events.html', context)
|
||||||
|
|
||||||
|
|
||||||
|
def view_mode_cat(request, mode, cat_id):
|
||||||
|
category = get_object_or_404(Category, pk=cat_id)
|
||||||
|
categories = Category.objects.all()
|
||||||
|
# TODO: select matching events
|
||||||
|
context = {"modes": list(DisplayMode), "selected_mode": mode, "category": category, "categories": categories}
|
||||||
|
return render(request, 'agenda_culturel/page-events.html', context)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -23,3 +23,6 @@ whitenoise==6.4.0
|
|||||||
selenium==4.14.0
|
selenium==4.14.0
|
||||||
BeautifulSoup4==4.12.2
|
BeautifulSoup4==4.12.2
|
||||||
watchdog==3.0.0
|
watchdog==3.0.0
|
||||||
|
django-colorfield==0.10.1
|
||||||
|
cffi==1.16.0
|
||||||
|
django-extensions==3.2.3
|
||||||
|
0
src/scripts/__init__.py
Normal file
0
src/scripts/__init__.py
Normal file
25
src/scripts/create_categories.py
Normal file
25
src/scripts/create_categories.py
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
from agenda_culturel.models import Category
|
||||||
|
|
||||||
|
def run():
|
||||||
|
# concert, théâtre, jeune public, danse, arts du spectacle, exposition
|
||||||
|
# conférence, nature,
|
||||||
|
# divers
|
||||||
|
|
||||||
|
categories = [
|
||||||
|
("Théâtre", "THÉ"),
|
||||||
|
("Concert", "CCR"),
|
||||||
|
("Danse", "DSE"),
|
||||||
|
("Arts du spectacle", "SPE"),
|
||||||
|
("Jeune public", "JEP"),
|
||||||
|
("Exposition", "EXP"),
|
||||||
|
("Conférence", "CNF"),
|
||||||
|
("Nature", "NTR"),
|
||||||
|
("Divers", "DIV")
|
||||||
|
]
|
||||||
|
|
||||||
|
if len(Category.objects.all()) == 0:
|
||||||
|
print("On créée des catégories")
|
||||||
|
for c in categories:
|
||||||
|
cat = Category(name=c[0], codename=c[1])
|
||||||
|
cat.save()
|
||||||
|
|
Loading…
Reference in New Issue
Block a user