| author | ymh <ymh.work@gmail.com> |
| Tue, 27 Oct 2015 13:03:02 +0100 | |
| changeset 665 | b8d3784be28d |
| parent 660 | 04255afd160e |
| child 671 | c196386ac4b4 |
| permissions | -rw-r--r-- |
|
11
143ab88d17f8
add ordered manytomany fields and indexing
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
1 |
# -*- coding: utf-8 -*- |
|
143ab88d17f8
add ordered manytomany fields and indexing
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
2 |
from django import forms |
|
143ab88d17f8
add ordered manytomany fields and indexing
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
3 |
from django.db.models.query import QuerySet |
|
665
b8d3784be28d
add message to look into spam folder for activation email
ymh <ymh.work@gmail.com>
parents:
660
diff
changeset
|
4 |
from django.utils.translation import ugettext_lazy as _ |
|
11
143ab88d17f8
add ordered manytomany fields and indexing
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
5 |
|
|
660
04255afd160e
display errors in registration form. Add check for email unicity. slightly change registration message, upgrade django-registration-redux
ymh <ymh.work@gmail.com>
parents:
266
diff
changeset
|
6 |
from registration.forms import RegistrationFormUniqueEmail |
|
11
143ab88d17f8
add ordered manytomany fields and indexing
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
7 |
|
|
143ab88d17f8
add ordered manytomany fields and indexing
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
8 |
class SortedMultipleChoiceField(forms.ModelMultipleChoiceField): |
|
143ab88d17f8
add ordered manytomany fields and indexing
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
9 |
def clean(self, value): |
|
143ab88d17f8
add ordered manytomany fields and indexing
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
10 |
queryset = super(SortedMultipleChoiceField, self).clean(value) |
|
143ab88d17f8
add ordered manytomany fields and indexing
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
11 |
if value is None or not isinstance(queryset, QuerySet): |
|
143ab88d17f8
add ordered manytomany fields and indexing
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
12 |
return queryset |
|
143ab88d17f8
add ordered manytomany fields and indexing
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
13 |
object_list = dict(( |
|
143ab88d17f8
add ordered manytomany fields and indexing
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
14 |
(unicode(key), value) |
|
143ab88d17f8
add ordered manytomany fields and indexing
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
15 |
for key, value in queryset.in_bulk(value).iteritems())) |
|
143ab88d17f8
add ordered manytomany fields and indexing
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
16 |
return [object_list[unicode(pk)] for pk in value] |
|
660
04255afd160e
display errors in registration form. Add check for email unicity. slightly change registration message, upgrade django-registration-redux
ymh <ymh.work@gmail.com>
parents:
266
diff
changeset
|
17 |
|
|
04255afd160e
display errors in registration form. Add check for email unicity. slightly change registration message, upgrade django-registration-redux
ymh <ymh.work@gmail.com>
parents:
266
diff
changeset
|
18 |
class HdaboRegistrationForm(RegistrationFormUniqueEmail): |
|
04255afd160e
display errors in registration form. Add check for email unicity. slightly change registration message, upgrade django-registration-redux
ymh <ymh.work@gmail.com>
parents:
266
diff
changeset
|
19 |
error_css_class = "registration-error" |
|
665
b8d3784be28d
add message to look into spam folder for activation email
ymh <ymh.work@gmail.com>
parents:
660
diff
changeset
|
20 |
|
|
b8d3784be28d
add message to look into spam folder for activation email
ymh <ymh.work@gmail.com>
parents:
660
diff
changeset
|
21 |
def __init__(self, *args, **kwargs): |
|
b8d3784be28d
add message to look into spam folder for activation email
ymh <ymh.work@gmail.com>
parents:
660
diff
changeset
|
22 |
super(HdaboRegistrationForm, self).__init__(*args, **kwargs) |
|
b8d3784be28d
add message to look into spam folder for activation email
ymh <ymh.work@gmail.com>
parents:
660
diff
changeset
|
23 |
self.fields['email'].help_text = _("email help text") |