Close issue #26: improve SAS ergonomy

This commit is contained in:
Skia 2016-12-06 13:53:16 +01:00
parent b7b9820d70
commit d2c580dd81

View File

@ -10,6 +10,7 @@ from django import forms
from django.core.exceptions import PermissionDenied from django.core.exceptions import PermissionDenied
from ajax_select import make_ajax_form, make_ajax_field from ajax_select import make_ajax_form, make_ajax_field
from ajax_select.fields import AutoCompleteSelectField, AutoCompleteSelectMultipleField
from io import BytesIO from io import BytesIO
from PIL import Image from PIL import Image
@ -48,9 +49,9 @@ class SASForm(forms.Form):
class RelationForm(forms.ModelForm): class RelationForm(forms.ModelForm):
class Meta: class Meta:
model = PeoplePictureRelation model = PeoplePictureRelation
fields = ['picture', 'user'] fields = ['picture']
widgets = {'picture': forms.HiddenInput} widgets = {'picture': forms.HiddenInput}
user = make_ajax_field(PeoplePictureRelation, 'user', 'users', label=_("Add user")) users = AutoCompleteSelectMultipleField('users', show_help_text=False, help_text="", label=_("Add user"), required=False)
class SASMainView(FormView): class SASMainView(FormView):
form_class = SASForm form_class = SASForm
@ -110,8 +111,10 @@ class PictureView(CanViewMixin, DetailView, FormMixin):
self.form = self.get_form() self.form = self.get_form()
if request.user.is_authenticated() and request.user.is_in_group('ae-membres'): if request.user.is_authenticated() and request.user.is_in_group('ae-membres'):
if self.form.is_valid(): if self.form.is_valid():
PeoplePictureRelation(user=self.form.cleaned_data['user'], for uid in self.form.cleaned_data['users']:
picture=self.form.cleaned_data['picture']).save() u = User.objects.filter(id=uid).first()
PeoplePictureRelation(user=u,
picture=self.form.cleaned_data['picture']).save()
return super(PictureView, self).form_valid(self.form) return super(PictureView, self).form_valid(self.form)
else: else:
self.form.add_error(None, _("You do not have the permission to do that")) self.form.add_error(None, _("You do not have the permission to do that"))