From f69faec312bb9322132eef39ca35b3374cdad0f4 Mon Sep 17 00:00:00 2001 From: Yoan Le Clanche Date: Thu, 25 Apr 2019 15:30:18 +0200 Subject: [PATCH] remove automatic teacher selection with postman : https://trackers.pilotsystems.net/probarreau/0469 --- teleforma/fields.py | 38 --------------------- teleforma/forms.py | 21 +----------- teleforma/templates/postman/base_write.html | 6 +--- 3 files changed, 2 insertions(+), 63 deletions(-) diff --git a/teleforma/fields.py b/teleforma/fields.py index 9a9d9c5f..76b15eb7 100644 --- a/teleforma/fields.py +++ b/teleforma/fields.py @@ -2,7 +2,6 @@ import django.db.models as models from django.forms import ModelForm, TextInput, Textarea from south.modelsinspector import add_introspection_rules -from postman.fields import BasicCommaSeparatedUserField as PostmanBasicCommaSeparatedUserField from django.core.exceptions import ValidationError try: @@ -23,40 +22,3 @@ add_introspection_rules([], ["^teleforma\.fields\.ShortTextField"]) -class BasicCommaSeparatedUserField(PostmanBasicCommaSeparatedUserField): - def clean(self, value): - """Check names are valid and filter them.""" - names = super(PostmanBasicCommaSeparatedUserField, self).clean(value) - if not names: - return [] - user_model = get_user_model() - users = list(user_model.objects.filter(is_active=True, **{'{0}__in'.format(user_model.USERNAME_FIELD): names})) - unknown_names = set(names) ^ set([u.get_username() for u in users]) - errors = [] - - if unknown_names == set(['auto']): - return 'auto' - - if unknown_names: - errors.append(self.error_messages['unknown'].format(users=', '.join(unknown_names))) - - if self.user_filter: - filtered_names = [] - for u in users[:]: - try: - reason = self.user_filter(u) - if reason is not None: - users.remove(u) - filtered_names.append( - self.error_messages[ - 'filtered_user_with_reason' if reason else 'filtered_user' - ].format(username=u.get_username(), reason=reason) - ) - except ValidationError as e: - users.remove(u) - errors.extend(e.messages) - if filtered_names: - errors.append(self.error_messages['filtered'].format(users=', '.join(filtered_names))) - if errors: - raise ValidationError(errors) - return users \ No newline at end of file diff --git a/teleforma/forms.py b/teleforma/forms.py index 2e25878a..998ab42e 100644 --- a/teleforma/forms.py +++ b/teleforma/forms.py @@ -1,7 +1,6 @@ from django.forms import ModelForm, ModelChoiceField from postman.forms import WriteForm as PostmanWriteForm - -from teleforma.fields import BasicCommaSeparatedUserField +from postman.fields import BasicCommaSeparatedUserField from teleforma.models import * from registration.forms import RegistrationForm from django.utils.translation import ugettext_lazy as _ @@ -111,22 +110,4 @@ class WriteForm(PostmanWriteForm): """compute recipient if 'auto' is set""" recipients = self.cleaned_data['recipients'] course = self.cleaned_data.get('course') - if recipients == 'auto': - professors = Professor.objects.filter(courses__in=[course]).order_by('user__last_name').all() - if course.last_professor_sent: - try: - index = list(professors).index(course.last_professor_sent) - except ValueError: - index = 0 - - if index < len(professors)-1: - professor = professors[index+1] - else: - professor = professors[0] - else: - professor = professors[0] - course.last_professor_sent = professor - course.save() - recipients = [professor.user,] - return recipients \ No newline at end of file diff --git a/teleforma/templates/postman/base_write.html b/teleforma/templates/postman/base_write.html index d3eb8d32..f0be0752 100644 --- a/teleforma/templates/postman/base_write.html +++ b/teleforma/templates/postman/base_write.html @@ -56,7 +56,7 @@