From e2dcdc460f9398b212064bbb0566c0e02141a5c2 Mon Sep 17 00:00:00 2001 From: almelid Date: Sat, 5 Mar 2011 19:33:11 +0000 Subject: [PATCH] skrevet views for bok og person --- python/web/library/models.py | 4 ++-- python/web/library/views.py | 18 ++++++++++++++++++ python/web/settings.py | 1 + python/web/urls.py | 7 +++++-- 4 files changed, 26 insertions(+), 4 deletions(-) diff --git a/python/web/library/models.py b/python/web/library/models.py index 50f68b8..26b2bc9 100644 --- a/python/web/library/models.py +++ b/python/web/library/models.py @@ -40,8 +40,8 @@ class Book(models.Model): num_pages = models.IntegerField(null=True, blank=True) series = models.ForeignKey(BookSeries, related_name='books', null=True, blank=True) description = models.CharField(max_length=1023, null=True, blank=True) - picture = models.ImageField(upload_to='%Y/%m/%d/pictures', null=True, blank=True) - thumbnail = models.ImageField(upload_to='%Y/%m/%d/thumbnails', null=True, blank=True) + picture = models.ImageField(upload_to='pictures', null=True, blank=True) + thumbnail = models.ImageField(upload_to='thumbnails', null=True, blank=True) # references = models.ManyToManyField(Reference, related_name='books',null=True, blank=True) #Generate a string from book info diff --git a/python/web/library/views.py b/python/web/library/views.py index 60f00ef..f3c86fc 100644 --- a/python/web/library/views.py +++ b/python/web/library/views.py @@ -1 +1,19 @@ +from web.library.models import * +from django.http import HttpResponse, HttpResponseRedirect +from django.shortcuts import render_to_response, get_object_or_404 + + # Create your views here. +def BookView(request,book_identifier): + book=get_object_or_404(Book,isbn=book_identifier) + people = book.persons.all() + return render_to_response('book/view.html', {'book' : book, 'people' : people}) + +def BookRedirect(request,book_identifier): + ident=get_object_or_404(Id,id=book_identifier) + return HttpResponseRedirect('/book/'+ident.book.isbn) + +def PersonView(request,person_identifier): + person = get_object_or_404(Person,id=person_identifier) + books = person.books.all() + return render_to_response('person/view.html', {'title' : 'Worblehat: person '+person.first_name+' '+person.last_name,'person' : person, 'books' : books}) diff --git a/python/web/settings.py b/python/web/settings.py index 2f6a233..0a841eb 100644 --- a/python/web/settings.py +++ b/python/web/settings.py @@ -69,6 +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/' ) INSTALLED_APPS = ( diff --git a/python/web/urls.py b/python/web/urls.py index c13d89e..d03b3f1 100644 --- a/python/web/urls.py +++ b/python/web/urls.py @@ -1,5 +1,5 @@ from django.conf.urls.defaults import * - +from django.conf import settings # Uncomment the next two lines to enable the admin: from django.contrib import admin admin.autodiscover() @@ -11,7 +11,10 @@ urlpatterns = patterns('', # Uncomment the admin/doc line below and add 'django.contrib.admindocs' # to INSTALLED_APPS to enable admin documentation: # (r'^admin/doc/', include('django.contrib.admindocs.urls')), - + (r'^media/(?P.*)$','django.views.static.serve',{'document_root' : settings.MEDIA_ROOT}), + (r'^book/(?P\d+)$','web.library.views.BookView'), + (r'^book/(?P\S+)$','web.library.views.BookRedirect'), + (r'^person/(?P\S+)$','web.library.views.PersonView'), # Uncomment the next line to enable the admin: (r'^admin/', include(admin.site.urls)), )