From d1d0980778f01e1addb698f4fc72ea6ae8041f82 Mon Sep 17 00:00:00 2001 From: Lucie Galland Date: Mon, 9 Aug 2021 12:41:44 +0200 Subject: [PATCH] ev only for chefs --- calendrier/admin.py | 6 +- calendrier/calend.py | 9 ++- .../migrations/0005_auto_20210726_0949.py | 28 +++++++++ calendrier/models.py | 6 +- calendrier/templates/calendrier/home.html | 63 ++++++++++++++++++- calendrier/templates/calendrier/reponse.html | 7 +++ .../templates/calendrier/view_event.html | 11 +++- calendrier/views.py | 42 +++++++++---- gestion/templates/gestion/chef.html | 2 + 9 files changed, 153 insertions(+), 21 deletions(-) create mode 100644 calendrier/migrations/0005_auto_20210726_0949.py diff --git a/calendrier/admin.py b/calendrier/admin.py index 90156b7..bd7204d 100644 --- a/calendrier/admin.py +++ b/calendrier/admin.py @@ -1,6 +1,6 @@ -# from django.contrib import admin +from django.contrib import admin -# from .models import Event +from .models import Event # Add event by admin page return a 502 error -# admin.site.register(Event) +admin.site.register(Event) diff --git a/calendrier/calend.py b/calendrier/calend.py index 0701527..c90075e 100644 --- a/calendrier/calend.py +++ b/calendrier/calend.py @@ -20,8 +20,13 @@ class EventCalendar(HTMLCalendar): cssclass += " filled" body = [] for ev in self.events[day]: - body.append(_('' % ev.id) - body.append(esc(ev.nom)) + body.append(_(''+esc(ev.nom)) + elif ev.calendrier == "D": + body.append('style="color:#a9008a">'+esc(ev.nom)) + else: + body.append('>'+esc(ev.nom)) body.append("
") return self.day_cell( cssclass, diff --git a/calendrier/migrations/0005_auto_20210726_0949.py b/calendrier/migrations/0005_auto_20210726_0949.py new file mode 100644 index 0000000..59164a4 --- /dev/null +++ b/calendrier/migrations/0005_auto_20210726_0949.py @@ -0,0 +1,28 @@ +# Generated by Django 2.2.24 on 2021-07-26 07:49 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('calendrier', '0004_auto_20210606_1640'), + ] + + operations = [ + migrations.AlterField( + model_name='event', + name='calendrier', + field=models.CharField(choices=[('F', 'Visible seulement par les fanfarons'), ('T', 'Afficher dans le calendrier pour tous'), ('H', 'Hall of fame'), ('C', 'Visible seulement par les cheff·e·s'), ('D', "Visible seulement par les cheff·e·s et sur l'agenda public")], default='F', max_length=1), + ), + migrations.AlterField( + model_name='event', + name='desc_users', + field=models.TextField(blank=True, null=True, verbose_name='Infos (visible seulement des fanfaron·ne·s)'), + ), + migrations.AlterField( + model_name='event', + name='desc_users_en', + field=models.TextField(blank=True, null=True, verbose_name='Infos en anglais (visible seulement des fanfaron·ne·s'), + ), + ] diff --git a/calendrier/models.py b/calendrier/models.py index 5dea4a8..5e42fb7 100644 --- a/calendrier/models.py +++ b/calendrier/models.py @@ -27,18 +27,20 @@ class Event(models.Model): description_en = models.TextField(blank=True) desc_users = models.TextField( blank=True, - verbose_name=_("Infos (visible seulement des fanfaron-ne-s)"), + verbose_name=_("Infos (visible seulement des fanfaron·ne·s)"), null=True, ) desc_users_en = models.TextField( blank=True, - verbose_name=_("Infos en anglais (visible seulement des fanfaron-ne-s"), + verbose_name=_("Infos en anglais (visible seulement des fanfaron·ne·s"), null=True, ) CALENDRIER_CHOICES = [ ("F", _("Visible seulement par les fanfarons")), ("T", _("Afficher dans le calendrier pour tous")), ("H", _("Hall of fame")), + ("C", _("Visible seulement par les cheff·e·s")), + ("D", _("Visible seulement par les cheff·e·s et sur l'agenda public")), ] calendrier = models.CharField( max_length=1, diff --git a/calendrier/templates/calendrier/home.html b/calendrier/templates/calendrier/home.html index 39130d3..87d7e62 100644 --- a/calendrier/templates/calendrier/home.html +++ b/calendrier/templates/calendrier/home.html @@ -60,13 +60,21 @@
+ {% if user.is_superuser or user.profile.is_chef %} + {% ifequal current_language "fr" %} + {{Calendar_chef|translate}} + {% else %} + {{Calendar_chef}} + {% endifequal %} + {% else %} {% ifequal current_language "fr" %} {{Calendar|translate}} {% else %} {{Calendar}} {% endifequal %} + {% endif%}
-{% if user.profile.is_chef %} +{% if user.is_superuser or user.profile.is_chef %} {% trans "Ajouter un évènement" %} {% endif %} @@ -90,7 +98,60 @@ {% endif %} + {% if user.is_superuser or user.profile.is_chef %} + {% if events_a_venir_chef %} +
+

{% blocktrans count counter=events_a_venir_chef|length %}Doodle seulement visible par les cheff·e·s :{% plural %}Doodles seulement visibles par les cheff·e·s :{% endblocktrans %}

+
+ + + + + + + + + + {% for e in events_a_venir_chef %} + + + + + + {% endfor %} + +
{% trans "Nom" %}{% trans "Date" %}{% trans "Lieu" %}
{{ e.nom }}{% blocktrans with date=e.date debut=e.debut %}Le {{ date }} à {{ debut }} {% endblocktrans %} {{e.lieu}}
+
+
+ {% endif %} + {% if events_a_venir_chef_public %} +
+

{% blocktrans count counter=events_a_venir_chef_public|length %}Doodle visible par les cheff·e·s et le public :{% plural %}Doodles seulement visibles par les cheff·e·s :{% endblocktrans %}

+
+ + + + + + + + + + {% for e in events_a_venir_chef_public %} + + + + + + + {% endfor %} + +
{% trans "Nom" %}{% trans "Date" %}{% trans "Lieu" %}
{{ e.nom }}{% blocktrans with date=e.date debut=e.debut %}Le {{ date }} à {{ debut }} {% endblocktrans %} {{e.lieu}}
+
+
+ {% endif %} + {% endif %} {% if events_a_venir_not_answered %}

{% blocktrans count counter=events_a_venir_not_answered|length %}Doodle à remplir !!!! :{% plural %}Doodles à remplir !!!! :{% endblocktrans %}

diff --git a/calendrier/templates/calendrier/reponse.html b/calendrier/templates/calendrier/reponse.html index 467d772..e222c53 100644 --- a/calendrier/templates/calendrier/reponse.html +++ b/calendrier/templates/calendrier/reponse.html @@ -6,6 +6,12 @@
+ {% if not user.is_superuser or not user.profile.is_chef %} + {% if user.is_superuser or user.profile.is_chef %} + {% trans "Cet événement est encore en construction ! Reviens plus tard." %} + {% endif %} + {% endif %} + {% if user.is_superuser or user.profile.is_chef or not chef_only%}
{% if envoi %}

{% trans "Votre réponse a été enregistrée !" %}

{% endif %} @@ -47,6 +53,7 @@
+{% endif %}
diff --git a/calendrier/templates/calendrier/view_event.html b/calendrier/templates/calendrier/view_event.html index c10247b..cd59955 100644 --- a/calendrier/templates/calendrier/view_event.html +++ b/calendrier/templates/calendrier/view_event.html @@ -8,10 +8,16 @@
+ {% if not user.is_superuser or not user.profile.is_chef %} + {% if chef_only %} + {% trans "Cet événement est encore en construction ! Reviens plus tard." %} + {% endif %} + {% endif %} + {% if user.is_superuser or user.profile.is_chef or not chef_only%}
-
+

{{ event.nom.capitalize }}

{% blocktrans with date=event.date%} Le {{ date }}{% endblocktrans %} @@ -34,7 +40,7 @@

{{event.desc_users_en|safe}}

{% endif %} -
+
{% if user.is_authenticated %} @@ -205,6 +211,7 @@ {% endif %}
+{% endif %}
diff --git a/calendrier/views.py b/calendrier/views.py index 1127949..84a81a0 100644 --- a/calendrier/views.py +++ b/calendrier/views.py @@ -45,6 +45,7 @@ class Agenda(TemplateView): context["events_a_venir"] = ( Event.objects.filter(date__gte=lToday) .exclude(calendrier__iexact="F") + .exclude(calendrier__iexact="C") .order_by("date") ) context["events_passe"] = ( @@ -71,14 +72,18 @@ class Calendar(LoginRequiredMixin, TemplateView): actu = Actu.objects.all() photo = Photo.objects.filter(cat="home").order_by("?").first() lToday = datetime.now() - lYear = int(self.pYear) - lMonth = int(self.pMonth) + lYear = int(lToday.year) + lMonth = int(lToday.month) lCalendarFromMonth = datetime(lYear, lMonth, 1) lCalendarToMonth = datetime(lYear, lMonth, monthrange(lYear, lMonth)[1]) lEvents = Event.objects.filter( date__gte=lCalendarFromMonth, date__lte=lCalendarToMonth - ) + ).exclude(calendrier__iexact="C").exclude(calendrier__iexact="D") + lEvents_chef = Event.objects.filter( + date__gte=lCalendarFromMonth, date__lte=lCalendarToMonth + ).filter(calendrier__in=["C","D"]) lCalendar = EventCalendar(lEvents).formatmonth(lYear, lMonth) + lCalendar_chef = EventCalendar(lEvents_chef).formatmonth(lYear, lMonth) lPreviousYear = lYear lPreviousMonth = lMonth - 1 if lPreviousMonth == 0: @@ -95,6 +100,8 @@ class Calendar(LoginRequiredMixin, TemplateView): events_a_venir_not_answered = ( Event.objects.filter(date__gte=lToday) .exclude(participants__participant=self.request.user.profile) + .exclude(calendrier__iexact="C") + .exclude(calendrier__iexact="D") .order_by("date") ) events_a_venir_answered_yes = ( @@ -103,6 +110,8 @@ class Calendar(LoginRequiredMixin, TemplateView): Q(participants__participant=self.request.user.profile) & Q(participants__reponse="oui") ) + .exclude(calendrier__iexact="C") + .exclude(calendrier__iexact="D") .order_by("date") ) events_a_venir_answered_no = ( @@ -111,6 +120,8 @@ class Calendar(LoginRequiredMixin, TemplateView): Q(participants__participant=self.request.user.profile) & Q(participants__reponse="non") ) + .exclude(calendrier__iexact="C") + .exclude(calendrier__iexact="D") .order_by("date") ) events_a_venir_answered_pe = ( @@ -119,10 +130,23 @@ class Calendar(LoginRequiredMixin, TemplateView): Q(participants__participant=self.request.user.profile) & Q(participants__reponse="pe") ) + .exclude(calendrier__iexact="C") + .exclude(calendrier__iexact="D") + .order_by("date") + ) + events_a_venir_chef = ( + Event.objects.filter(date__gte=lToday) + .filter(calendrier__in=["C"]) + .order_by("date") + ) + events_a_venir_chef_public = ( + Event.objects.filter(date__gte=lToday) + .filter(calendrier__in=["D"]) .order_by("date") ) context["Calendar"] = mark_safe(lCalendar) + context["Calendar_chef"] = mark_safe(lCalendar_chef) context["Month"] = lMonth context["MonthName"] = named_month(lMonth) context["Year"] = lYear @@ -138,6 +162,8 @@ class Calendar(LoginRequiredMixin, TemplateView): context["events_a_venir_answered_no"] = events_a_venir_answered_no context["events_a_venir_answered_pe"] = events_a_venir_answered_pe context["events_a_venir_not_answered"] = events_a_venir_not_answered + context["events_a_venir_chef"] = events_a_venir_chef + context["events_a_venir_chef_public"] = events_a_venir_chef_public context["actu"] = actu context["photo"] = photo return context @@ -146,14 +172,6 @@ class Calendar(LoginRequiredMixin, TemplateView): class Home(Calendar): lToday = datetime.now() - @property - def pYear(self): - return self.lToday.year - - @property - def pMonth(self): - return self.lToday.month - class ViewEvent(LoginRequiredMixin, TemplateView): template_name = "calendrier/view_event.html" @@ -222,6 +240,7 @@ class ViewEvent(LoginRequiredMixin, TemplateView): context["nbpe"] = len(participants.filter(reponse="pe")) context["nbnon"] = len(participants.filter(reponse="non")) context["multi_instrumentistes"] = multi_instrumentistes + context["chef_only"] = (event.calendrier == "C")|(event.calendrier == "D") return context @@ -297,6 +316,7 @@ class ReponseEvent(LoginRequiredMixin, TemplateView): context["form"] = self.form_class() context["ev"] = get_object_or_404(Event, id=self.kwargs["id"]) context["id"] = self.kwargs["id"] + context["chef_only"] = (context["ev"].calendrier == "C")|(context["ev"].calendrier == "D") return context def post(self, request, *args, **kwargs): diff --git a/gestion/templates/gestion/chef.html b/gestion/templates/gestion/chef.html index 031f26e..8b3bc46 100644 --- a/gestion/templates/gestion/chef.html +++ b/gestion/templates/gestion/chef.html @@ -13,6 +13,8 @@
  • {% trans "Administration" %}
  • {% trans "Ajouter un événement" %}
  • {% trans "Modifier les actualités" %}
  • +
  • {% trans "Modifier les photos" %}
  • +
  • {% trans "Modifier les vidéos" %}