src/jocondelab/forms.py
author ymh <ymh.work@gmail.com>
Mon, 22 Jul 2013 15:31:17 +0200
changeset 75 702760606a16
parent 72 db80ba79fb52
child 81 e78e5a2017b6
permissions -rw-r--r--
correct pb when creating users
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
0
4095911a7830 Jocondelab first commit before design
ymh <ymh.work@gmail.com>
parents:
diff changeset
     1
# -*- coding: utf-8 -*-
4095911a7830 Jocondelab first commit before design
ymh <ymh.work@gmail.com>
parents:
diff changeset
     2
'''
4095911a7830 Jocondelab first commit before design
ymh <ymh.work@gmail.com>
parents:
diff changeset
     3
Created on Jun 13, 2013
4095911a7830 Jocondelab first commit before design
ymh <ymh.work@gmail.com>
parents:
diff changeset
     4
4095911a7830 Jocondelab first commit before design
ymh <ymh.work@gmail.com>
parents:
diff changeset
     5
@author: ymh
4095911a7830 Jocondelab first commit before design
ymh <ymh.work@gmail.com>
parents:
diff changeset
     6
'''
71
3fde7d26ad08 Add link_semantic_level to filter (bug #17542)
ymh <ymh.work@gmail.com>
parents: 67
diff changeset
     7
from core.models import (Thesaurus, Term, TERM_URL_STATUS_CHOICES_TRANS, 
3fde7d26ad08 Add link_semantic_level to filter (bug #17542)
ymh <ymh.work@gmail.com>
parents: 67
diff changeset
     8
    TERM_WK_LINK_SEMANTIC_LEVEL_CHOICES_TRANS)
75
702760606a16 correct pb when creating users
ymh <ymh.work@gmail.com>
parents: 72
diff changeset
     9
from django.contrib.auth import get_user_model
702760606a16 correct pb when creating users
ymh <ymh.work@gmail.com>
parents: 72
diff changeset
    10
from django.contrib.auth.forms import (UserChangeForm as AuthUserChangeForm, 
702760606a16 correct pb when creating users
ymh <ymh.work@gmail.com>
parents: 72
diff changeset
    11
    UserCreationForm as AuthUserCreationForm)
702760606a16 correct pb when creating users
ymh <ymh.work@gmail.com>
parents: 72
diff changeset
    12
from django.forms import Form, fields, ModelChoiceField, ValidationError
702760606a16 correct pb when creating users
ymh <ymh.work@gmail.com>
parents: 72
diff changeset
    13
from django.forms.fields import ChoiceField
62
33fd91a414cc selection dialog for thesaurus tree
ymh <ymh.work@gmail.com>
parents: 51
diff changeset
    14
from django.forms.util import flatatt
75
702760606a16 correct pb when creating users
ymh <ymh.work@gmail.com>
parents: 72
diff changeset
    15
from django.forms.widgets import (Widget, Select, 
702760606a16 correct pb when creating users
ymh <ymh.work@gmail.com>
parents: 72
diff changeset
    16
    NullBooleanSelect as DjangoNullBooleanSelect)
62
33fd91a414cc selection dialog for thesaurus tree
ymh <ymh.work@gmail.com>
parents: 51
diff changeset
    17
from django.utils import formats
33fd91a414cc selection dialog for thesaurus tree
ymh <ymh.work@gmail.com>
parents: 51
diff changeset
    18
from django.utils.encoding import force_text
33fd91a414cc selection dialog for thesaurus tree
ymh <ymh.work@gmail.com>
parents: 51
diff changeset
    19
from django.utils.html import format_html, escape
33fd91a414cc selection dialog for thesaurus tree
ymh <ymh.work@gmail.com>
parents: 51
diff changeset
    20
from django.utils.safestring import mark_safe
72
db80ba79fb52 Add filter on "wikipedia edition" field.
ymh <ymh.work@gmail.com>
parents: 71
diff changeset
    21
from django.utils.translation import ugettext as _, ugettext_lazy
67
5d9223bb3aab Add other wikipedia.
ymh <ymh.work@gmail.com>
parents: 62
diff changeset
    22
from jocondelab import settings
62
33fd91a414cc selection dialog for thesaurus tree
ymh <ymh.work@gmail.com>
parents: 51
diff changeset
    23
import json
33fd91a414cc selection dialog for thesaurus tree
ymh <ymh.work@gmail.com>
parents: 51
diff changeset
    24
75
702760606a16 correct pb when creating users
ymh <ymh.work@gmail.com>
parents: 72
diff changeset
    25
User = get_user_model()
702760606a16 correct pb when creating users
ymh <ymh.work@gmail.com>
parents: 72
diff changeset
    26
62
33fd91a414cc selection dialog for thesaurus tree
ymh <ymh.work@gmail.com>
parents: 51
diff changeset
    27
class ThesaurusTreeWidget(Widget):
33fd91a414cc selection dialog for thesaurus tree
ymh <ymh.work@gmail.com>
parents: 51
diff changeset
    28
    
33fd91a414cc selection dialog for thesaurus tree
ymh <ymh.work@gmail.com>
parents: 51
diff changeset
    29
    def _format_value(self, value):
33fd91a414cc selection dialog for thesaurus tree
ymh <ymh.work@gmail.com>
parents: 51
diff changeset
    30
        if self.is_localized:
33fd91a414cc selection dialog for thesaurus tree
ymh <ymh.work@gmail.com>
parents: 51
diff changeset
    31
            return formats.localize_input(value)
33fd91a414cc selection dialog for thesaurus tree
ymh <ymh.work@gmail.com>
parents: 51
diff changeset
    32
        return value
33fd91a414cc selection dialog for thesaurus tree
ymh <ymh.work@gmail.com>
parents: 51
diff changeset
    33
33fd91a414cc selection dialog for thesaurus tree
ymh <ymh.work@gmail.com>
parents: 51
diff changeset
    34
    def render(self, name, value, attrs=None):
33fd91a414cc selection dialog for thesaurus tree
ymh <ymh.work@gmail.com>
parents: 51
diff changeset
    35
        term = None
33fd91a414cc selection dialog for thesaurus tree
ymh <ymh.work@gmail.com>
parents: 51
diff changeset
    36
        if isinstance(value, Term):
33fd91a414cc selection dialog for thesaurus tree
ymh <ymh.work@gmail.com>
parents: 51
diff changeset
    37
            term = value
33fd91a414cc selection dialog for thesaurus tree
ymh <ymh.work@gmail.com>
parents: 51
diff changeset
    38
        elif value and isinstance(value, (int, basestring)):
33fd91a414cc selection dialog for thesaurus tree
ymh <ymh.work@gmail.com>
parents: 51
diff changeset
    39
            terms = list(Term.objects.filter(id=int(value)))  # @UndefinedVariable
33fd91a414cc selection dialog for thesaurus tree
ymh <ymh.work@gmail.com>
parents: 51
diff changeset
    40
            if terms:
33fd91a414cc selection dialog for thesaurus tree
ymh <ymh.work@gmail.com>
parents: 51
diff changeset
    41
                term = terms[0]
33fd91a414cc selection dialog for thesaurus tree
ymh <ymh.work@gmail.com>
parents: 51
diff changeset
    42
33fd91a414cc selection dialog for thesaurus tree
ymh <ymh.work@gmail.com>
parents: 51
diff changeset
    43
        final_attrs = self.build_attrs(attrs, type="hidden", name=name)
33fd91a414cc selection dialog for thesaurus tree
ymh <ymh.work@gmail.com>
parents: 51
diff changeset
    44
        if term is not None:
33fd91a414cc selection dialog for thesaurus tree
ymh <ymh.work@gmail.com>
parents: 51
diff changeset
    45
            # Only add the 'value' attribute if a value is non-empty.
33fd91a414cc selection dialog for thesaurus tree
ymh <ymh.work@gmail.com>
parents: 51
diff changeset
    46
            final_attrs['value'] = force_text(self._format_value(term.id))
33fd91a414cc selection dialog for thesaurus tree
ymh <ymh.work@gmail.com>
parents: 51
diff changeset
    47
            final_attrs['data-term_tree_node'] = mark_safe(json.dumps({'id': term.id, 'label': escape(term.label)}).replace("\"", "'"));
33fd91a414cc selection dialog for thesaurus tree
ymh <ymh.work@gmail.com>
parents: 51
diff changeset
    48
        input_res = format_html('<input{0} />', flatatt(final_attrs))
33fd91a414cc selection dialog for thesaurus tree
ymh <ymh.work@gmail.com>
parents: 51
diff changeset
    49
                
33fd91a414cc selection dialog for thesaurus tree
ymh <ymh.work@gmail.com>
parents: 51
diff changeset
    50
        if term is not None:
33fd91a414cc selection dialog for thesaurus tree
ymh <ymh.work@gmail.com>
parents: 51
diff changeset
    51
            dialog_text = term.label
33fd91a414cc selection dialog for thesaurus tree
ymh <ymh.work@gmail.com>
parents: 51
diff changeset
    52
        else:
33fd91a414cc selection dialog for thesaurus tree
ymh <ymh.work@gmail.com>
parents: 51
diff changeset
    53
            dialog_text = _("Open Dialog")
33fd91a414cc selection dialog for thesaurus tree
ymh <ymh.work@gmail.com>
parents: 51
diff changeset
    54
            
33fd91a414cc selection dialog for thesaurus tree
ymh <ymh.work@gmail.com>
parents: 51
diff changeset
    55
        dialog_res = "<div id=\"dialog-link-container\" class=\"ui-state-default ui-corner-all\"><a href=\"#\" id=\"dialog-link\" title=\"%s\">%s</a><span class=\"ui-icon ui-icon-closethick\" id=\"dialog-deselect\"></span></div>" % (_("Open Dialog"),dialog_text)
33fd91a414cc selection dialog for thesaurus tree
ymh <ymh.work@gmail.com>
parents: 51
diff changeset
    56
        
33fd91a414cc selection dialog for thesaurus tree
ymh <ymh.work@gmail.com>
parents: 51
diff changeset
    57
        return input_res + dialog_res
0
4095911a7830 Jocondelab first commit before design
ymh <ymh.work@gmail.com>
parents:
diff changeset
    58
72
db80ba79fb52 Add filter on "wikipedia edition" field.
ymh <ymh.work@gmail.com>
parents: 71
diff changeset
    59
class NullBooleanSelect(DjangoNullBooleanSelect):
db80ba79fb52 Add filter on "wikipedia edition" field.
ymh <ymh.work@gmail.com>
parents: 71
diff changeset
    60
    """
db80ba79fb52 Add filter on "wikipedia edition" field.
ymh <ymh.work@gmail.com>
parents: 71
diff changeset
    61
    A Select Widget intended to be used with NullBooleanField.
db80ba79fb52 Add filter on "wikipedia edition" field.
ymh <ymh.work@gmail.com>
parents: 71
diff changeset
    62
    """
db80ba79fb52 Add filter on "wikipedia edition" field.
ymh <ymh.work@gmail.com>
parents: 71
diff changeset
    63
    def __init__(self, attrs=None):
db80ba79fb52 Add filter on "wikipedia edition" field.
ymh <ymh.work@gmail.com>
parents: 71
diff changeset
    64
        choices = (('1', ('---')),
db80ba79fb52 Add filter on "wikipedia edition" field.
ymh <ymh.work@gmail.com>
parents: 71
diff changeset
    65
                   ('2', ugettext_lazy('yes')),
db80ba79fb52 Add filter on "wikipedia edition" field.
ymh <ymh.work@gmail.com>
parents: 71
diff changeset
    66
                   ('3', ugettext_lazy('no')))
db80ba79fb52 Add filter on "wikipedia edition" field.
ymh <ymh.work@gmail.com>
parents: 71
diff changeset
    67
        Select.__init__(self, attrs, choices)
db80ba79fb52 Add filter on "wikipedia edition" field.
ymh <ymh.work@gmail.com>
parents: 71
diff changeset
    68
0
4095911a7830 Jocondelab first commit before design
ymh <ymh.work@gmail.com>
parents:
diff changeset
    69
4095911a7830 Jocondelab first commit before design
ymh <ymh.work@gmail.com>
parents:
diff changeset
    70
class ValidateTermForm(Form):
4095911a7830 Jocondelab first commit before design
ymh <ymh.work@gmail.com>
parents:
diff changeset
    71
    term_id = fields.IntegerField(required=True)
4095911a7830 Jocondelab first commit before design
ymh <ymh.work@gmail.com>
parents:
diff changeset
    72
    validation_val = fields.BooleanField(required=False)
26
758b9289aa9a add check box to indicate that a wk page should be created
ymh <ymh.work@gmail.com>
parents: 15
diff changeset
    73
758b9289aa9a add check box to indicate that a wk page should be created
ymh <ymh.work@gmail.com>
parents: 15
diff changeset
    74
class WikipediaEditionForm(Form):
758b9289aa9a add check box to indicate that a wk page should be created
ymh <ymh.work@gmail.com>
parents: 15
diff changeset
    75
    term_id = fields.IntegerField(required=True)
758b9289aa9a add check box to indicate that a wk page should be created
ymh <ymh.work@gmail.com>
parents: 15
diff changeset
    76
    wikipedia_edition = fields.BooleanField(required=False)
0
4095911a7830 Jocondelab first commit before design
ymh <ymh.work@gmail.com>
parents:
diff changeset
    77
    
4095911a7830 Jocondelab first commit before design
ymh <ymh.work@gmail.com>
parents:
diff changeset
    78
class ModifyWpLinkForm(Form):
4095911a7830 Jocondelab first commit before design
ymh <ymh.work@gmail.com>
parents:
diff changeset
    79
    term_id = fields.IntegerField(required=True)
4095911a7830 Jocondelab first commit before design
ymh <ymh.work@gmail.com>
parents:
diff changeset
    80
    label = fields.CharField(required=True, min_length=1)
67
5d9223bb3aab Add other wikipedia.
ymh <ymh.work@gmail.com>
parents: 62
diff changeset
    81
    wp_lang = fields.ChoiceField(label=_('Wikipedia version'), required=False, choices=tuple([(k,k) for k in settings.WIKIPEDIA_URLS]))
0
4095911a7830 Jocondelab first commit before design
ymh <ymh.work@gmail.com>
parents:
diff changeset
    82
35
859862939996 add qualifier on the wikipedia link
ymh <ymh.work@gmail.com>
parents: 26
diff changeset
    83
class LinkSemanticLevelForm(Form):
859862939996 add qualifier on the wikipedia link
ymh <ymh.work@gmail.com>
parents: 26
diff changeset
    84
    term_id = fields.IntegerField(required=True)
859862939996 add qualifier on the wikipedia link
ymh <ymh.work@gmail.com>
parents: 26
diff changeset
    85
    link_semantic_level = fields.IntegerField(required=True)
859862939996 add qualifier on the wikipedia link
ymh <ymh.work@gmail.com>
parents: 26
diff changeset
    86
0
4095911a7830 Jocondelab first commit before design
ymh <ymh.work@gmail.com>
parents:
diff changeset
    87
class RemoveWpLinkForm(Form):
4095911a7830 Jocondelab first commit before design
ymh <ymh.work@gmail.com>
parents:
diff changeset
    88
    term_id = fields.IntegerField(required=True)
4095911a7830 Jocondelab first commit before design
ymh <ymh.work@gmail.com>
parents:
diff changeset
    89
         
4095911a7830 Jocondelab first commit before design
ymh <ymh.work@gmail.com>
parents:
diff changeset
    90
class TermFilterForm(Form):
43
b9baab399b4d add nb_notice columns
ymh <ymh.work@gmail.com>
parents: 35
diff changeset
    91
    thesaurus = ModelChoiceField(label=_("thesaurus"), required=False, queryset=Thesaurus.objects.all().order_by('label'))
62
33fd91a414cc selection dialog for thesaurus tree
ymh <ymh.work@gmail.com>
parents: 51
diff changeset
    92
    thesaurus_tree = ModelChoiceField(label=_("thesaurus tree"), queryset=Term.objects.all(), required=False, widget=ThesaurusTreeWidget)  # @UndefinedVariable
15
8440c36660e5 add translation,
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    93
    label = fields.CharField(label=_("label"), required=False)
8440c36660e5 add translation,
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    94
    link_status = fields.TypedChoiceField(label=_("link_status"), required=False, empty_value=-1, coerce=int, choices=tuple([(-1,'---------')]+[(v, l) for v,l in TERM_URL_STATUS_CHOICES_TRANS]))
71
3fde7d26ad08 Add link_semantic_level to filter (bug #17542)
ymh <ymh.work@gmail.com>
parents: 67
diff changeset
    95
    link_semantic_level = fields.TypedChoiceField(label=_("link_semantic_level"), required=False, empty_value=0, coerce=int, choices=TERM_WK_LINK_SEMANTIC_LEVEL_CHOICES_TRANS)
72
db80ba79fb52 Add filter on "wikipedia edition" field.
ymh <ymh.work@gmail.com>
parents: 71
diff changeset
    96
    wikipedia_edition = fields.NullBooleanField(label=_("wikipedia_edition"), required=False, widget=NullBooleanSelect)
db80ba79fb52 Add filter on "wikipedia edition" field.
ymh <ymh.work@gmail.com>
parents: 71
diff changeset
    97
    validated = fields.NullBooleanField(label=_("validated"), required=False, widget=NullBooleanSelect)
62
33fd91a414cc selection dialog for thesaurus tree
ymh <ymh.work@gmail.com>
parents: 51
diff changeset
    98
    order_by = fields.ChoiceField(label=_("order_by"), required=False, choices=(('normalized_label',_('label')),('nb_notice',_('nb notice')),('level',_('level'))))
15
8440c36660e5 add translation,
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    99
    order_dir = fields.ChoiceField(label=_("order_dir"), required=False, choices=(('asc',_('asc')), ('desc',_('desc'))))
0
4095911a7830 Jocondelab first commit before design
ymh <ymh.work@gmail.com>
parents:
diff changeset
   100
    
4095911a7830 Jocondelab first commit before design
ymh <ymh.work@gmail.com>
parents:
diff changeset
   101
    def get_filter_qs(self, base_qs=None):
4095911a7830 Jocondelab first commit before design
ymh <ymh.work@gmail.com>
parents:
diff changeset
   102
        qs = base_qs
62
33fd91a414cc selection dialog for thesaurus tree
ymh <ymh.work@gmail.com>
parents: 51
diff changeset
   103
        
0
4095911a7830 Jocondelab first commit before design
ymh <ymh.work@gmail.com>
parents:
diff changeset
   104
        if qs is None:
62
33fd91a414cc selection dialog for thesaurus tree
ymh <ymh.work@gmail.com>
parents: 51
diff changeset
   105
            qs = Term.objects.all()  # @UndefinedVariable
33fd91a414cc selection dialog for thesaurus tree
ymh <ymh.work@gmail.com>
parents: 51
diff changeset
   106
                
0
4095911a7830 Jocondelab first commit before design
ymh <ymh.work@gmail.com>
parents:
diff changeset
   107
        thes = self.cleaned_data.get('thesaurus',None)
4095911a7830 Jocondelab first commit before design
ymh <ymh.work@gmail.com>
parents:
diff changeset
   108
        if thes:
4095911a7830 Jocondelab first commit before design
ymh <ymh.work@gmail.com>
parents:
diff changeset
   109
            qs = qs.filter(thesaurus=thes)
62
33fd91a414cc selection dialog for thesaurus tree
ymh <ymh.work@gmail.com>
parents: 51
diff changeset
   110
33fd91a414cc selection dialog for thesaurus tree
ymh <ymh.work@gmail.com>
parents: 51
diff changeset
   111
        thes_tree = self.cleaned_data.get('thesaurus_tree',None)
33fd91a414cc selection dialog for thesaurus tree
ymh <ymh.work@gmail.com>
parents: 51
diff changeset
   112
        if thes_tree:
33fd91a414cc selection dialog for thesaurus tree
ymh <ymh.work@gmail.com>
parents: 51
diff changeset
   113
            qs = qs & thes_tree.get_descendants()  # @UndefinedVariable
33fd91a414cc selection dialog for thesaurus tree
ymh <ymh.work@gmail.com>
parents: 51
diff changeset
   114
0
4095911a7830 Jocondelab first commit before design
ymh <ymh.work@gmail.com>
parents:
diff changeset
   115
        lk_status = self.cleaned_data.get('link_status',-1)
4095911a7830 Jocondelab first commit before design
ymh <ymh.work@gmail.com>
parents:
diff changeset
   116
        if lk_status>=0:
4095911a7830 Jocondelab first commit before design
ymh <ymh.work@gmail.com>
parents:
diff changeset
   117
            qs = qs.filter(url_status=lk_status)
4095911a7830 Jocondelab first commit before design
ymh <ymh.work@gmail.com>
parents:
diff changeset
   118
            
71
3fde7d26ad08 Add link_semantic_level to filter (bug #17542)
ymh <ymh.work@gmail.com>
parents: 67
diff changeset
   119
        lk_semantic_level = self.cleaned_data.get('link_semantic_level', 0)
3fde7d26ad08 Add link_semantic_level to filter (bug #17542)
ymh <ymh.work@gmail.com>
parents: 67
diff changeset
   120
        if lk_semantic_level:
72
db80ba79fb52 Add filter on "wikipedia edition" field.
ymh <ymh.work@gmail.com>
parents: 71
diff changeset
   121
            qs = qs.filter(link_semantic_level=lk_semantic_level)            
71
3fde7d26ad08 Add link_semantic_level to filter (bug #17542)
ymh <ymh.work@gmail.com>
parents: 67
diff changeset
   122
            
0
4095911a7830 Jocondelab first commit before design
ymh <ymh.work@gmail.com>
parents:
diff changeset
   123
        validated = self.cleaned_data.get('validated', None)
4095911a7830 Jocondelab first commit before design
ymh <ymh.work@gmail.com>
parents:
diff changeset
   124
        if validated is not None:
4095911a7830 Jocondelab first commit before design
ymh <ymh.work@gmail.com>
parents:
diff changeset
   125
            qs = qs.filter(validated=validated)
4095911a7830 Jocondelab first commit before design
ymh <ymh.work@gmail.com>
parents:
diff changeset
   126
            
72
db80ba79fb52 Add filter on "wikipedia edition" field.
ymh <ymh.work@gmail.com>
parents: 71
diff changeset
   127
        wikipedia_edition = self.cleaned_data.get('wikipedia_edition', None)
db80ba79fb52 Add filter on "wikipedia edition" field.
ymh <ymh.work@gmail.com>
parents: 71
diff changeset
   128
        if wikipedia_edition is not None:
db80ba79fb52 Add filter on "wikipedia edition" field.
ymh <ymh.work@gmail.com>
parents: 71
diff changeset
   129
            qs = qs.filter(wikipedia_edition=wikipedia_edition)
db80ba79fb52 Add filter on "wikipedia edition" field.
ymh <ymh.work@gmail.com>
parents: 71
diff changeset
   130
            
0
4095911a7830 Jocondelab first commit before design
ymh <ymh.work@gmail.com>
parents:
diff changeset
   131
        label_regexp = self.cleaned_data.get('label', None)
4095911a7830 Jocondelab first commit before design
ymh <ymh.work@gmail.com>
parents:
diff changeset
   132
        if label_regexp:
4095911a7830 Jocondelab first commit before design
ymh <ymh.work@gmail.com>
parents:
diff changeset
   133
            qs = qs.filter(label__iregex=label_regexp)
4095911a7830 Jocondelab first commit before design
ymh <ymh.work@gmail.com>
parents:
diff changeset
   134
        
4095911a7830 Jocondelab first commit before design
ymh <ymh.work@gmail.com>
parents:
diff changeset
   135
        order_by = self.cleaned_data.get('order_by', 'normalized_label') or 'normalized_label'
4095911a7830 Jocondelab first commit before design
ymh <ymh.work@gmail.com>
parents:
diff changeset
   136
        order_dir = self.cleaned_data.get('order_dir', 'asc') or 'asc'
4095911a7830 Jocondelab first commit before design
ymh <ymh.work@gmail.com>
parents:
diff changeset
   137
        if order_dir == 'desc':
4095911a7830 Jocondelab first commit before design
ymh <ymh.work@gmail.com>
parents:
diff changeset
   138
            order_by = "-"+order_by
51
8890db197b37 add prev and next buttons
ymh <ymh.work@gmail.com>
parents: 43
diff changeset
   139
        if order_by == "normalized_label" or order_by == "label":
8890db197b37 add prev and next buttons
ymh <ymh.work@gmail.com>
parents: 43
diff changeset
   140
            order_by = [order_by, 'nb_notice', 'id']
8890db197b37 add prev and next buttons
ymh <ymh.work@gmail.com>
parents: 43
diff changeset
   141
        else:
8890db197b37 add prev and next buttons
ymh <ymh.work@gmail.com>
parents: 43
diff changeset
   142
            order_by = [order_by, 'normalized_label', 'id']
8890db197b37 add prev and next buttons
ymh <ymh.work@gmail.com>
parents: 43
diff changeset
   143
        qs = qs.order_by(*order_by)
0
4095911a7830 Jocondelab first commit before design
ymh <ymh.work@gmail.com>
parents:
diff changeset
   144
        
62
33fd91a414cc selection dialog for thesaurus tree
ymh <ymh.work@gmail.com>
parents: 51
diff changeset
   145
        return qs
33fd91a414cc selection dialog for thesaurus tree
ymh <ymh.work@gmail.com>
parents: 51
diff changeset
   146
    
75
702760606a16 correct pb when creating users
ymh <ymh.work@gmail.com>
parents: 72
diff changeset
   147
class UserCreationform(AuthUserCreationForm):
702760606a16 correct pb when creating users
ymh <ymh.work@gmail.com>
parents: 72
diff changeset
   148
    class Meta:
702760606a16 correct pb when creating users
ymh <ymh.work@gmail.com>
parents: 72
diff changeset
   149
        model = User
702760606a16 correct pb when creating users
ymh <ymh.work@gmail.com>
parents: 72
diff changeset
   150
        
702760606a16 correct pb when creating users
ymh <ymh.work@gmail.com>
parents: 72
diff changeset
   151
    def clean_username(self):
702760606a16 correct pb when creating users
ymh <ymh.work@gmail.com>
parents: 72
diff changeset
   152
        # Since User.username is unique, this check is redundant,
702760606a16 correct pb when creating users
ymh <ymh.work@gmail.com>
parents: 72
diff changeset
   153
        # but it sets a nicer error message than the ORM. See #13147.
702760606a16 correct pb when creating users
ymh <ymh.work@gmail.com>
parents: 72
diff changeset
   154
        username = self.cleaned_data["username"]
702760606a16 correct pb when creating users
ymh <ymh.work@gmail.com>
parents: 72
diff changeset
   155
        try:
702760606a16 correct pb when creating users
ymh <ymh.work@gmail.com>
parents: 72
diff changeset
   156
            User.objects.get(username=username)
702760606a16 correct pb when creating users
ymh <ymh.work@gmail.com>
parents: 72
diff changeset
   157
        except User.DoesNotExist:
702760606a16 correct pb when creating users
ymh <ymh.work@gmail.com>
parents: 72
diff changeset
   158
            return username
702760606a16 correct pb when creating users
ymh <ymh.work@gmail.com>
parents: 72
diff changeset
   159
        raise ValidationError(self.error_messages['duplicate_username'])    
702760606a16 correct pb when creating users
ymh <ymh.work@gmail.com>
parents: 72
diff changeset
   160
    
702760606a16 correct pb when creating users
ymh <ymh.work@gmail.com>
parents: 72
diff changeset
   161
702760606a16 correct pb when creating users
ymh <ymh.work@gmail.com>
parents: 72
diff changeset
   162
class UserChangeForm(AuthUserChangeForm):
702760606a16 correct pb when creating users
ymh <ymh.work@gmail.com>
parents: 72
diff changeset
   163
    language = ChoiceField(label=_("language"), choices=[(k,_(v)) for k,v in settings.LANGUAGES], initial=settings.LANGUAGE_CODE[:2])
702760606a16 correct pb when creating users
ymh <ymh.work@gmail.com>
parents: 72
diff changeset
   164
    class Meta:
702760606a16 correct pb when creating users
ymh <ymh.work@gmail.com>
parents: 72
diff changeset
   165
        model = User