From 2e4605071e70593bb4fac4537c84b07aed4c3cf6 Mon Sep 17 00:00:00 2001 From: sanj Date: Sun, 7 Nov 2010 03:02:55 +0530 Subject: [PATCH] css - moved left menu up --- itf/erang_organised/urls.py | 1 + itf/erang_organised/views.py | 16 +++++++++++++ itf/settings.py | 2 ++ itf/templates/erang/home.html | 43 +++++++++++++++++++++++++++++++++-- 4 files changed, 60 insertions(+), 2 deletions(-) diff --git a/itf/erang_organised/urls.py b/itf/erang_organised/urls.py index 73ef3db..7e6aff7 100644 --- a/itf/erang_organised/urls.py +++ b/itf/erang_organised/urls.py @@ -7,5 +7,6 @@ urlpatterns = patterns('', #(r'^search/', include('solango.urls')), (r'^$', views.home), (r'^subscribe/$', views.subscribe), + (r'^search/$', views.search), (r'^postfeedback/$', views.postfeedback) ) diff --git a/itf/erang_organised/views.py b/itf/erang_organised/views.py index b76cd60..5589f99 100644 --- a/itf/erang_organised/views.py +++ b/itf/erang_organised/views.py @@ -5,6 +5,8 @@ from settings import ERANG_SUBSCRIBE_URL import urllib2 from django.http import HttpResponse from django.core.mail import send_mail +from django.db.models import Q +from oxdjango.shortcuts import render_to_json_response def home(request): all_issues = Issue.objects.all().order_by('-date') @@ -26,6 +28,20 @@ def subscribe(request): re = urllib2.urlopen(url).read() return HttpResponse(re) +def search(request): + terms = request.GET['search'] + words = terms.split(" ") + qset = Issue.objects.all() + issues = [] + for w in words: + qset = qset.filter(Q(title__icontains=w) | Q(summary__icontains=w)) + for issue in qset: + issues.append({ + 'id': issue.id, + 'title': issue.title, + 'summary': issue.summary, + }) + return render_to_json_response(issues) def postfeedback(request): p = request.POST diff --git a/itf/settings.py b/itf/settings.py index 0c7763a..7afa0c7 100644 --- a/itf/settings.py +++ b/itf/settings.py @@ -5,6 +5,8 @@ from os.path import join DEBUG = True TEMPLATE_DEBUG = DEBUG +JSON_DEBUG = DEBUG + LOCAL_DEVELOPMENT = True LOGGING_INTERCEPT_REDIRECTS = True LOGGING_LOG_SQL = True diff --git a/itf/templates/erang/home.html b/itf/templates/erang/home.html index 028a009..e170162 100644 --- a/itf/templates/erang/home.html +++ b/itf/templates/erang/home.html @@ -29,7 +29,14 @@ $(document).ready(function() { $(document).ready(function() { $('#subscribeForm').submit(function(e) { e.preventDefault(); - var email = $('#email').val(); + $('.validation').slideUp("fast"); + var $email = $('#email'); + var email = $email.val(); + if (!isRFC822ValidEmail(email)) { + $('
').addClass('validation').html("Invalid Email Address").hide().insertAfter($email).slideDown("slow"); +// $email.append(html); + return false; + } $('#subscribeBtn').attr("disabled", "disabled").text("Subscribing..."); $.post("/erang/subscribe/", { 'email': email @@ -59,6 +66,33 @@ $(document).ready(function() { }); }); +//from: http://rosskendall.com/blog/web/javascript-function-to-check-an-email-address-conforms-to-rfc822 + +function isRFC822ValidEmail(sEmail) { + + var sQtext = '[^\\x0d\\x22\\x5c\\x80-\\xff]'; + var sDtext = '[^\\x0d\\x5b-\\x5d\\x80-\\xff]'; + var sAtom = '[^\\x00-\\x20\\x22\\x28\\x29\\x2c\\x2e\\x3a-\\x3c\\x3e\\x40\\x5b-\\x5d\\x7f-\\xff]+'; + var sQuotedPair = '\\x5c[\\x00-\\x7f]'; + var sDomainLiteral = '\\x5b(' + sDtext + '|' + sQuotedPair + ')*\\x5d'; + var sQuotedString = '\\x22(' + sQtext + '|' + sQuotedPair + ')*\\x22'; + var sDomain_ref = sAtom; + var sSubDomain = '(' + sDomain_ref + '|' + sDomainLiteral + ')'; + var sWord = '(' + sAtom + '|' + sQuotedString + ')'; + var sDomain = sSubDomain + '(\\x2e' + sSubDomain + ')*'; + var sLocalPart = sWord + '(\\x2e' + sWord + ')*'; + var sAddrSpec = sLocalPart + '\\x40' + sDomain; // complete RFC822 email address spec + var sValidEmail = '^' + sAddrSpec + '$'; // as whole string + + var reValidEmail = new RegExp(sValidEmail); + + if (reValidEmail.test(sEmail)) { + return true; + } + + return false; +} +