From b260ae8eb86483b7203fe7b6792998223602598d Mon Sep 17 00:00:00 2001 From: Lucie Galland Date: Mon, 7 Jun 2021 00:56:03 +0200 Subject: [PATCH] add photo/video from site + choice instru in response event --- Ernestophone/urls.py | 20 + calendrier/admin.py | 7 +- calendrier/forms.py | 2 +- .../migrations/0004_auto_20210606_1640.py | 28 + calendrier/models.py | 8 + calendrier/templates/calendrier/reponse.html | 42 +- calendrier/templates/calendrier/response.html | 17 - .../templates/calendrier/view_event.html | 16 +- calendrier/views.py | 55 +- gestion/static/js/main.js | 15 +- gestion/templates/gestion/base.html | 14 +- gestion/templates/gestion/create_photo.html | 19 + gestion/templates/gestion/create_video.html | 19 + gestion/templates/gestion/delete_photo.html | 16 + gestion/templates/gestion/delete_video.html | 16 + gestion/templates/gestion/photo.html | 42 ++ gestion/templates/gestion/update_photo.html | 15 + gestion/templates/gestion/update_video.html | 15 + gestion/templates/gestion/video.html | 30 ++ gestion/views.py | 71 ++- .../templates/instruments/create_instru.html | 2 +- locale/en/LC_MESSAGES/django.mo | Bin 20093 -> 24113 bytes locale/en/LC_MESSAGES/django.po | 504 ++++++++++-------- 23 files changed, 687 insertions(+), 286 deletions(-) create mode 100644 calendrier/migrations/0004_auto_20210606_1640.py delete mode 100644 calendrier/templates/calendrier/response.html create mode 100644 gestion/templates/gestion/create_photo.html create mode 100644 gestion/templates/gestion/create_video.html create mode 100644 gestion/templates/gestion/delete_photo.html create mode 100644 gestion/templates/gestion/delete_video.html create mode 100644 gestion/templates/gestion/photo.html create mode 100644 gestion/templates/gestion/update_photo.html create mode 100644 gestion/templates/gestion/update_video.html create mode 100644 gestion/templates/gestion/video.html diff --git a/Ernestophone/urls.py b/Ernestophone/urls.py index a04aa58..081e0d5 100644 --- a/Ernestophone/urls.py +++ b/Ernestophone/urls.py @@ -46,6 +46,26 @@ urlpatterns += i18n_patterns( path("trombonoscope/", include("trombonoscope.urls")), path("actu/", include("actu.urls")), path("avatar/", include("avatar.urls")), + path("photos", gestion_views.PhotoList.as_view(), name="liste_photo"), + path("add_photo", gestion_views.PhotoCreate.as_view(), name="add_photo"), + path( + "photo_edition/", gestion_views.PhotoUpdate.as_view(), name="edit_photo" + ), + path( + "photo_delete/", + gestion_views.PhotoDelete.as_view(), + name="delete_photo", + ), + path("videos", gestion_views.VideoList.as_view(), name="liste_video"), + path("add_video", gestion_views.VideoCreate.as_view(), name="add_video"), + path( + "video_edition/", gestion_views.VideoUpdate.as_view(), name="edit_video" + ), + path( + "video_delete/", + gestion_views.VideoDelete.as_view(), + name="delete_video", + ), prefix_default_language=False, ) urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT) diff --git a/calendrier/admin.py b/calendrier/admin.py index 2d241a6..90156b7 100644 --- a/calendrier/admin.py +++ b/calendrier/admin.py @@ -1,5 +1,6 @@ -from django.contrib import admin +# from django.contrib import admin -from .models import Event +# from .models import Event -admin.site.register(Event) +# Add event by admin page return a 502 error +# admin.site.register(Event) diff --git a/calendrier/forms.py b/calendrier/forms.py index 3c112a1..2b67099 100644 --- a/calendrier/forms.py +++ b/calendrier/forms.py @@ -37,7 +37,7 @@ class EventForm(forms.ModelForm): class ParticipantsForm(forms.ModelForm): class Meta: model = Participants - fields = ("reponse", "details") + fields = ("reponse", "details", "dont_play_main", "instrument") widgets = { "details": forms.Textarea(attrs={"placeholder": _("50 caractères max")}), } diff --git a/calendrier/migrations/0004_auto_20210606_1640.py b/calendrier/migrations/0004_auto_20210606_1640.py new file mode 100644 index 0000000..d743552 --- /dev/null +++ b/calendrier/migrations/0004_auto_20210606_1640.py @@ -0,0 +1,28 @@ +# Generated by Django 2.2.17 on 2021-06-06 16:40 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ("calendrier", "0003_auto_20210427_1834"), + ] + + operations = [ + migrations.AddField( + model_name="participants", + name="dont_play_main", + field=models.CharField( + choices=[("Non", "Non"), ("Oui", "Oui")], + default="Non", + max_length=3, + verbose_name="Je veux jouer d'un instrument different de mon instrument principal:", + ), + ), + migrations.AddField( + model_name="participants", + name="instrument", + field=models.CharField(blank=True, max_length=50, null=True), + ), + ] diff --git a/calendrier/models.py b/calendrier/models.py index 00033e9..5dea4a8 100644 --- a/calendrier/models.py +++ b/calendrier/models.py @@ -59,4 +59,12 @@ class Participants(models.Model): reponse = models.CharField( _("Réponse"), max_length=20, default="non", choices=ANSWERS ) + instrument = models.CharField(max_length=50, blank=True, null=True) + dont_play_main = models.CharField( + _("Je veux jouer d'un instrument different de mon instrument principal:"), + default="Non", + null=False, + max_length=3, + choices=[("Non", _("Non")), ("Oui", _("Oui"))], + ) details = models.CharField(max_length=50, blank=True) diff --git a/calendrier/templates/calendrier/reponse.html b/calendrier/templates/calendrier/reponse.html index e8ba760..467d772 100644 --- a/calendrier/templates/calendrier/reponse.html +++ b/calendrier/templates/calendrier/reponse.html @@ -13,10 +13,36 @@

