diff options
author | ashwinishinde | 2015-06-23 13:05:21 +0530 |
---|---|---|
committer | ashwinishinde | 2015-06-23 13:05:21 +0530 |
commit | fff3f3cc5623ea5fdd42da87ea1e54fb9a3d7aa7 (patch) | |
tree | fc5d7e575b00adca1b0cb11c1f72278e371ce0a7 | |
parent | bf20363adec8afed8d8e10ad7e0b641c51568cff (diff) | |
download | FOSSEE-Forum-fff3f3cc5623ea5fdd42da87ea1e54fb9a3d7aa7.tar.gz FOSSEE-Forum-fff3f3cc5623ea5fdd42da87ea1e54fb9a3d7aa7.tar.bz2 FOSSEE-Forum-fff3f3cc5623ea5fdd42da87ea1e54fb9a3d7aa7.zip |
Subject: Fixed bug from Registration page.
Description:
1) Integrity Error.
-rw-r--r-- | forums/forms.py | 26 | ||||
-rw-r--r-- | forums/views.py | 5 | ||||
-rw-r--r-- | static/website/templates/get-question.html | 1 | ||||
-rw-r--r-- | static/website/templates/questions.html | 13 | ||||
-rw-r--r-- | 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 @@ <span class="vote-count-post" id="show_vote_count"> {{ net_count }} </span> + {% ifequal thisUserDownvote 0 %} <img src="{% static 'website/images/down1-off.png' %}" class="vote-down" title="This question does not show any research effort; it is not useful and unclear"/> 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 @@ <th> Question <span class="glyphicon glyphicon-link"></span></th> <th> Date</th> <th> Views</th> + <div class="viewcount" id ="viewcount"> + {% if num_votes == 0 %} + vote + {% elif num_votes == 1 %} + vote + {% elif num_votes == -1 %} + vote + {% else %} + votes + {% endif %} + </div> <th> Answers</th> <th> User</th> {% for question in questions %} @@ -49,7 +60,7 @@ <td> {{ question.answer_set.count }} </td> - + <td> <span class="title" data-toggle="tooltip" data-placement="top" title="{{ question.user }}"> {{ question.user|truncatechars:10 }} diff --git a/website/views.py b/website/views.py index c9a2a5f..5974433 100644 --- a/website/views.py +++ b/website/views.py @@ -36,7 +36,9 @@ def questions(request): questions = Question.objects.all().order_by('date_created').reverse() paginator = Paginator(questions, 20) page = request.GET.get('page') - + for q in questions: + print q.title + print q.num_votes try: questions = paginator.page(page) except PageNotAnInteger: @@ -46,6 +48,7 @@ def questions(request): context = { 'questions': questions } + return render(request, 'website/templates/questions.html', context) def get_question(request, question_id=None, pretty_url=None): @@ -59,19 +62,21 @@ def get_question(request, question_id=None, pretty_url=None): thisuserdownvote = question.userDownVotes.filter(id=request.user.id).count() net_count = question.userUpVotes.count() - question.userDownVotes.count() + context = { 'question': question, 'answers': answers, 'form': form, 'thisUserUpvote': thisuserupvote, 'thisUserDownvote': thisuserdownvote, - 'net_count': net_count + 'net_count': net_count, + 'num_votes':question.num_votes } - context.update(csrf(request)) # updating views count question.views += 1 question.save() + return render(request, 'website/templates/get-question.html', context) @login_required @@ -343,7 +348,7 @@ def vote_post(request): num_votes = cur_post.userUpVotes.count() - cur_post.userDownVotes.count() cur_post.num_votes = num_votes cur_post.save() - + print "Num Votes: %s" % num_votes return HttpResponse(num_votes) |