From 8533d61eb93ecb4c943ec3c3b83dfef87b20a916 Mon Sep 17 00:00:00 2001 From: Jayaram Pai Date: Sun, 1 Dec 2013 13:09:49 +0530 Subject: basic auth and new-question --- forums/forms.py | 6 ++ forums/settings.py | 1 + forums/urls.py | 4 ++ forums/views.py | 34 +++++++++ static/forums/templates/user-login.html | 4 ++ static/website/css/main.css | 8 ++- static/website/images/ajax-loader.gif | Bin 0 -> 847 bytes static/website/js/custom.js | 44 ++++++++++++ static/website/templates/ajax-duration.html | 16 +++++ static/website/templates/ajax-tutorials.html | 4 ++ static/website/templates/base.html | 3 +- static/website/templates/fetch_questions.html | 9 +++ static/website/templates/fetch_tutorials.html | 2 +- static/website/templates/get_tutorial.html | 12 ++++ static/website/templates/index.html | 6 +- static/website/templates/new-post.html | 45 ++++++++++++ static/website/templates/new-question.html | 45 ++++++++++++ static/website/templates/recent_questions.html | 5 ++ website/forms.py | 71 ++++++++++++++++++ website/helpers.py | 3 + website/models.py | 8 ++- website/templatetags/count_tags.py | 60 ++++++++++++++-- website/templatetags/sidebar_tags.py | 11 ++- website/urls.py | 10 ++- website/views.py | 96 +++++++++++++++---------- 25 files changed, 448 insertions(+), 59 deletions(-) create mode 100644 forums/forms.py create mode 100644 forums/views.py create mode 100644 static/forums/templates/user-login.html create mode 100644 static/website/images/ajax-loader.gif create mode 100644 static/website/js/custom.js create mode 100644 static/website/templates/ajax-duration.html create mode 100644 static/website/templates/ajax-tutorials.html create mode 100644 static/website/templates/fetch_questions.html create mode 100644 static/website/templates/get_tutorial.html create mode 100644 static/website/templates/new-post.html create mode 100644 static/website/templates/new-question.html create mode 100644 static/website/templates/recent_questions.html create mode 100644 website/forms.py diff --git a/forums/forms.py b/forums/forms.py new file mode 100644 index 0000000..2e3a6d1 --- /dev/null +++ b/forums/forms.py @@ -0,0 +1,6 @@ +from django import forms + +class UserLoginForm(forms.Form): + username = forms.CharField() + password = forms.CharField(widget=forms.PasswordInput()) + diff --git a/forums/settings.py b/forums/settings.py index 3345be2..37d6202 100644 --- a/forums/settings.py +++ b/forums/settings.py @@ -143,6 +143,7 @@ INSTALLED_APPS = ( # Uncomment the next line to enable admin documentation: # 'django.contrib.admindocs', 'website', + 'widget_tweaks', ) # A sample logging configuration. The only tangible logging diff --git a/forums/urls.py b/forums/urls.py index 1e4ee04..e129d4b 100644 --- a/forums/urls.py +++ b/forums/urls.py @@ -15,4 +15,8 @@ urlpatterns = patterns('', # Uncomment the next line to enable the admin: url(r'^admin/', include(admin.site.urls)), + + # User account urls + url(r'^accounts/login/', 'forums.views.user_login', name='user_login'), + url(r'^accounts/logout/', 'forums.views.user_logout', name='user_logout'), ) diff --git a/forums/views.py b/forums/views.py new file mode 100644 index 0000000..6890d61 --- /dev/null +++ b/forums/views.py @@ -0,0 +1,34 @@ +from django.http import HttpResponse, HttpResponseRedirect +from django.contrib.auth import login, logout, authenticate +from django.shortcuts import render_to_response +from django.core.context_processors import csrf + +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) + return HttpResponseRedirect('/') + else: + return HttpResponse('you are blocked') + else: + return HttpResponse('Invalid username or password') + else: + form = UserLoginForm() + context = { + 'form': form + } + context.update(csrf(request)) + return render_to_response('forums/templates/user-login.html', context) + else: + return HttpResponseRedirect('/') + +def user_logout(request): + logout(request) + return HttpResponseRedirect('/') diff --git a/static/forums/templates/user-login.html b/static/forums/templates/user-login.html new file mode 100644 index 0000000..6ac4fee --- /dev/null +++ b/static/forums/templates/user-login.html @@ -0,0 +1,4 @@ +
diff --git a/static/website/css/main.css b/static/website/css/main.css index 997a154..9e68e7f 100644 --- a/static/website/css/main.css +++ b/static/website/css/main.css @@ -9,12 +9,15 @@ } #content-inner { +} +#content{ + min-height: 600px; } #content .category { min-height: 50px; border-bottom: 1px solid #f5f5f5; } -#content .category .posts { +#content .category .questions { color: #7395d9; } #content .category .replies { @@ -38,3 +41,6 @@ #footer-inner { } +.field_error { + border: 1px solid red; +} diff --git a/static/website/images/ajax-loader.gif b/static/website/images/ajax-loader.gif new file mode 100644 index 0000000..e192ca8 Binary files /dev/null and b/static/website/images/ajax-loader.gif differ diff --git a/static/website/js/custom.js b/static/website/js/custom.js new file mode 100644 index 0000000..20801f6 --- /dev/null +++ b/static/website/js/custom.js @@ -0,0 +1,44 @@ +$(document).ready(function() { + $category = $("#id_category"); + $tutorial = $("#id_tutorial"); + $minute_range = $("#id_minute_range"); + $second_range = $("#id_second_range"); + + $category.change(function() { + var category = $(this).val(); + $.ajax({ + url: "/ajax-tutorials/", + type: "POST", + data: { + category: category + }, + success: function(data) { + $("#id_tutorial").html(data); + $("#id_tutorial").removeAttr("disabled"); + console.log("response = " + data); + } + }); + }); + + $tutorial.change(function() { + console.log("tut changed"); + var category = $category.val(); + var tutorial = $(this).val(); + $.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"); + } + }); + }); +}); diff --git a/static/website/templates/ajax-duration.html b/static/website/templates/ajax-duration.html new file mode 100644 index 0000000..f89927b --- /dev/null +++ b/static/website/templates/ajax-duration.html @@ -0,0 +1,16 @@ +{% load count_tags %} +