mirror of
				https://gitlab.com/animath/si/plateforme.git
				synced 2025-11-04 00:52:03 +01:00 
			
		
		
		
	Add button to update notes
Signed-off-by: Emmy D'Anello <emmy.danello@animath.fr>
This commit is contained in:
		@@ -936,13 +936,13 @@ class Note(models.Model):
 | 
			
		||||
    def get_absolute_url(self):
 | 
			
		||||
        return reverse_lazy("participation:passage_detail", args=(self.passage.pk,))
 | 
			
		||||
 | 
			
		||||
    @property
 | 
			
		||||
    def modal_name(self):
 | 
			
		||||
        return f"updateNotes{self.pk}"
 | 
			
		||||
 | 
			
		||||
    def __str__(self):
 | 
			
		||||
        return _("Notes of {jury} for {passage}").format(jury=self.jury, passage=self.passage)
 | 
			
		||||
 | 
			
		||||
    def __bool__(self):
 | 
			
		||||
        return any((self.defender_writing, self.defender_oral, self.opponent_writing, self.opponent_oral,
 | 
			
		||||
                   self.reporter_writing, self.reporter_oral, self.observer_oral))
 | 
			
		||||
 | 
			
		||||
    class Meta:
 | 
			
		||||
        verbose_name = _("note")
 | 
			
		||||
        verbose_name_plural = _("notes")
 | 
			
		||||
 
 | 
			
		||||
@@ -1,7 +1,8 @@
 | 
			
		||||
# Copyright (C) 2020 by Animath
 | 
			
		||||
# SPDX-License-Identifier: GPL-3.0-or-later
 | 
			
		||||
 | 
			
		||||
from django.urls import reverse_lazy
 | 
			
		||||
from django.utils import formats
 | 
			
		||||
from django.utils.safestring import mark_safe
 | 
			
		||||
from django.utils.text import format_lazy
 | 
			
		||||
from django.utils.translation import gettext_lazy as _
 | 
			
		||||
import django_tables2 as tables
 | 
			
		||||
@@ -137,10 +138,21 @@ class NoteTable(tables.Table):
 | 
			
		||||
        }
 | 
			
		||||
    )
 | 
			
		||||
 | 
			
		||||
    update = tables.Column(
 | 
			
		||||
        verbose_name=_("Update"),
 | 
			
		||||
        accessor="id",
 | 
			
		||||
        empty_values=(),
 | 
			
		||||
    )
 | 
			
		||||
 | 
			
		||||
    def render_update(self, record):
 | 
			
		||||
        return mark_safe(f'<button class="btn btn-info" data-bs-toggle="modal" '
 | 
			
		||||
                         f'data-bs-target="#{record.modal_name}Modal">'
 | 
			
		||||
                         f'{_("Update")}</button>')
 | 
			
		||||
 | 
			
		||||
    class Meta:
 | 
			
		||||
        attrs = {
 | 
			
		||||
            'class': 'table table-condensed table-striped text-center',
 | 
			
		||||
        }
 | 
			
		||||
        model = Note
 | 
			
		||||
        fields = ('jury', 'defender_writing', 'defender_oral', 'opponent_writing', 'opponent_oral',
 | 
			
		||||
                  'reporter_writing', 'reporter_oral', 'observer_oral',)
 | 
			
		||||
                  'reporter_writing', 'reporter_oral', 'observer_oral', 'update',)
 | 
			
		||||
 
 | 
			
		||||
@@ -5,6 +5,8 @@
 | 
			
		||||
{% block content %}
 | 
			
		||||
    <form method="post">
 | 
			
		||||
        <div id="form-content">
 | 
			
		||||
            <h4>{% trans "Notes of" %} {{ note.jury }}</h4>
 | 
			
		||||
            <hr>
 | 
			
		||||
            {% csrf_token %}
 | 
			
		||||
            {{ form|crispy }}
 | 
			
		||||
        </div>
 | 
			
		||||
 
 | 
			
		||||
