Précédent   Forum du club des développeurs et IT Pro > Autres langages > Python & Zope > Réseau/Web > Django
Django Forum d'entraide sur le framework Web Django
Partagez cette discussion sur d'autres réseaux sociaux : Viadeo Twitter Google Facebook Digg Delicious MySpace Yahoo
Réponse
 
Outils de la discussion
Publicité
'
Vieux 18/12/2012, 02h36   #1
car00x
Invité de passage
 
Inscription : septembre 2006
Messages : 49
Détails du profil
Informations forums :
Inscription : septembre 2006
Messages : 49
Points : 3
Points : 3
Par défaut affichage des erreures du formulaire

Bonjour la communauté,
excusez moi de revenir encore sur ce sujet je vais m'expliquer mieux:

j'ai un problème de verification des champs de mon formulaire quand je valide, je m'explique:
quand je valide le formulaire,la vérification par defaut de django marche c'est à dire que les erreures s'affiche mais ne tient pas compte du système de vérification que j'ai mis en place ne marche, je ne sais pas si j'ai fait des erreures quelques, prière jetter un coup d'oeil sur mon code s'il vous plait.
merci
voici mon code de views:
Code :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
 
from django.http import HttpResponseRedirect, HttpResponse
from django.template import RequestContext
from django.utils.translation import ugettext as _
from django import forms
from django.shortcuts import render_to_response, redirect
from django.utils.hashcompat import md5_constructor, sha_constructor
from django.forms import ModelForm
from django import forms
from models import Tout
import django.utils.simplejson as json
 
def index(request):
    return render_to_response('index.html')
 
class Doctor(ModelForm):
 
    class Meta:
       model = Tout
       widgets = {
            'password': forms.PasswordInput(),'password2': forms.PasswordInput()
        }
 
       default_error_messages = {
        'already exists': _(u'A user with that username already exists'),
        'already exists': _(u'Already use , choise another please'),
        'short_password': _(u'Password has to be at least 8 characters long'),
        'is not the same password': _(u'The two password fields didn\'t match'),
        'required': _(u'you must choice your sex.'),
        'required': _('you must choice your countrie'),
        'required': _(u'your town please.'),
        'required': _('you must choice your speciality'),
    }
 
def clean_username(self):
        username = self.cleaned_data["username"]
 
        try:
            User.objects.get(username=username)
        except User.DoesNotExist:
            return username
        raise forms.ValidationError(self.default_error_messages['Already exists'])
 
def clean_email(self):
        """
        Validates that an active user exists with the given e-mail address.
        """
        email = self.cleaned_data["email"]
        self.users_cache = User.objects.filter(
                                email__iexact=email,
                                is_active=True
                            )
        if len(self.users_cache) == 1:
            raise forms.ValidationError(self.default_error_messages['Already exists'])
        return email
 
def clean_password(self):
        password = self.cleaned_data['password']
        length = len(password)
        if length < 8:
            raise forms.ValidationError(self.default_error_messages['short password'])
        return password
 
def clean_password2(self):
	# Make sure the new password and confirmation match
	password = self.cleaned_data.get('password')
	password2 = self.cleaned_data.get('password2')
 
	if password != password2:
	    raise forms.ValidationError(self.default_error_messages['it is not the same password']) 
	return password2
 
def account(request):
    if request.method == 'POST':  
        form_d = Doctor(request.POST)
 
        if form_d.is_valid():
           username = form_d.cleaned_data['username']
           last_name = form_d.cleaned_data['last_name']
           first_name = form_d.cleaned_data['first_name']
           email = form_d.cleaned_data['email']
           password = form_d.cleaned_data['password']
           password2 = form_d.cleaned_data['password2']
           sex = form_d.cleaned_data['sex']
           country = form_d.cleaned_data['country']
           town = form_d.cleaned_data['town']
           speciality = form_d.cleaned_data['speciality']
           form_d.save()
 
           if request.is_ajax():
                return HttpResponse(content=json.dumps({'success' : '/success'}), mimetype='application/json')
 
           return redirect('success') # Redirect after POST
        elif request.is_ajax():
                errors = json.dumps(forms.errors)
                return HttpResponse(errors, mimetype='application/json')
    else: 
        form_d = Doctor()
    return render_to_response('account.html', {'form_d':form_d})
 
def clean_password(self):
        password = self.cleaned_data['password']
        length = len(password)
        if length < 8:
            raise forms.ValidationError("Password has to be at least 8 characters long.")
        return password
 
def success(request):
    return render_to_response('success.html', {'success' : success}, context_instance=RequestContext(request))
car00x est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 22/12/2012, 11h00   #2
car00x
Invité de passage
 
Inscription : septembre 2006
Messages : 49
Détails du profil
Informations forums :
Inscription : septembre 2006
Messages : 49
Points : 3
Points : 3
Par défaut afficahge des erreures du formulaire

Bonjour,
s'il vous plait personne pour m'aider?
car00x est déconnecté   Envoyer un message privé Réponse avec citation 00
Réponse
Outils de la discussion

Navigation rapide


Fuseau horaire GMT +2. Il est actuellement 14h44.


 
 
 
 
Partenaires

Hébergement Web