Changeset 358 in main


Ignore:
Timestamp:
09/30/11 10:34:22 (8 years ago)
Author:
pcosquer
Message:

sponsor: warns the user if homonyms are found

Location:
trunk/openPLM/plmapp
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/openPLM/plmapp/forms.py

    r357 r358  
    403403    sponsor = forms.ModelChoiceField(queryset=User.objects.all(), 
    404404            required=True, widget=forms.HiddenInput()) 
     405    warned = forms.BooleanField(initial=False, required=False, 
     406                                widget=forms.HiddenInput()) 
    405407 
    406408    class Meta: 
     
    417419            self.fields["groups"].query_set = qset 
    418420        self.fields["groups"].help_text = _("The new user will belong to the selected groups")  
    419         for field in self.fields.itervalues(): 
    420             field.required = True 
     421        for key, field in self.fields.iteritems(): 
     422            if key != "warned": 
     423                field.required = True 
    421424 
    422425    def clean_email(self): 
     
    435438            pass 
    436439        return email 
    437      
    438  
     440   
     441    def clean(self): 
     442        super(SponsorForm, self).clean() 
     443        if not self.cleaned_data.get("warned", False): 
     444            first_name = self.cleaned_data["first_name"] 
     445            last_name = self.cleaned_data["last_name"] 
     446            homonyms = User.objects.filter(first_name=first_name, last_name=last_name) 
     447            if homonyms: 
     448                self.data = self.data.copy() 
     449                self.data["warned"] = "on" 
     450                error = _(u"Warning! There are homonyms: %s!") % \ 
     451                    u", ".join(u.username for u in homonyms) 
     452                raise forms.ValidationError(error) 
     453        return self.cleaned_data 
  • trunk/openPLM/plmapp/views/main.py

    r357 r358  
    10251025        form = forms.SponsorForm(request.POST) 
    10261026        if form.is_valid(): 
    1027             # TODO: checks (first_name, last_name) and warns if it exists 
    10281027            new_user = form.save() 
    10291028            obj.sponsor(new_user) 
Note: See TracChangeset for help on using the changeset viewer.