Mercurial > public > sg101
comparison messages/forms.py @ 1138:0e93eaa323e7
Fix user autocomplete for private messages the right V3 way.
author | Brian Neal <bgneal@gmail.com> |
---|---|
date | Sun, 23 Oct 2016 12:17:03 -0500 |
parents | 6abcecd3d277 |
children |
comparison
equal
deleted
inserted
replaced
1137:6abcecd3d277 | 1138:0e93eaa323e7 |
---|---|
25 """ | 25 """ |
26 This form is used to compose private messages. | 26 This form is used to compose private messages. |
27 """ | 27 """ |
28 receiver = forms.CharField(label='To', | 28 receiver = forms.CharField(label='To', |
29 max_length=30, | 29 max_length=30, |
30 widget=forms.TextInput(attrs={'class': 'sg101-user-autocomplete'})) | 30 widget=forms.TextInput(attrs={'class': 'sg101-autocomplete'})) |
31 subject = forms.CharField(max_length=120) | 31 subject = forms.CharField(max_length=120) |
32 message = forms.CharField(widget=forms.Textarea) | 32 message = forms.CharField(widget=forms.Textarea) |
33 attach_signature = forms.BooleanField(label='Attach Signature?', required=False) | 33 attach_signature = forms.BooleanField(label='Attach Signature?', required=False) |
34 parent_id = forms.IntegerField(required=False, widget=forms.HiddenInput) | 34 parent_id = forms.IntegerField(required=False, widget=forms.HiddenInput) |
35 | 35 |
36 def __init__(self, user, *args, **kwargs): | 36 def __init__(self, user, *args, **kwargs): |
37 forms.Form.__init__(self, *args, **kwargs) | 37 forms.Form.__init__(self, *args, **kwargs) |
38 self.user = user | 38 self.user = user |
39 options = Options.objects.for_user(user) | 39 options = Options.objects.for_user(user) |
40 self.fields['attach_signature'].initial = options.attach_signature | 40 self.fields['attach_signature'].initial = options.attach_signature |
41 url = reverse('core-ajax_users') | |
42 self.fields['receiver'].widget.attrs['data-autocomplete-url'] = url | |
41 | 43 |
42 def clean_receiver(self): | 44 def clean_receiver(self): |
43 receiver = self.cleaned_data['receiver'] | 45 receiver = self.cleaned_data['receiver'] |
44 try: | 46 try: |
45 self.rcvr_user = User.objects.get(username=receiver) | 47 self.rcvr_user = User.objects.get(username=receiver) |