]> git.parisson.com Git - teleforma.git/commitdiff
Fix "send message" link from profile : https://trackers.pilotsystems.net/probarreau...
authortest test <yoanl@pilotsystems.net>
Thu, 24 Jun 2021 09:44:29 +0000 (11:44 +0200)
committerYoan Le Clanche <yoanl@pilotsystems.net>
Thu, 24 Jun 2021 09:44:29 +0000 (11:44 +0200)
teleforma/forms.py
teleforma/templates/postman/base_write.html
teleforma/views/crfpa.py

index 38c8373f58725fcccca2ec43ee4859661ee68de7..01674afd0a2d5ee00ca6a41bf44121fca7bf217e 100644 (file)
@@ -319,5 +319,4 @@ class WriteForm(PostmanWriteForm):
     def clean_recipients(self):
         """compute recipient if 'auto' is set"""
         recipients = self.cleaned_data['recipients']
-        course = self.cleaned_data.get('course')
         return recipients
index 15b067fb4ccac8807af5f8c8e59cdd2cffde5298..af0ac2a74154f027f1381bde615e5129e2c06d04 100644 (file)
 
 
                 {{ form.errors.recipients }}
-                <input type="radio" id="recipient_category-admin" name="recipient_category" value="admin" {% if request.POST.recipient_category == 'admin' %}checked="checked"{% endif %}/><label
+                <input type="radio" id="recipient_category-admin" name="recipient_category" value="admin" {% if recipient_category == 'admin' %}checked="checked"{% endif %}/><label
                     for="recipient_category-admin">A un administrateur</label>
-                <input type="radio" id="recipient_category-prof" name="recipient_category" value="prof" {% if request.POST.recipient_category == 'prof' %}checked="checked"{% endif %}/><label
+                <input type="radio" id="recipient_category-prof" name="recipient_category" value="prof" {% if recipient_category == 'prof' %}checked="checked"{% endif %}/><label
                     for="recipient_category-prof">A un professeur</label>
-                <input type="radio" id="recipient_category-corrector" name="recipient_category" value="corrector" {% if request.POST.recipient_category == 'corrector' %}checked="checked"{% endif %}/><label
+                <input type="radio" id="recipient_category-corrector" name="recipient_category" value="corrector" {% if recipient_category == 'corrector' %}checked="checked"{% endif %}/><label
                     for="recipient_category-corrector">A un correcteur</label>
 
                 {% if not user.student.all %}
-                    <input type="radio" id="recipient_category-other" name="recipient_category" value="other" {% if request.POST.recipient_category == 'other' %}checked="checked"{% endif %}/><label
+                    <input type="radio" id="recipient_category-other" name="recipient_category" value="other" {% if recipient_category == 'other' %}checked="checked"{% endif %}/><label
                         for="recipient_category-other">A un étudiant</label>
                 {% endif %}
 
             });
         }
 
-        function update_desk_messages(event) {
+        function update_desk_messages(event, noReset) {
 
             // reset values
             if(event){
 
             // show or hide field depending on what is selected
             var recipientCategory = $('[name="recipient_category"]:checked').val();
-            $("#id_recipients").val('');
+
+            if(!noReset)
+                $("#id_recipients").val('');
             $('#category-admin').hide();
             $('#category-prof').hide();
             $('#category-corrector').hide();
         $('[name="recipient_category"]').bind('change', update_desk_messages);
         $('[name="course"], [name="corrector_course"]').bind('change', update_desk_messages);
         $('#_professorSelect, #_correctorSelect, #_adminSelect').bind('change', update_desk_messages);
-        update_desk_messages();
+        update_desk_messages(null, true);
 
         document.getElementById("id_subject").focus();
         $('#send_button').click(function () {
index 80ff879ba6634625d2ffa71e7aaf66547c66feac..62899bd0be90f9e160db651f8a949839ba2ac6ca 100644 (file)
@@ -1128,6 +1128,14 @@ class WriteView(PostmanWriteView):
     form_classes = (WriteForm, AnonymousWriteForm)
     success_url = "postman:sent"
 
+    def get_context_data(self, **kwargs):
+        context = super().get_context_data(**kwargs)
+        context['recipient_category'] = self.request.POST.get('recipient_category', None)
+        if self.kwargs.get('recipients') and not context['recipient_category']:
+            context['recipient_category'] = 'other'
+
+        return context
+
 class CRFPAProfileView(ProfileView):
     """Provide Collections web UI methods"""