Ordnet html-visning av hyller.
Denne trenger fiksing, gjerne med CSS-magi, men viser foreløpig hyller med kategorier representert som html-tabeller.
This commit is contained in:
parent
39c3e4ec38
commit
77490d2173
|
@ -230,6 +230,16 @@ class Placement(models.Model):
|
|||
shelf_list[placement.get_column()][placement.get_row()].append(placement.category)
|
||||
return shelf_list
|
||||
|
||||
@staticmethod
|
||||
def shelf_as_list_row_then_col(shelfname):
|
||||
placements = Placement.objects.filter(shelf__startswith=shelfname)
|
||||
rows = max(map(lambda x: x.get_row(), placements))
|
||||
columns = max(map(lambda x: x.get_column(), placements))
|
||||
shelf_list = [ [[] for i in xrange(columns+1)] for j in xrange(rows+1)]
|
||||
for placement in placements:
|
||||
shelf_list[placement.get_row()][placement.get_column()].append(placement.category)
|
||||
return shelf_list
|
||||
|
||||
@staticmethod
|
||||
def get_all_shelves():
|
||||
shelves = set()
|
||||
|
|
|
@ -1,8 +1,10 @@
|
|||
from web.library.models import *
|
||||
from django.http import HttpResponse, HttpResponseRedirect
|
||||
from django.http import HttpResponse, HttpResponseRedirect, Http404
|
||||
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)
|
||||
|
@ -17,3 +19,9 @@ 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})
|
||||
|
||||
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})
|
||||
|
|
|
@ -0,0 +1,24 @@
|
|||
{% extends "base/main.html" %}
|
||||
|
||||
{%block title%}
|
||||
Worblehat 0.1: Fresh, detailed, life-saving maps!
|
||||
{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<table border="1">
|
||||
{% for row in shelf %}
|
||||
<tr>
|
||||
{% for column in row %}
|
||||
<td>
|
||||
<table>
|
||||
{% for category in column %}
|
||||
<tr><td><a href="/category/{{ category.id }}"> {{ category }} </a></td></tr>
|
||||
{% endfor %}
|
||||
</table>
|
||||
</td>
|
||||
{% endfor %}
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</table>
|
||||
{% endblock %}
|
||||
|
|
@ -15,6 +15,7 @@ urlpatterns = patterns('',
|
|||
(r'^book/(?P<book_identifier>\d+)$','web.library.views.BookView'),
|
||||
(r'^book/(?P<book_identifier>\S+)$','web.library.views.BookRedirect'),
|
||||
(r'^person/(?P<person_identifier>\S+)$','web.library.views.PersonView'),
|
||||
(r'^map/(?P<shelf_identifier>\S+)$', 'web.library.views.MapView'),
|
||||
# Uncomment the next line to enable the admin:
|
||||
(r'^admin/', include(admin.site.urls)),
|
||||
)
|
||||
|
|
Reference in New Issue