#9 og #10 løst. Alt ser ut til å fungere. Mer funksjonalitet kan legges til, men generelt ser ting greit ut.

This commit is contained in:
2011-03-06 17:14:25 +00:00
parent 56dd7b67c8
commit 136d1dd7c3
5 changed files with 102 additions and 13 deletions

View File

@@ -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,related_name='placement')
category = models.ForeignKey(Category, related_name='placement')
shelf = models.CharField(max_length=10)
def __unicode__(self):

View File

@@ -3,19 +3,54 @@ from django.http import HttpResponse, HttpResponseRedirect, Http404
from django.shortcuts import render_to_response, get_object_or_404
from django.db.models import Q
relations = {'Author' : u'Forfatter', 'Illustrator' : u'Tegner', 'Translator' : u'Oversetter'}
# 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})
book=get_object_or_404(Book,isbn=book_identifier)
people = book.persons.all()
shelves = None
global relations
if book.category:
if book.category.placement:
shelves = book.category.placement.all()
contributors = {}
for person in people:
print person.relation
if str(person.relation) in relations:
relation = relations[str(person.relation)]
else:
relation = 'Medvirkende'
if not relation in contributors:
contributors[relation] = [0, []]
# contributors[person.relation] = "%s %s" % (person.person.first_name, person.person.last_name)
# else:
contributors[relation][0] += 1
contributors[relation][1].append(person)
print contributors
return render_to_response('book/view.html', {'book' : book, 'people' : people, 'shelves' : shelves, 'contributors' : contributors})
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})
global relations
person = get_object_or_404(Person,id=person_identifier)
books = person.books.all()
contributed = {}
for book in books:
if str(book.relation) in relations:
relation = relations[str(book.relation)]
else:
relation = 'Medvirkende'
if not relation in contributed:
contributed[relation] = [0, []]
contributed[relation][0] += 1
contributed[relation][1].append(book)
return render_to_response('person/view.html', {'title' : 'Worblehat: person '+person.first_name+' '+person.last_name, 'person' : person, 'books' : books, 'contributed' : contributed })
def MapView(request,shelf_identifier):
if shelf_identifier not in Placement.get_all_shelves():