@@ -49,7 +49,7 @@
 | 
			
		||||
        {% if notes is not None %}
 | 
			
		||||
            <div class="card-footer text-center">
 | 
			
		||||
                {% if my_note is not None %}
 | 
			
		||||
                    <button class="btn btn-info" data-bs-toggle="modal" data-bs-target="#updateNotesModal">{% trans "Update notes" %}</button>
 | 
			
		||||
                    <button class="btn btn-info" data-bs-toggle="modal" data-bs-target="#{{ my_note.modal_name }}Modal">{% trans "Update notes" %}</button>
 | 
			
		||||
                {% endif %}
 | 
			
		||||
                <button class="btn btn-primary" data-bs-toggle="modal" data-bs-target="#updatePassageModal">{% trans "Update" %}</button>
 | 
			
		||||
            </div>
 | 
			
		||||
@@ -121,12 +121,12 @@
 | 
			
		||||
        {% url "participation:passage_update" pk=passage.pk as modal_action %}
 | 
			
		||||
        {% include "base_modal.html" with modal_id="updatePassage" %}
 | 
			
		||||
 | 
			
		||||
        {% if my_note is not None %}
 | 
			
		||||
        {% for note in notes.data %}
 | 
			
		||||
            {% trans "Update notes" as modal_title %}
 | 
			
		||||
            {% trans "Update" as modal_button %}
 | 
			
		||||
            {% url "participation:update_notes" pk=my_note.pk as modal_action %}
 | 
			
		||||
            {% include "base_modal.html" with modal_id="updateNotes" %}
 | 
			
		||||
        {% endif %}
 | 
			
		||||
            {% url "participation:update_notes" pk=note.pk as modal_action %}
 | 
			
		||||
            {% include "base_modal.html" with modal_id=note.modal_name %}
 | 
			
		||||
        {% endfor %}
 | 
			
		||||
    {% elif user.registration.participates %}
 | 
			
		||||
        {% trans "Upload synthesis" as modal_title %}
 | 
			
		||||
        {% trans "Upload" as modal_button %}
 | 
			
		||||
@@ -141,9 +141,9 @@
 | 
			
		||||
            {% if notes is not None %}
 | 
			
		||||
                initModal("updatePassage", "{% url "participation:passage_update" pk=passage.pk %}")
 | 
			
		||||
 | 
			
		||||
                {% if my_note is not None %}
 | 
			
		||||
                    initModal("updateNotes", "{% url "participation:update_notes" pk=my_note.pk %}")
 | 
			
		||||
                {% endif %}
 | 
			
		||||
              {% for note in notes.data %}
 | 
			
		||||
                initModal("{{ note.modal_name }}", "{% url "participation:update_notes" pk=note.pk %}")
 | 
			
		||||
            {% endfor %}
 | 
			
		||||
            {% elif user.registration.participates %}
 | 
			
		||||
                initModal("uploadSynthesis", "{% url "participation:upload_synthesis" pk=passage.pk %}")
 | 
			
		||||
            {% endif %}
 | 
			
		||||
 
 | 
			
		||||
@@ -1527,9 +1527,9 @@ class PassageDetailView(LoginRequiredMixin, DetailView):
 | 
			
		||||
        context = super().get_context_data(**kwargs)
 | 
			
		||||
        if self.request.user.registration in self.object.pool.juries.all():
 | 
			
		||||
            context["my_note"] = Note.objects.get_or_create(passage=self.object, jury=self.request.user.registration)[0]
 | 
			
		||||
            context["notes"] = NoteTable([note for note in self.object.notes.all() if note])
 | 
			
		||||
            context["notes"] = NoteTable(self.object.notes.all())
 | 
			
		||||
        elif self.request.user.registration.is_admin:
 | 
			
		||||
            context["notes"] = NoteTable([note for note in self.object.notes.all() if note])
 | 
			
		||||
            context["notes"] = NoteTable(self.object.notes.all())
 | 
			
		||||
        if 'notes' in context and not self.object.observer:
 | 
			
		||||
            # Only display the observer column for 4-teams pools
 | 
			
		||||
            context['notes']._sequence.pop()
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user