mirror of
https://gitlab.com/animath/si/plateforme-corres2math.git
synced 2025-06-21 13:18:22 +02:00
Update calendar
This commit is contained in:
@ -80,6 +80,17 @@ class PhaseForm(forms.ModelForm):
|
||||
model = Phase
|
||||
fields = ('start', 'end',)
|
||||
widgets = {
|
||||
'start': DateTimePickerInput(),
|
||||
'end': DateTimePickerInput(),
|
||||
'start': DateTimePickerInput(format='%d/%m/%Y %H:%M'),
|
||||
'end': DateTimePickerInput(format='%d/%m/%Y %H:%M'),
|
||||
}
|
||||
|
||||
def clean(self):
|
||||
# Ensure that dates are in a right order
|
||||
cleaned_data = super().clean()
|
||||
if cleaned_data["end"] <= cleaned_data["start"]:
|
||||
self.add_error("end", _("Start date must be before the end date."))
|
||||
if Phase.objects.filter(phase_number__lt=self.instance.phase_number, end__gt=cleaned_data["start"]).exists():
|
||||
self.add_error("start", _("This phase must start after the previous phases."))
|
||||
if Phase.objects.filter(phase_number__gt=self.instance.phase_number, start__lt=cleaned_data["end"]).exists():
|
||||
self.add_error("end", _("This phase must end after the next phases."))
|
||||
return cleaned_data
|
||||
|
@ -12,12 +12,14 @@ class CalendarTable(tables.Table):
|
||||
}
|
||||
row_attrs = {
|
||||
'class': lambda record: 'bg-success' if timezone.now() > record.end else
|
||||
'bg-waring' if timezone.now() > record.start else
|
||||
'bg-danger'
|
||||
'bg-warning' if timezone.now() > record.start else
|
||||
'bg-danger',
|
||||
'data-id': lambda record: str(record.phase_number),
|
||||
}
|
||||
model = Phase
|
||||
fields = ('phase_number', 'description', 'start', 'end',)
|
||||
template_name = 'django_tables2/bootstrap4.html'
|
||||
order_by = ('phase_number',)
|
||||
|
||||
|
||||
# noinspection PyTypeChecker
|
||||
|
@ -3,7 +3,7 @@
|
||||
{% load crispy_forms_filters i18n %}
|
||||
|
||||
{% block content %}
|
||||
<form method="post">
|
||||
<form method="post" action="{% url "participation:update_phase" pk=object.pk %}">
|
||||
<div id="form-content">
|
||||
{% csrf_token %}
|
||||
{{ form|crispy }}
|
||||
|
@ -8,4 +8,22 @@
|
||||
|
||||
{% block content %}
|
||||
{% render_table table %}
|
||||
|
||||
{% trans "Update phase" as modal_title %}
|
||||
{% trans "Update" as modal_button %}
|
||||
{% include "base_modal.html" with modal_id="updatePhase" %}
|
||||
{% endblock %}
|
||||
|
||||
{% if user.registration.is_admin %}
|
||||
{% block extrajavascript %}
|
||||
<script>
|
||||
$("tr").click(function () {
|
||||
let modalBody = $("#updatePhaseModal div.modal-body");
|
||||
if (!modalBody.html().trim())
|
||||
modalBody.load("{% url "participation:calendar" %}" + $(this).data("id") + "/ #form-content");
|
||||
$("#updatePhase-form").attr("action", "{% url "participation:calendar" %}" + $(this).data("id") + "/")
|
||||
$("#updatePhaseModal").modal();
|
||||
})
|
||||
</script>
|
||||
{% endblock %}
|
||||
{% endif %}
|
||||
|
@ -287,3 +287,6 @@ class CalendarView(SingleTableView):
|
||||
class PhaseUpdateView(AdminMixin, UpdateView):
|
||||
model = Phase
|
||||
form_class = PhaseForm
|
||||
|
||||
def get_success_url(self):
|
||||
return reverse_lazy("participation:calendar")
|
||||
|
Reference in New Issue
Block a user