{% trans "Retour à l'événement" %}

{% blocktrans with nom=ev.nom date=ev.date debut=ev.debut|time:"H:i" %} Voulez vous participer à l'événement {{ nom }}, le {{ date }} à {{ debut }} ?{% endblocktrans %}

+

{% trans "Instrument principal"%} : {% if request.user.profile.instru == "Autre" %}{{request.user.profile.instru_autre}}{% else %}{{request.user.profile.instru}}{% endif %}

+
{% csrf_token %} - {{ form.as_p }} + {{ form.non_field_errors }} + {% for field in form %} +
+ {{ field.errors }} + + + {% if field.id_for_label == "id_dont_play_main" %} + + @@ -25,3 +51,17 @@
{% endblock %} + +{% block script %} + +{% endblock %} diff --git a/calendrier/templates/calendrier/response.html b/calendrier/templates/calendrier/response.html deleted file mode 100644 index 1e52df5..0000000 --- a/calendrier/templates/calendrier/response.html +++ /dev/null @@ -1,17 +0,0 @@ -{% extends "gestion/base.html" %} -{% load i18n %} -{% block titre %}{% trans "Participation à un événement" %}{% endblock %} - -{% block content %} -{% if envoi %}

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

{% endif %} - - -

{% trans "Retour à l'événement" %}

