rakkapy/books/views.py

22 lines
1.1 KiB
Python
Raw Normal View History

from . import models
from rakka.utils import rerender
@rerender
def index():
books=models.Book.objects.all()
#Make table I guess, for now just get data up there
contents='<br/>\n'.join([f'<a href="/books/{book.url}">{book}</a> - {book.last_updated}' for book in books])
return {'title':'Booklist','content':contents+"<br/>\nYou should be able to read books now.",'date':'2021/10/24'}
@rerender
def book(bookurl):
book=models.Book.objects.filter(url=bookurl)[0]
chapters=models.Chapter.objects.filter(book=book).order_by('added')
return {'title':book.title,'content':'<a href="/books/">Top</a><br/>\n'+'<br/>\n'.join([f'<a href="/books/{book.url}/{chap.number}">{chap}</a> - {chap.added}' for chap in chapters]),'date':book.last_updated}
@rerender
def chapter(bookurl,chapnum):
book=models.Book.objects.filter(url=bookurl)[0]
chapter=models.Chapter.objects.filter(book=book,number=chapnum)[0]
2021-10-29 05:53:01 +11:00
text='<p>'+chapter.contents.replace('<','&lt;').replace('>','&gt;').replace('\n\n','</p><p>').replace('\n','<br/>')+'</p>'
2021-10-29 05:53:33 +11:00
return {'title':chapter,'content':'<p>Navigation buttons will come later...</p>\n'+text,'date':chapter.added}