mirror of
https://github.com/ajurna/cbwebreader.git
synced 2025-12-06 06:17:17 +00:00
Sri (#35)
* added django-sri and updated templates. * updated requirements.txt * datatables with integrity * fixed recent comics not showing when related comicstatus doesnt exist. * fixed classifications on recent comcis. * fixed classifications on recent comcis. * fixed classifications on recent comcis. * fixed classifications on recent comcis. * fixed classifications on recent comcis. * fixes for pymupdy 1.18.13 * fixes for pymupdy 1.18.13 * fixes for pymupdy 1.18.13 * fixes for pymupdy 1.18.13 * fixes for pymupdy 1.18.13 * fixes for pymupdy 1.18.13 * fixes for pymupdy 1.18.13 * fixes for pymupdy 1.18.13 * fixes for pymupdy 1.18.13 * fixes for pymupdy 1.18.13 * fixes for pymupdy 1.18.13 * fixes for pymupdy 1.18.13 * fixes for pymupdy 1.18.13 * fixes for pymupdy 1.18.13 * fixes for pymupdy 1.18.13 * fixes for pymupdy 1.18.13 * fixes for pymupdy 1.18.13 * fixes for pymupdy 1.18.13 * fixes for pymupdy 1.18.13 * fixes for pymupdy 1.18.13 * fixes for pymupdy 1.18.13 * fixes for pymupdy 1.18.13 * fixes for pymupdy 1.18.13 * fixes for pymupdy 1.18.13 * fixes for pymupdy 1.18.13 * fix for pdf's not switching properly * fix for comics's not switching properly * fix for comics's not switching properly
This commit is contained in:
@@ -1,25 +1,39 @@
|
||||
import uuid
|
||||
|
||||
from django.contrib.auth.models import User
|
||||
from django.contrib.syndication.views import Feed
|
||||
from django.db.models import Case, When, PositiveSmallIntegerField, F
|
||||
from django.http import HttpRequest
|
||||
from django.shortcuts import get_object_or_404
|
||||
from django.urls import reverse
|
||||
from django.utils.http import urlsafe_base64_decode, urlsafe_base64_encode
|
||||
|
||||
from .models import ComicBook, UserMisc
|
||||
from .models import ComicBook, UserMisc, Directory
|
||||
|
||||
|
||||
class RecentComics(Feed):
|
||||
title = "CBWebReader Recent Comics"
|
||||
link = "/comics/"
|
||||
description = "Recently added Comics"
|
||||
user: User
|
||||
|
||||
def get_object(self, request: HttpRequest, user_selector: str, *args, **kwargs) -> UserMisc:
|
||||
user_selector = uuid.UUID(bytes=urlsafe_base64_decode(user_selector))
|
||||
return get_object_or_404(UserMisc, feed_id=user_selector)
|
||||
user_misc = get_object_or_404(UserMisc, feed_id=user_selector)
|
||||
self.user = user_misc.user
|
||||
return user_misc.user
|
||||
|
||||
@staticmethod
|
||||
def items() -> ComicBook:
|
||||
return ComicBook.objects.order_by("-date_added")[:10]
|
||||
def items(self) -> ComicBook:
|
||||
comics = ComicBook.objects.order_by("-date_added")
|
||||
comics = comics.annotate(
|
||||
classification=Case(
|
||||
When(directory__isnull=True, then=Directory.Classification.C_18),
|
||||
default=F('directory__classification'),
|
||||
output_field=PositiveSmallIntegerField(choices=Directory.Classification.choices)
|
||||
)
|
||||
)
|
||||
comics = comics.filter(classification__lte=self.user.usermisc.allowed_to_read)
|
||||
return comics[:10]
|
||||
|
||||
def item_title(self, item: ComicBook) -> str:
|
||||
return item.file_name
|
||||
@@ -29,4 +43,4 @@ class RecentComics(Feed):
|
||||
|
||||
# item_link is only needed if NewsItem has no get_absolute_url method.
|
||||
def item_link(self, item: ComicBook) -> str:
|
||||
return f"/comic/read/{urlsafe_base64_encode(item.selector.bytes)}/"
|
||||
return reverse('read_comic', args=(urlsafe_base64_encode(item.selector.bytes),))
|
||||
|
||||
@@ -242,9 +242,13 @@ class ComicBook(models.Model):
|
||||
return ComicPage.objects.filter(Comic=self).count()
|
||||
|
||||
def nav(self, user):
|
||||
next_path, next_type = self.nav_get_next_comic(user)
|
||||
prev_path, prev_type = self.nav_get_prev_comic(user)
|
||||
return {
|
||||
"next_path": self.nav_get_next_comic(user),
|
||||
"prev_path": self.nav_get_prev_comic(user),
|
||||
"next_path": next_path,
|
||||
"next_type": next_type,
|
||||
"prev_path": prev_path,
|
||||
"prev_type": prev_type,
|
||||
"cur_path": urlsafe_base64_encode(self.selector.bytes)
|
||||
}
|
||||
|
||||
@@ -258,17 +262,17 @@ class ComicBook(models.Model):
|
||||
comic_index = dir_list.index(self.file_name)
|
||||
if comic_index == 0:
|
||||
if self.directory:
|
||||
comic_path = urlsafe_base64_encode(self.directory.selector.bytes)
|
||||
comic_path = urlsafe_base64_encode(self.directory.selector.bytes), type(self.directory).__name__
|
||||
else:
|
||||
comic_path = ""
|
||||
comic_path = "", None
|
||||
else:
|
||||
prev_comic = dir_list[comic_index - 1]
|
||||
|
||||
if Path(folder, prev_comic).is_dir():
|
||||
if self.directory:
|
||||
comic_path = urlsafe_base64_encode(self.directory.selector.bytes)
|
||||
comic_path = urlsafe_base64_encode(self.directory.selector.bytes), type(self.directory).__name__
|
||||
else:
|
||||
comic_path = ""
|
||||
comic_path = "", None
|
||||
else:
|
||||
try:
|
||||
if self.directory:
|
||||
@@ -281,7 +285,7 @@ class ComicBook(models.Model):
|
||||
else:
|
||||
book = ComicBook.process_comic_book(Path(prev_comic))
|
||||
cs, _ = ComicStatus.objects.get_or_create(comic=book, user=user)
|
||||
comic_path = urlsafe_base64_encode(book.selector.bytes)
|
||||
comic_path = urlsafe_base64_encode(book.selector.bytes), type(book).__name__
|
||||
|
||||
return comic_path
|
||||
|
||||
@@ -315,12 +319,12 @@ class ComicBook(models.Model):
|
||||
books.delete()
|
||||
if type(book) is str:
|
||||
raise IndexError
|
||||
comic_path = urlsafe_base64_encode(book.selector.bytes)
|
||||
comic_path = urlsafe_base64_encode(book.selector.bytes), type(book).__name__
|
||||
except IndexError:
|
||||
if self.directory:
|
||||
comic_path = urlsafe_base64_encode(self.directory.selector.bytes)
|
||||
comic_path = urlsafe_base64_encode(self.directory.selector.bytes), type(self.directory).__name__
|
||||
else:
|
||||
comic_path = ""
|
||||
comic_path = "", None
|
||||
return comic_path
|
||||
|
||||
class DirFile:
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
{% load bootstrap4 %}
|
||||
{% load static %}
|
||||
{% load sri %}
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
@@ -17,12 +18,8 @@
|
||||
{% bootstrap_css %}
|
||||
<link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/v/bs4/dt-1.10.21/b-1.6.2/b-colvis-1.6.2/r-2.2.4/datatables.min.css"/>
|
||||
<!-- Custom styles for this template -->
|
||||
<link href="{% static "css/base.min.css" %}" rel="stylesheet">
|
||||
<link href="{% static "font-awesome/css/all.css" %}" rel="stylesheet">
|
||||
|
||||
{# <link href="{% static "reveal.js/css/reveal.css" %}" rel="stylesheet">#}
|
||||
{# <link href="{% static "reveal.js/css/theme/white.css" %}" rel="stylesheet">#}
|
||||
|
||||
{% sri_static "css/base.min.css" %}
|
||||
{% sri_static "font-awesome/css/all.css" %}
|
||||
|
||||
</head>
|
||||
|
||||
@@ -64,12 +61,12 @@
|
||||
================================================== -->
|
||||
<!-- Placed at the end of the document so the pages load faster -->
|
||||
{% bootstrap_javascript jquery='full' %}
|
||||
<script type="text/javascript" src="https://cdn.datatables.net/v/bs4/dt-1.10.21/b-1.6.2/b-colvis-1.6.2/r-2.2.4/datatables.min.js"></script>
|
||||
<script type="text/javascript" src="{% static "js/js.cookie.js" %}"></script>
|
||||
<script type="text/javascript" src="{% static "reveal.js/reveal.js" %}"></script>
|
||||
<script type="text/javascript" src="{% static "reveal.js/plugin/menu/menu.js" %}"></script>
|
||||
<script type="text/javascript" src="{% static "js/hammer.min.js" %}"></script>
|
||||
<script type="text/javascript" src="{% static "js/isotope.pkgd.min.js" %}"></script>
|
||||
<script src="https://cdn.datatables.net/v/bs4/dt-1.10.21/b-1.6.2/b-colvis-1.6.2/r-2.2.4/datatables.min.js" integrity="sha384-P3iGLDP5TXhDKfLfR7rtqmxJ8IqQE6m4zOeFjT7Nnt3scS9VMDJ88XVSnG+yrM4e" crossorigin="anonymous"></script>
|
||||
{% sri_static "js/js.cookie.js" %}
|
||||
{% sri_static "reveal.js/reveal.js" %}
|
||||
{% sri_static "reveal.js/plugin/menu/menu.js" %}
|
||||
{% sri_static "js/hammer.min.js" %}
|
||||
{% sri_static "js/isotope.pkgd.min.js" %}
|
||||
|
||||
{% block script %}
|
||||
{% endblock %}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
{% extends "base.html" %}
|
||||
{% load sri %}
|
||||
{% load bootstrap4 %}
|
||||
{% load static %}
|
||||
{% block title %}{{ title }}{% endblock %}
|
||||
@@ -119,5 +120,5 @@
|
||||
|
||||
{% block script %}
|
||||
{{ js_urls|json_script:'js_urls' }}
|
||||
<script type="text/javascript" src="{% static "js/comic_list.min.js" %}"></script>
|
||||
{% sri_static "js/comic_list.min.js" %}
|
||||
{% endblock %}
|
||||
@@ -1,4 +1,5 @@
|
||||
{% extends "base.html" %}
|
||||
{% load sri %}
|
||||
{% load static %}
|
||||
{% block title %}{{ title }}{% endblock %}
|
||||
|
||||
@@ -24,5 +25,5 @@
|
||||
{% block script %}
|
||||
{{ nav|json_script:"nav" }}
|
||||
{{ status.last_read_page|json_script:"last_read_page" }}
|
||||
<script type="text/javascript" src="{% static "js/read_comic.min.js" %}"></script>
|
||||
{% sri_static "js/read_comic.min.js" %}
|
||||
{% endblock %}
|
||||
@@ -1,4 +1,5 @@
|
||||
{% extends "base.html" %}
|
||||
{% load sri %}
|
||||
{% load static %}
|
||||
{% block title %}{{ title }}{% endblock %}
|
||||
|
||||
@@ -23,8 +24,8 @@
|
||||
{% endblock %}
|
||||
|
||||
{% block script %}
|
||||
<script type="text/javascript" src="{% static "pdfjs/build/pdf.js" %}"></script>
|
||||
{% sri_static "pdfjs/build/pdf.js" %}
|
||||
{{ nav|json_script:"nav" }}
|
||||
{{ status.last_read_page|json_script:"last_read_page" }}
|
||||
<script type="text/javascript" src="{% static 'js/read_comic_pdf.min.js' %}"></script>
|
||||
{% sri_static 'js/read_comic_pdf.min.js' %}
|
||||
{% endblock %}
|
||||
@@ -1,4 +1,5 @@
|
||||
{% extends "base.html" %}
|
||||
{% load sri %}
|
||||
{% load static %}
|
||||
{% block title %}{{ title }}{% endblock %}
|
||||
|
||||
@@ -41,5 +42,5 @@
|
||||
{% endblock %}
|
||||
|
||||
{% block script %}
|
||||
<script type="text/javascript" src="{% static "js/recent_comics.min.js" %}"></script>
|
||||
{% sri_static "js/recent_comics.min.js" %}
|
||||
{% endblock %}
|
||||
@@ -4,7 +4,7 @@ import uuid
|
||||
from django.contrib.auth import authenticate, login
|
||||
from django.contrib.auth.decorators import login_required, user_passes_test
|
||||
from django.contrib.auth.models import User
|
||||
from django.db.models import Max, Count, F
|
||||
from django.db.models import Max, Count, F, Case, When, BooleanField, PositiveSmallIntegerField
|
||||
from django.db.transaction import atomic
|
||||
from django.http import HttpResponse, FileResponse
|
||||
from django.shortcuts import get_object_or_404, redirect, render
|
||||
@@ -135,11 +135,18 @@ def recent_comics_json(request):
|
||||
else:
|
||||
order_string += "date_added"
|
||||
comics = comics.order_by(order_string)
|
||||
comics = comics.filter(comicstatus__user=request.user).annotate(
|
||||
unread=F('comicstatus__unread'),
|
||||
finished=F('comicstatus__finished'),
|
||||
last_read_page=F('comicstatus__last_read_page')
|
||||
comics = comics.annotate(
|
||||
unread=Case(When(comicstatus__user=request.user, then='comicstatus__unread')),
|
||||
finished=Case(When(comicstatus__user=request.user, then='comicstatus__finished')),
|
||||
last_read_page=Case(When(comicstatus__user=request.user, then='comicstatus__last_read_page')),
|
||||
classification=Case(
|
||||
When(directory__isnull=True, then=Directory.Classification.C_18),
|
||||
default=F('directory__classification'),
|
||||
output_field=PositiveSmallIntegerField(choices=Directory.Classification.choices)
|
||||
)
|
||||
)
|
||||
comics = comics.filter(classification__lte=request.user.usermisc.allowed_to_read)
|
||||
|
||||
response_data["recordsFiltered"] = comics.count()
|
||||
response_data["data"] = list()
|
||||
for book in comics[start:end]:
|
||||
@@ -292,6 +299,7 @@ def read_comic(request, comic_selector):
|
||||
|
||||
status, _ = ComicStatus.objects.get_or_create(comic=book, user=request.user)
|
||||
title = "CBWebReader - " + book.file_name
|
||||
print(book.nav(request.user))
|
||||
context = {
|
||||
"book": book,
|
||||
"pages": pages,
|
||||
|
||||
Reference in New Issue
Block a user