#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:
parent
56dd7b67c8
commit
136d1dd7c3
|
@ -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
|
return self.person.first_name +u' '+ self.person.last_name+ u' '+ self.relation.name+ u' of '+self.book.title
|
||||||
|
|
||||||
class Placement(models.Model):
|
class Placement(models.Model):
|
||||||
category = models.ForeignKey(Category,related_name='placement')
|
category = models.ForeignKey(Category, related_name='placement')
|
||||||
shelf = models.CharField(max_length=10)
|
shelf = models.CharField(max_length=10)
|
||||||
|
|
||||||
def __unicode__(self):
|
def __unicode__(self):
|
||||||
|
|
|
@ -3,19 +3,54 @@ from django.http import HttpResponse, HttpResponseRedirect, Http404
|
||||||
from django.shortcuts import render_to_response, get_object_or_404
|
from django.shortcuts import render_to_response, get_object_or_404
|
||||||
from django.db.models import Q
|
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):
|
def BookView(request,book_identifier):
|
||||||
book=get_object_or_404(Book,isbn=book_identifier)
|
book=get_object_or_404(Book,isbn=book_identifier)
|
||||||
people = book.persons.all()
|
people = book.persons.all()
|
||||||
return render_to_response('book/view.html', {'book' : book, 'people' : people})
|
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):
|
def BookRedirect(request,book_identifier):
|
||||||
ident=get_object_or_404(Id,id=book_identifier)
|
ident=get_object_or_404(Id,id=book_identifier)
|
||||||
return HttpResponseRedirect('/book/'+ident.book.isbn)
|
return HttpResponseRedirect('/book/'+ident.book.isbn)
|
||||||
|
|
||||||
def PersonView(request,person_identifier):
|
def PersonView(request,person_identifier):
|
||||||
person = get_object_or_404(Person,id=person_identifier)
|
global relations
|
||||||
books = person.books.all()
|
person = get_object_or_404(Person,id=person_identifier)
|
||||||
return render_to_response('person/view.html', {'title' : 'Worblehat: person '+person.first_name+' '+person.last_name,'person' : person, 'books' : books})
|
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):
|
def MapView(request,shelf_identifier):
|
||||||
if shelf_identifier not in Placement.get_all_shelves():
|
if shelf_identifier not in Placement.get_all_shelves():
|
||||||
|
|
|
@ -75,6 +75,9 @@ img.aligncenter {
|
||||||
}
|
}
|
||||||
|
|
||||||
.img {
|
.img {
|
||||||
|
float: left;
|
||||||
|
display: inline;
|
||||||
|
margin-right: 10px;
|
||||||
text-align: left;
|
text-align: left;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,15 +1,56 @@
|
||||||
{% extends "base/main.html" %}
|
{% extends "base/main.html" %}
|
||||||
|
|
||||||
{%block title%}
|
{%block title%}
|
||||||
Worblehat 0.1: {{ book.title }}
|
Worblehat: {{ book.title }}
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
{% block content %}
|
{% block content %}
|
||||||
|
{% if book.thumbnail %}
|
||||||
|
<span class="img">
|
||||||
|
<img src="/media/{{ book.thumbnail }}" alt="{{ book.title }}">
|
||||||
|
</span>
|
||||||
|
{% endif %}
|
||||||
|
<span class="img">
|
||||||
|
<h2>{{ book.title }}</h2>
|
||||||
|
{% if book.subtitle %}
|
||||||
|
<h3>{{ book.subtitle }}</h3>
|
||||||
|
{% endif %}
|
||||||
|
<!---
|
||||||
<span class="key">Title:</span> {{ book.title }} <br>
|
<span class="key">Title:</span> {{ book.title }} <br>
|
||||||
{% if book.subtitle %}
|
{% if book.subtitle %}
|
||||||
<span class="key">Subtitle:</span> {{ book.subtitle }} <br>
|
<span class="key">Subtitle:</span> {{ book.subtitle }} <br>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
<span class="key">ISBN:</span> {{ book.isbn }} <br>
|
|
||||||
{% for person in people %}
|
{% for person in people %}
|
||||||
<span class="key">{{ person.relation }}:</span> <a href=/person/{{person.person.id}}>{{ person.person.first_name }} {{ person.person.last_name }}</a> <br>
|
<span class="key">{{ person.relation }}:</span> <a href=/person/{{person.person.id}}>{{ person.person.first_name }} {{ person.person.last_name }}</a> <br>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
---!>
|
||||||
|
{% for relation, persons in contributors.iteritems %}
|
||||||
|
<span class="key">{{ relation }}{% if persons.0 != 1 and relation != 'Medvirkende' %}e{% endif %}:</span>
|
||||||
|
{% for person in persons.1 %}
|
||||||
|
<a href=/person/{{person.person.id}}>{{ person.person.first_name }} {{ person.person.last_name }}</a>{% if not forloop.last %}, {% endif %}
|
||||||
|
{% endfor %}
|
||||||
|
<br>
|
||||||
|
{% endfor %}
|
||||||
|
{% if book.category %}
|
||||||
|
<span class="key">Kategori:</span> {{ book.category }} <br>
|
||||||
|
{% endif %}
|
||||||
|
{% if book.shelves %}
|
||||||
|
<span class="key">Hylle:</span> {{ book.shelves }} <br>
|
||||||
|
{% endif %}
|
||||||
|
{% if book.published_year %}
|
||||||
|
<span class="key">År:</span> {{ book.published_year }} <br>
|
||||||
|
{% endif %}
|
||||||
|
{% if book.edition %}
|
||||||
|
<span class="key">Utgave:</span> {{ book.edition }} <br>
|
||||||
|
{% endif %}
|
||||||
|
{% if book.num_pages %}
|
||||||
|
<span class="key">Antall sider:</span> {{ book.num_pages }} <br>
|
||||||
|
{% endif %}
|
||||||
|
{% if book.series %}
|
||||||
|
<span class="key">Serie:</span> {{ book.series }} <br>
|
||||||
|
{% endif %}
|
||||||
|
{% if book.description %}
|
||||||
|
<span class="key">Beskrivelse:</span> {{ book.description }} <br>
|
||||||
|
{% endif %}
|
||||||
|
<span class="key">ISBN:</span> {{ book.isbn }} <br>
|
||||||
|
</span>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
|
@ -1,12 +1,22 @@
|
||||||
{% extends "base/main.html" %}
|
{% extends "base/main.html" %}
|
||||||
|
|
||||||
{% block title%}
|
{% block title%}
|
||||||
Worblehat 0.1: {{ person.first_name }} {{ person.last_name }}
|
Worblehat: {{ person.first_name }} {{ person.last_name }}
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
{% block content %}
|
{% block content %}
|
||||||
<span class="key">Name:</span> {{person.first_name}} {{person.last_name}}<br>
|
<h2>{{ person.first_name }} {{ person.last_name }}</h2>
|
||||||
|
{% for relation, books in contributed.iteritems %}
|
||||||
|
<span class="key">{{ relation }}:</span><br/>
|
||||||
|
<ul>
|
||||||
|
{% for book in books.1 %}
|
||||||
|
<li> <a href=/bok/{{book.book.isbn}}>{{ book.book.title }}</a>
|
||||||
|
<!--- <span class="key">Name:</span> {{person.first_name}} {{person.last_name}}<br>
|
||||||
{% for book in books %}
|
{% for book in books %}
|
||||||
<span class="key">{{ book.relation.name }} of:</span> <a href=/bok/{{ book.book.isbn }}>{{ book.book.title }}</a> <br>
|
<span class="key">{{ book.relation.name }} of:</span> <a href=/bok/{{ book.book.isbn }}>{{ book.book.title }}</a> <br>
|
||||||
|
---!>
|
||||||
|
{% endfor %}
|
||||||
|
<br/>
|
||||||
|
</ul>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
Reference in New Issue