diff options
author | Jayaram Pai | 2014-05-03 18:22:10 +0530 |
---|---|---|
committer | Jayaram Pai | 2014-05-03 18:22:10 +0530 |
commit | 0a8b9fd4976f5d67c2b9701eb52ac4c6a309eec7 (patch) | |
tree | 98b04670483694ab7a5e6eb044902957eda8b273 | |
parent | 0e54a7e22115e1d6437c5be6991a08054dfc052a (diff) | |
download | FOSSEE-Forum-0a8b9fd4976f5d67c2b9701eb52ac4c6a309eec7.tar.gz FOSSEE-Forum-0a8b9fd4976f5d67c2b9701eb52ac4c6a309eec7.tar.bz2 FOSSEE-Forum-0a8b9fd4976f5d67c2b9701eb52ac4c6a309eec7.zip |
added General FOSS category, fixed user-login
-rw-r--r-- | forums/forms.py | 14 | ||||
-rw-r--r-- | forums/views.py | 38 | ||||
-rw-r--r-- | static/forums/templates/user-login.html | 10 | ||||
-rw-r--r-- | static/website/js/custom.js | 100 | ||||
-rw-r--r-- | static/website/templates/ajax-tutorials.html | 2 | ||||
-rw-r--r-- | static/website/templates/new-question.html | 2 | ||||
-rw-r--r-- | website/forms.py | 1 | ||||
-rw-r--r-- | website/views.py | 2 |
8 files changed, 114 insertions, 55 deletions
diff --git a/forums/forms.py b/forums/forms.py index 2e3a6d1..5a93b5f 100644 --- a/forums/forms.py +++ b/forums/forms.py @@ -1,6 +1,20 @@ from django import forms +from django.contrib.auth import login, logout, authenticate class UserLoginForm(forms.Form): username = forms.CharField() password = forms.CharField(widget=forms.PasswordInput()) + def clean(self): + cleaned_data = self.cleaned_data + username = cleaned_data.get('username') + password = cleaned_data.get('password') + if username is None or password is None: + raise forms.ValidationError("Invalid username or password") + user = authenticate(username=username, password=password) + 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 diff --git a/forums/views.py b/forums/views.py index a38d6b7..b2dae90 100644 --- a/forums/views.py +++ b/forums/views.py @@ -8,29 +8,25 @@ from forums.forms import UserLoginForm def user_login(request): if request.user.is_anonymous(): if request.method == 'POST': - username = request.POST['username'] - password = request.POST['password'] - user = authenticate(username=username, password=password) - if user is not None: - if user.is_active: - login(request, user) - if 'next' in request.POST: - next_url = request.POST.get('next') - return HttpResponseRedirect(next_url) - return HttpResponseRedirect('/') - else: - return HttpResponse('you are blocked') - else: - return HttpResponse('Invalid username or password') + form = UserLoginForm(request.POST) + if form.is_valid(): + cleaned_data = form.cleaned_data + user = cleaned_data.get("user") + login(request, user) + if 'next' in request.POST: + next_url = request.POST.get('next') + return HttpResponseRedirect(next_url) + return HttpResponseRedirect('/') else: form = UserLoginForm() - next_url = request.GET.get('next') - context = { - 'form': form, - 'next': next_url - } - context.update(csrf(request)) - return render_to_response('forums/templates/user-login.html', context) + + next_url = request.GET.get('next') + context = { + 'form': form, + 'next': next_url + } + context.update(csrf(request)) + return render_to_response('forums/templates/user-login.html', context) else: return HttpResponseRedirect('/') diff --git a/static/forums/templates/user-login.html b/static/forums/templates/user-login.html index 21c4551..ef62ffe 100644 --- a/static/forums/templates/user-login.html +++ b/static/forums/templates/user-login.html @@ -6,6 +6,12 @@ <div class="col-lg-6" style="border-right: 1px dashed #424242;"> <h4>Please login with your <br>Spoken-Tutorial.org account.</h4> <form action="/accounts/login/" method="POST"> {% csrf_token %} + {% if form.errors %} + <div class="alert alert-danger"> + <button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button> + Invalid username or password + </div> + {% endif %} {% with WIDGET_ERROR_CLASS='field_error' %} <div class="form-group"> <label for="id_username">Username:</label> @@ -39,3 +45,7 @@ </div> <!-- /.col --> </div> <!-- /.row --> {% endblock %} + +{% block javascript %} + $(".alert").alert(); +{% endblock %} diff --git a/static/website/js/custom.js b/static/website/js/custom.js index 49b4053..5565683 100644 --- a/static/website/js/custom.js +++ b/static/website/js/custom.js @@ -4,45 +4,86 @@ $(document).ready(function() { $minute_range = $("#id_minute_range"); $second_range = $("#id_second_range"); + function reset() { + for (var i = 0, l = arguments.length; i < l; i ++) { + switch(arguments[i]) { + case "tutorial": + $tutorial.html("<option value='None'>Select a Tutorial</option>"); + $tutorial.attr("disabled", true); + break; + + case "minute_range": + $minute_range.html("<option value='None'>min</option>"); + $minute_range.attr("disabled", true); + break; + + case "second_range": + $second_range.html("<option value='None'>sec</option>"); + $second_range.attr("disabled", true); + break; + + } + } + } + $category.change(function() { $("#similar-link").hide(); - var category = $(this).val(); + /* resetting dropdowns */ + reset("tutorial", "minute_range", "second_range"); /* see thread-user.js */ $("#question-details-ok").show(); - $.ajax({ - url: "/ajax-tutorials/", - type: "POST", - data: { - category: category - }, - success: function(data) { - $("#id_tutorial").html(data); - $("#id_tutorial").removeAttr("disabled"); - console.log("response = " + data); - } - }); + var category = $(this).val(); + if(category == "General") { + /* disabling all other fields */ + $tutorial.html("<option value='None'>Not required</option>"); + $tutorial.removeAttr("disabled"); + $minute_range.html("<option value='None'>Not required</option>"); + $minute_range.removeAttr("disabled"); + $second_range.html("<option value='None'>Not required</option>"); + $second_range.removeAttr("disabled"); + } else { + $.ajax({ + url: "/ajax-tutorials/", + type: "POST", + data: { + category: category + }, + success: function(data) { + $("#id_tutorial").html(data); + $("#id_tutorial").removeAttr("disabled"); + } + }); + } }); $tutorial.change(function() { - console.log("tut changed"); + /* resetting dropdowns */ + reset("minute_range", "second_range"); var category = $category.val(); var tutorial = $(this).val(); - $.ajax({ - url: "/ajax-duration/", - type: "POST", - data: { - category: category, + if(tutorial == "General") { + /* disabling all other fields */ + $minute_range.html("<option value='None'>Not required</option>"); + $minute_range.removeAttr("disabled"); + $second_range.html("<option value='None'>Not required</option>"); + $second_range.removeAttr("disabled"); + } else { + $.ajax({ + url: "/ajax-duration/", + type: "POST", + data: { + category: category, tutorial: tutorial - }, - success: function(data){ - var $response = $(data); - console.log($response.html()); - $minute_range.html($response.find("#minutes").html()) - $minute_range.removeAttr("disabled"); - $second_range.html($response.find("#seconds").html()) - $second_range.removeAttr("disabled"); - } - }); + }, + success: function(data){ + var $response = $(data); + $minute_range.html($response.find("#minutes").html()) + $minute_range.removeAttr("disabled"); + $second_range.html($response.find("#seconds").html()) + $second_range.removeAttr("disabled"); + } + }); + } }); $second_range.change(function() { @@ -57,7 +98,6 @@ $(document).ready(function() { }, dataType: "html", success: function(data) { - console.log(data); $response = $(data); var similar_count= $response.find("#similar-count").text(); $("#similar-link").show().html(similar_count); diff --git a/static/website/templates/ajax-tutorials.html b/static/website/templates/ajax-tutorials.html index 63e6000..c19fe3c 100644 --- a/static/website/templates/ajax-tutorials.html +++ b/static/website/templates/ajax-tutorials.html @@ -2,4 +2,4 @@ {% for tutorial in tutorials %} <option value="{{ tutorial.tutorial_name }}">{{ tutorial.tutorial_name }}</option> {% endfor %} -<option value="General">General Question</option> +<option value="General">General</option> diff --git a/static/website/templates/new-question.html b/static/website/templates/new-question.html index 16c6021..28fc707 100644 --- a/static/website/templates/new-question.html +++ b/static/website/templates/new-question.html @@ -11,7 +11,7 @@ {% with WIDGET_ERROR_CLASS='field_error' %} <p> - Please enter the tutorial details. {{ category }} + Please enter the tutorial details. <img id="ajax-loader" src="{% static 'website/images/ajax-loader.gif' %}" style="display:none;"> </p> <div class="row"> diff --git a/website/forms.py b/website/forms.py index c8f3578..b982d54 100644 --- a/website/forms.py +++ b/website/forms.py @@ -4,6 +4,7 @@ from website.models import * categories = ( ("None", "Select a Category"), + ("General", "General"), ('Advanced-C++', 'Advanced-C++'), ('BASH', 'BASH'), ('Blender', 'Blender'), diff --git a/website/views.py b/website/views.py index 0665b0f..e349daa 100644 --- a/website/views.py +++ b/website/views.py @@ -245,13 +245,11 @@ def new_question(request): question.tutorial, 'http://forums.spoken-tutorial.org/question/'+str(question.id) ) - email = EmailMultiAlternatives( subject,'', 'forums', ['team@spoken-tutorial.org', 'team@fossee.in'], headers={"Content-type":"text/html;charset=iso-8859-1"} ) - email.attach_alternative(message, "text/html") email.send(fail_silently=True) # End of email send |