From fff3f3cc5623ea5fdd42da87ea1e54fb9a3d7aa7 Mon Sep 17 00:00:00 2001 From: ashwinishinde Date: Tue, 23 Jun 2015 13:05:21 +0530 Subject: Subject: Fixed bug from Registration page. Description: 1) Integrity Error. --- forums/forms.py | 26 ++++++++++++++++++++++---- forums/views.py | 5 ++--- static/website/templates/get-question.html | 1 + static/website/templates/questions.html | 13 ++++++++++++- website/views.py | 13 +++++++++---- 5 files changed, 46 insertions(+), 12 deletions(-) diff --git a/forums/forms.py b/forums/forms.py index 3404ac2..90a147d 100644 --- a/forums/forms.py +++ b/forums/forms.py @@ -15,24 +15,33 @@ from website.models import Profile class UserLoginForm(forms.Form): + username = forms.CharField() password = forms.CharField(widget=forms.PasswordInput()) + db = forms.ChoiceField(choices=[('forum', 'forum'), ('scilab', 'scilab'), ('client2', 'client2')]) def clean(self): cleaned_data = self.cleaned_data username = cleaned_data.get('username') - print username password = cleaned_data.get('password') - print password + db = cleaned_data.get('db') + if username is None or password is None: raise forms.ValidationError("Invalid username or password") - user = authenticate(username=username, password=password) - + + + if db == 'forum': + user = authenticate(username=username, password=password) + print "default" , "*******************" + else: + user = authenticate(username=username, password=password, db=db) + print db , "*******************" if not user: raise forms.ValidationError("Invalid username or password") if not user.is_active: raise forms.ValidationError("User is blocked") cleaned_data['user'] = user + return cleaned_data class ProfileForm(forms.ModelForm): @@ -95,3 +104,12 @@ class RegisterForm(forms.Form): required=True ) captcha = ReCaptchaField() + + + def clean_username(self): + try: + User.objects.get(username=self.cleaned_data['username']) + raise forms.ValidationError(_("This username has already existed.")) + except User.DoesNotExist: + pass + return username diff --git a/forums/views.py b/forums/views.py index f1f3096..80410b4 100644 --- a/forums/views.py +++ b/forums/views.py @@ -49,7 +49,6 @@ def account_register(request): } context.update(csrf(request)) return render_to_response('forums/templates/user-register.html', context) - def confirm(request, confirmation_code, username): try: user = User.objects.get(username=username) @@ -60,11 +59,11 @@ def confirm(request, confirmation_code, username): user.save() user.backend='django.contrib.auth.backends.ModelBackend' login(request,user) - print "In if" + messages.success(request, "Your account has been activated!. Please update your profile to complete your registration") return HttpResponseRedirect('/accounts/profile/'+user.username) else: - print "In else" + messages.success(request, "Something went wrong!. Please try again!") return HttpResponseRedirect('/') except Exception, e: diff --git a/static/website/templates/get-question.html b/static/website/templates/get-question.html index 7c93803..67ac33a 100644 --- a/static/website/templates/get-question.html +++ b/static/website/templates/get-question.html @@ -34,6 +34,7 @@ {{ net_count }} + {% ifequal thisUserDownvote 0 %} diff --git a/static/website/templates/questions.html b/static/website/templates/questions.html index 96f596d..81c0d56 100644 --- a/static/website/templates/questions.html +++ b/static/website/templates/questions.html @@ -13,6 +13,17 @@