-
{% blocktrans with nom=ev.nom date=ev.date debut=ev.debut%} Voulez vous participer à l'événement {{ nom }}, le {{ date }} à {{ debut|time:"H:i" }} ?{% endblocktrans %}
- -
- {% csrf_token %} - {{ form.as_p }} - -
-{% endblock %} diff --git a/calendrier/templates/calendrier/view_event.html b/calendrier/templates/calendrier/view_event.html index e53faef..c10247b 100644 --- a/calendrier/templates/calendrier/view_event.html +++ b/calendrier/templates/calendrier/view_event.html @@ -160,7 +160,7 @@ - + @@ -173,12 +173,22 @@ {% endif %} - - + {% endfor %} diff --git a/calendrier/views.py b/calendrier/views.py index c62eab8..bf84156 100644 --- a/calendrier/views.py +++ b/calendrier/views.py @@ -45,7 +45,7 @@ class Agenda(TemplateView): context["events_a_venir"] = ( Event.objects.filter(date__gte=lToday) .exclude(calendrier__iexact="F") - .order_by("-date") + .order_by("date") ) context["events_passe"] = ( Event.objects.filter(date__lt=lToday) @@ -91,38 +91,36 @@ class Calendar(LoginRequiredMixin, TemplateView): lNextYear = lYear + 1 lYearAfterThis = lYear + 1 lYearBeforeThis = lYear - 1 - try: - events_a_venir_not_answered = Event.objects.filter( - date__gte=lToday - ).exclude(participants__participant=self.request.user.profile) - events_a_venir_answered_yes = Event.objects.filter(date__gte=lToday).filter( + + events_a_venir_not_answered = ( + Event.objects.filter(date__gte=lToday) + .exclude(participants__participant=self.request.user.profile) + .order_by("date") + ) + events_a_venir_answered_yes = ( + Event.objects.filter(date__gte=lToday) + .filter( Q(participants__participant=self.request.user.profile) & Q(participants__reponse="oui") ) - events_a_venir_answered_no = Event.objects.filter(date__gte=lToday).filter( + .order_by("date") + ) + events_a_venir_answered_no = ( + Event.objects.filter(date__gte=lToday) + .filter( Q(participants__participant=self.request.user.profile) & Q(participants__reponse="non") ) - events_a_venir_answered_pe = Event.objects.filter(date__gte=lToday).filter( + .order_by("date") + ) + events_a_venir_answered_pe = ( + Event.objects.filter(date__gte=lToday) + .filter( Q(participants__participant=self.request.user.profile) & Q(participants__reponse="pe") ) - except Event.DoesNotExist: - events_a_venir_not_answered = Event.objects.filter( - date__gte=lToday - ).exclude(participants__participant__user__username=self.request.user) - events_a_venir_answered_yes = Event.objects.filter(date__gte=lToday).filter( - Q(participants__participant__user__username=self.request.user) - & Q(participants__reponse="oui") - ) - events_a_venir_answered_no = Event.objects.filter(date__gte=lToday).filter( - Q(participants__participant__user__username=self.request.user) - & Q(participants__reponse="non") - ) - events_a_venir_answered_pe = Event.objects.filter(date__gte=lToday).filter( - Q(participants__participant__user__username=self.request.user) - & Q(participants__reponse="pe") - ) + .order_by("date") + ) context["Calendar"] = mark_safe(lCalendar) context["Month"] = lMonth @@ -178,6 +176,8 @@ class ViewEvent(LoginRequiredMixin, TemplateView): instru = participant.participant.instru if instru == "Autre": instru = participant.participant.instru_autre + if participant.dont_play_main == "Oui": + instru = participant.instrument sure, maybe, namesoui, namespe, namesnon = instrument_count[instru] @@ -286,7 +286,12 @@ class ReponseEvent(LoginRequiredMixin, TemplateView): def get_context_data(self, **kwargs): context = super().get_context_data(**kwargs) - context["form"] = self.form_class() + ev = get_object_or_404(Event, id=self.kwargs["id"]) + context["form"] = self.form_class( + instance=get_object_or_404( + Participants, event=ev, participant=self.request.user.profile + ) + ) context["ev"] = get_object_or_404(Event, id=self.kwargs["id"]) context["id"] = self.kwargs["id"] return context diff --git a/gestion/static/js/main.js b/gestion/static/js/main.js index f25ca6c..ba20001 100755 --- a/gestion/static/js/main.js +++ b/gestion/static/js/main.js @@ -41,18 +41,7 @@ ); }); - // Menu. - $('#menu') - .append('') - .appendTo($body) - .panel({ - delay: 500, - hideOnClick: true, - hideOnSwipe: true, - resetScroll: true, - resetForms: true, - side: 'right' - }); + $('#id_multi_instrumentiste').on('change', function() { @@ -64,6 +53,8 @@ } }); + + $('#id_instru').on('change', function() { diff --git a/gestion/templates/gestion/base.html b/gestion/templates/gestion/base.html index dfb85da..a3a4b88 100644 --- a/gestion/templates/gestion/base.html +++ b/gestion/templates/gestion/base.html @@ -28,7 +28,7 @@
{% trans "Nom" %}{% trans "Instrument principal" %}{% trans "Instrument" %} {% trans "Instrument·s bonus" %} {% trans "Réponse" %}
{% if participant.participant.instru == "Autre" %} + {% if participant.dont_play_main == 'Oui' %} + {{participant.instrument}} + {% elif participant.participant.instru == "Autre" %} {{participant.participant.instru_autre}} {% else %} {{ participant.participant.instru }} {% endif %}{{ participant.participant.instru_bonus }}{% if participant.dont_play_main == 'Oui' %} + {% if participant.participant.instru == "Autre" %} + {{participant.participant.instru_autre}} + {% else %} + {{ participant.participant.instru }} + {% endif %}
{% endif %} + {% if participant.instrument != participant.participant.instru_bonus %} + {{ participant.participant.instru_bonus }} + {% endif %}
{{participant.reponse}}