Skip to content
Snippets Groups Projects
Verified Commit 677bf77d authored by TheJoeCoder's avatar TheJoeCoder
Browse files

Read book pages for pdf and invalid

parent db387f89
Branches
No related tags found
No related merge requests found
{% extends "base.html" %}
{% block content %}
<h1 class="title">
Invalid file type.
</h1>
<p>
Unfortunately this file type is not available at the moment. Please try again later.
{% if request.META.HTTP_REFERER %}
<a href="{{ request.META.HTTP_REFERER }}">Go back</a>
{% endif %}
</p>
{% endblock %}
\ No newline at end of file
{% load static %}
<!DOCTYPE html>
<!--
Based on PDF.js.
Modified for use here - original code is at https://github.com/mozilla/pdf.js
Original comment below:
Copyright 2012 Mozilla Foundation
Licensed under the Apache License, Version 2.0 (the "License");
......@@ -35,7 +39,7 @@ See https://github.com/adobe-type-tools/cmap-resources
<link rel="stylesheet" href="{% static "pdfjs/viewer.css" %}">
<script type="module">
{% include "reader/viewer.mjs" %}
{% include "reader/book_read/viewer.mjs" %}
</script>
</head>
......
......@@ -38,7 +38,7 @@
<span>{{ user_book.percentage_read_whole }}%</span>
</div>
<div class="column is-narrow">
<a href="#" class="button is-success">Read</a>
<a href="{% url 'read_book' book_id=book.id %}" class="button is-success">Read</a>
</div>
</div>
{% elif user.is_authenticated %}
......
......@@ -8,4 +8,5 @@ urlpatterns = [
path("books/create", views.create_book, name='create_book'),
path("books/<int:book_id>", views.view_book, name='view_book'),
path("books/<int:book_id>/to_library", views.add_to_library, name='add_to_library'),
path("books/<int:book_id>/read", views.read_book, name='read_book'),
]
\ No newline at end of file
......@@ -132,3 +132,22 @@ def add_to_library(request, book_id):
userbook = UserBook(book=book, user=request.user)
userbook.save()
return redirect("view_book", book_id=book_id)
def read_book(request, book_id):
book = get_object_or_404(Book, id=book_id)
if not user_can_access_book(request, book):
raise PermissionDenied
userbook = get_object_or_404(UserBook, book=book, user=request.user)
# Check file type
match book.file_type:
case "pdf":
reader_template = "reader/book_read/pdf_viewer.html"
case "epub":
reader_template = "reader/book_read/epub_viewer.html"
case _:
reader_template = "reader/book_read/invalid_filetype.html"
return render(request, reader_template, {
"book": book,
"userbook": userbook
})
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment