From 56dd7b67c8b3fcd5d6b3dcbc50706538ec4c5491 Mon Sep 17 00:00:00 2001 From: almelid Date: Sun, 6 Mar 2011 16:57:12 +0000 Subject: [PATCH] =?UTF-8?q?Lagt=20til=20s=C3=B8keside.=20Mye=20flikking=20?= =?UTF-8?q?p=C3=A5=20url-configen.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- python/web/library/models.py | 2 +- python/web/library/views.py | 38 +++++++++++++++++++------ python/web/settings.py | 2 +- python/web/templates/index.html | 13 +++++++++ python/web/templates/person/view.html | 2 +- python/web/templates/search/search.html | 21 ++++++++++++++ python/web/urls.py | 2 ++ 7 files changed, 69 insertions(+), 11 deletions(-) create mode 100644 python/web/templates/index.html create mode 100644 python/web/templates/search/search.html diff --git a/python/web/library/models.py b/python/web/library/models.py index 2e646f9..7a02e20 100644 --- a/python/web/library/models.py +++ b/python/web/library/models.py @@ -208,7 +208,7 @@ class BookPerson(models.Model): return self.person.first_name +u' '+ self.person.last_name+ u' '+ self.relation.name+ u' of '+self.book.title class Placement(models.Model): - category = models.ForeignKey(Category) + category = models.ForeignKey(Category,related_name='placement') shelf = models.CharField(max_length=10) def __unicode__(self): diff --git a/python/web/library/views.py b/python/web/library/views.py index 7c8e4ef..335c0b4 100644 --- a/python/web/library/views.py +++ b/python/web/library/views.py @@ -1,11 +1,8 @@ from web.library.models import * from django.http import HttpResponse, HttpResponseRedirect, Http404 from django.shortcuts import render_to_response, get_object_or_404 +from django.db.models import Q - - - -# Create your views here. def BookView(request,book_identifier): book=get_object_or_404(Book,isbn=book_identifier) people = book.persons.all() @@ -21,7 +18,32 @@ def PersonView(request,person_identifier): return render_to_response('person/view.html', {'title' : 'Worblehat: person '+person.first_name+' '+person.last_name,'person' : person, 'books' : books}) def MapView(request,shelf_identifier): - if shelf_identifier not in Placement.get_all_shelves(): - raise Http404() - shelf_list = Placement.shelf_as_list_row_then_col(shelf_identifier) - return render_to_response('map/view.html', {'shelf': shelf_list}) + if shelf_identifier not in Placement.get_all_shelves(): + raise Http404() + shelf_list = Placement.shelf_as_list_row_then_col(shelf_identifier) + return render_to_response('map/view.html', {'shelf': shelf_list}) + +def IndexView(request): + return render_to_response('index.html') + +def SearchView(request): + search_string=request.GET['searchterm'] + results=search(search_string) + return render_to_response('search/search.html',{'search_string' : search_string, 'books' : results[0], 'people' : results[1], 'categories' : results[2]}) + +def search(string): + book_q=Book.objects.select_related('id','alt_titles') + person_q=Person.objects + category_q=Category.objects + for word in string.split(" "): + book_q=book_q.filter(Q(title__icontains=word) | Q(subtitle__icontains=word) | + Q(alt_titles__alt_title__icontains=word) | Q(id__id__icontains=word)) + person_q=person_q.filter(Q(first_name__icontains=word) | Q(last_name__icontains=word) | Q(id__icontains=word)) + category_q=category_q.filter(Q(id__icontains=word)|Q(name__icontains=word)) + return [book_q.all(),person_q.all(),category_q.all()] + +def remove_duplicates(list): + d={} + for i in list: + d[i]=None + return d.keys() diff --git a/python/web/settings.py b/python/web/settings.py index 97abf6d..0a841eb 100644 --- a/python/web/settings.py +++ b/python/web/settings.py @@ -69,7 +69,7 @@ TEMPLATE_DIRS = ( # Put strings here, like "/home/html/django_templates" or "C:/www/django/templates". # Always use forward slashes, even on Windows. # Don't forget to use absolute paths, not relative paths. - '/web/templates/' + 'web/templates/' ) INSTALLED_APPS = ( diff --git a/python/web/templates/index.html b/python/web/templates/index.html new file mode 100644 index 0000000..313ca94 --- /dev/null +++ b/python/web/templates/index.html @@ -0,0 +1,13 @@ +{% extends "base/main.html" %} + +{% block title %} +Worblehat 0.1. Heisann!! +{% endblock %} + +{% block content %} +Velkommen til PVVs bokdatabase, Worblehat.
+Her kan du søke etter bøker til din hjertens lyst.
+
+
+
+{% endblock %} diff --git a/python/web/templates/person/view.html b/python/web/templates/person/view.html index bba1a4e..fae65a9 100644 --- a/python/web/templates/person/view.html +++ b/python/web/templates/person/view.html @@ -7,6 +7,6 @@ Worblehat 0.1: {{ person.first_name }} {{ person.last_name }} {% block content %} Name: {{person.first_name}} {{person.last_name}}
{% for book in books %} -{{ book.relation.name }} of: {{ book.book.title }}
+{{ book.relation.name }} of: {{ book.book.title }}
{% endfor %} {% endblock %} diff --git a/python/web/templates/search/search.html b/python/web/templates/search/search.html new file mode 100644 index 0000000..9730468 --- /dev/null +++ b/python/web/templates/search/search.html @@ -0,0 +1,21 @@ +{% extends "base/main.html" %} + +{% block title %} + Worblehat 0.1: Søk! +{% endblock %} + +{% block content %} + Du søkte på {{ search_string }}.
+ {% if people %} + Personer:
+ {% for person in people %} + {{ person.first_name }} {{ person.last_name }}
+ {% endfor %} + {% endif %} + {% if books %} + Bøker:
+ {% for book in books %} + {{ book.title }}
+ {% endfor %} + {% endif %} +{% endblock %} diff --git a/python/web/urls.py b/python/web/urls.py index 9da772d..074414f 100644 --- a/python/web/urls.py +++ b/python/web/urls.py @@ -18,4 +18,6 @@ urlpatterns = patterns('', (r'^kart/(?P\S+)/$', 'web.library.views.MapView'), # Uncomment the next line to enable the admin: (r'^admin/', include(admin.site.urls)), + (r'^let/','web.library.views.SearchView'), + (r'^$','web.library.views.IndexView'), )