From 450d09fd574a6e2219764ac58169768568a97ed7 Mon Sep 17 00:00:00 2001 From: Alex Lewis Date: Sat, 29 Sep 2012 16:28:30 +1000 Subject: [PATCH] Added search --- bodyrep/apps/core/views.py | 11 ++++++++++- bodyrep/media/js/application.js | 4 +++- bodyrep/templates/core/member/profile.html | 1 - bodyrep/templates/core/user/searchResults.html | 14 ++++++++++++++ bodyrep/templates/navbar.html | 2 +- bodyrep/urls.py | 6 ++++-- 6 files changed, 32 insertions(+), 6 deletions(-) create mode 100644 bodyrep/templates/core/user/searchResults.html diff --git a/bodyrep/apps/core/views.py b/bodyrep/apps/core/views.py index f3c16ef..61e874e 100644 --- a/bodyrep/apps/core/views.py +++ b/bodyrep/apps/core/views.py @@ -17,6 +17,7 @@ from django.conf import settings from django.contrib.sites.models import Site from django.core.context_processors import csrf from django.template import RequestContext +from django.db.models import Q # Libs from annoying.decorators import render_to, ajax_request @@ -68,6 +69,15 @@ def login(request): return {'login_form':login_form} +@never_cache +def search(request, kw): + try: + members = Members.objects.filter(Q(firstname__icontains=kw) | Q(lastname__icontains=kw)) + + except Members.DoesNotExist: + x=1 + + return render_to_response ('core/user/searchResults.html', { 'user': request.user, 'members': members} ) @never_cache def dologin(request): @@ -94,7 +104,6 @@ def logout(request): @ajax_request @render_to('core/user/editProfile.html') def editUserProfile(request): - sys.stderr.write('xxx\n\n') if request.user.is_anonymous(): return login(request) else: diff --git a/bodyrep/media/js/application.js b/bodyrep/media/js/application.js index 87f1728..b4df4f7 100644 --- a/bodyrep/media/js/application.js +++ b/bodyrep/media/js/application.js @@ -5,15 +5,17 @@ $(function() { $('#mcnt').html(data); }); }); + $('form#topsearch').live('submit', function(){ frm = $(this); var searchTerm = frm.find('input').val(); url = frm.attr('action') + '/'+searchTerm; $.get(url, {}, function(data) { - $('.symfony-content > .row-fluid').html(data); + $('.symfony-content').html(data); }); return false; }); + $('form#profile').live('submit', function(){ frm = $(this); $.post(frm.attr('action'), frm.serialize(), function(response) { diff --git a/bodyrep/templates/core/member/profile.html b/bodyrep/templates/core/member/profile.html index 218ec77..267931c 100644 --- a/bodyrep/templates/core/member/profile.html +++ b/bodyrep/templates/core/member/profile.html @@ -25,7 +25,6 @@

{{ member.firstname }} {{ member.lastname }}

- Edit Profile
Weight: 100kg (
0)
diff --git a/bodyrep/templates/core/user/searchResults.html b/bodyrep/templates/core/user/searchResults.html new file mode 100644 index 0000000..72b1df3 --- /dev/null +++ b/bodyrep/templates/core/user/searchResults.html @@ -0,0 +1,14 @@ + +{% block content %} +{% include 'navbar.html' %} +

Search Results

+ + {% if members %} + {% for m in members %} +

{{ m.firstname }} {{ m.lastname }}

+ {% endfor %} + {% else %} + No members found with that keyword + {% endif %} + +{% endblock %} diff --git a/bodyrep/templates/navbar.html b/bodyrep/templates/navbar.html index 053123c..a310701 100644 --- a/bodyrep/templates/navbar.html +++ b/bodyrep/templates/navbar.html @@ -27,7 +27,7 @@
-
diff --git a/bodyrep/urls.py b/bodyrep/urls.py index 283af09..75a28ed 100644 --- a/bodyrep/urls.py +++ b/bodyrep/urls.py @@ -21,7 +21,9 @@ urlpatterns = patterns('', url(r'^m/profile/?$', coreviews.showUserProfile, name='showUserProfile'), url(r'^m/profile/save/?$', coreviews.saveUserProfile, name='saveUserProfile'), url(r'^m/profile/edit/?$', coreviews.editUserProfile, name='editUser'), - + + url(r'^m/search/(.+)$', coreviews.search, name='search'), + # Auth url(r'^logout$', coreviews.logout, name='logout'), url(r'^login$', coreviews.login, name='login'), @@ -33,6 +35,6 @@ urlpatterns = patterns('', url(r'^admin/', include(admin.site.urls)), # Member profile - url(r'^([a-zA-Z0-9]+)', coreviews.showMemberProfile), + url(r'^([a-zA-Z0-9]+)', coreviews.showMemberProfile, name='showMemberProfile'), )