diff --git a/core/static/js/s3_upload.js b/core/static/js/s3_upload.js index 7054d38cd..250b554a8 100644 --- a/core/static/js/s3_upload.js +++ b/core/static/js/s3_upload.js @@ -17,7 +17,7 @@ const extensionToContentTypeMapping = { // - s3UploadConfigId: ID of DOM element that contains the JSON values of the S3 config (eg. max file size, timeout, etc). window.s3UploadInit = function s3UploadInit({ - dropzoneSelector = "#answer_image_form", + dropzoneSelector = "#image_form", callbackLocationSelector = "", s3FormValuesId = "s3-form-values", s3UploadConfigId = "s3-upload-config", diff --git a/questions/forms.py b/questions/forms.py index c44ef8301..9d5200caa 100644 --- a/questions/forms.py +++ b/questions/forms.py @@ -29,6 +29,7 @@ class Meta: def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) self.fields["tags"].queryset = Tag.objects.all().order_by("name") + self.fields["answer_image_url"].label = "Image pour illustrer la réponse" for field_name in QUESTION_READONLY_FORM_FIELDS: self.fields[field_name].disabled = True for field_name in QUESTION_REQUIRED_FORM_FIELDS: diff --git a/quizs/forms.py b/quizs/forms.py index f3ea04c45..41dfff612 100644 --- a/quizs/forms.py +++ b/quizs/forms.py @@ -22,11 +22,14 @@ class QuizCreateForm(forms.ModelForm): class Meta: model = Quiz fields = QUIZ_CREATE_FORM_FIELDS + QUIZ_READONLY_FORM_FIELDS - widgets = {} + widgets = { + "image_background_url": forms.HiddenInput(), + } def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) self.fields["tags"].queryset = Tag.objects.all().order_by("name") + self.fields["image_background_url"].label = "Image pour illustrer le quiz" for field_name in QUIZ_READONLY_FORM_FIELDS: self.fields[field_name].disabled = True diff --git a/templates/questions/detail_edit.html b/templates/questions/detail_edit.html index acbacaa3c..f1cbdd4d5 100644 --- a/templates/questions/detail_edit.html +++ b/templates/questions/detail_edit.html @@ -1,6 +1,5 @@ {% extends "questions/detail_base.html" %} -{% load static %} -{% load django_bootstrap5 %} +{% load static django_bootstrap5 %} {% block extra_css %} @@ -17,14 +16,18 @@
{% bootstrap_form form alert_error_type="all" %}
+
+
L'ajout de l'image d'explication se fait à la fin du formulaire 👇
+
+
{# {{ form.answer_image_url.as_hidden }} #} - - {% include "includes/_s3_upload_form.html" with dropzone_form_id="answer_image_form" %} + + {% include "includes/_s3_upload_form.html" with dropzone_form_id="image_form" %}
@@ -69,12 +72,12 @@ {{ form.media.js }} -{{ s3_form_values_answer_image|json_script:"s3-form-values-question-image" }} -{{ s3_upload_config_answer_image|json_script:"s3-upload-config-question-image" }} +{{ s3_form_values|json_script:"s3-form-values-question-image" }} +{{ s3_upload_config|json_script:"s3-upload-config-question-image" }} + +{{ s3_form_values|json_script:"s3-form-values-quiz-image" }} +{{ s3_upload_config|json_script:"s3-upload-config-quiz-image" }} + {% endblock %} diff --git a/www/questions/views.py b/www/questions/views.py index 301d1b527..fbee4492b 100644 --- a/www/questions/views.py +++ b/www/questions/views.py @@ -81,9 +81,9 @@ def get_context_data(self, **kwargs): question = self.get_object() # S3 Upload form s3_upload = S3Upload(kind="question_answer_image") - context["s3_form_values_answer_image"] = s3_upload.form_values - context["s3_upload_config_answer_image"] = s3_upload.config - # User can edit? + context["s3_form_values"] = s3_upload.form_values + context["s3_upload_config"] = s3_upload.config + # User authorizations context["user_can_edit_question"] = self.request.user.can_edit_question(question) return context diff --git a/www/quizs/views.py b/www/quizs/views.py index d6499c0bb..c1233fe4b 100644 --- a/www/quizs/views.py +++ b/www/quizs/views.py @@ -13,6 +13,7 @@ from contributions.tables import ContributionTable from core.forms import form_filters_cleaned_dict, form_filters_to_list from core.mixins import ContributorUserRequiredMixin +from core.utils.s3 import S3Upload from history.utilities import get_diff_between_two_history_records from quizs.filters import QuizFilter from quizs.forms import QUIZ_FORM_FIELDS, QuizCreateForm, QuizEditForm, QuizQuestionFormSet @@ -78,6 +79,11 @@ def get_form(self, *args, **kwargs): def get_context_data(self, **kwargs): context = super().get_context_data(**kwargs) quiz = self.get_object() + # S3 Upload form + s3_upload = S3Upload(kind="quiz_image_background") + context["s3_form_values"] = s3_upload.form_values + context["s3_upload_config"] = s3_upload.config + # User authorizations context["user_can_edit_quiz"] = self.request.user.can_edit_quiz(quiz) return context