mirror of
https://github.com/ajurna/cbwebreader.git
synced 2025-12-06 14:17:19 +00:00
made sorting work in all locations.
This commit is contained in:
@@ -2,6 +2,7 @@ from django.db import models
|
|||||||
from django.utils.http import urlsafe_base64_encode, urlsafe_base64_decode
|
from django.utils.http import urlsafe_base64_encode, urlsafe_base64_decode
|
||||||
|
|
||||||
from comic import rarfile
|
from comic import rarfile
|
||||||
|
from comic.util import get_ordered_dir_list
|
||||||
import zipfile
|
import zipfile
|
||||||
from os import path
|
from os import path
|
||||||
import os
|
import os
|
||||||
@@ -86,7 +87,7 @@ class ComicBook(models.Model):
|
|||||||
base_dir = Setting.objects.get(name='BASE_DIR').value
|
base_dir = Setting.objects.get(name='BASE_DIR').value
|
||||||
comic_path = urlsafe_base64_decode(comic_path)
|
comic_path = urlsafe_base64_decode(comic_path)
|
||||||
directory, comic = path.split(comic_path)
|
directory, comic = path.split(comic_path)
|
||||||
dir_list = os.listdir(path.join(base_dir, directory))
|
dir_list = get_ordered_dir_list(path.join(base_dir, directory))
|
||||||
comic_index = dir_list.index(comic)
|
comic_index = dir_list.index(comic)
|
||||||
if comic_index == 0:
|
if comic_index == 0:
|
||||||
comic_path = urlsafe_base64_encode(directory)
|
comic_path = urlsafe_base64_encode(directory)
|
||||||
@@ -111,7 +112,7 @@ class ComicBook(models.Model):
|
|||||||
base_dir = Setting.objects.get(name='BASE_DIR')
|
base_dir = Setting.objects.get(name='BASE_DIR')
|
||||||
comic_path = urlsafe_base64_decode(comic_path)
|
comic_path = urlsafe_base64_decode(comic_path)
|
||||||
directory, comic = path.split(comic_path)
|
directory, comic = path.split(comic_path)
|
||||||
dir_list = os.listdir(path.join(base_dir.value, directory))
|
dir_list = get_ordered_dir_list(path.join(base_dir.value, directory))
|
||||||
comic_index = dir_list.index(comic)
|
comic_index = dir_list.index(comic)
|
||||||
try:
|
try:
|
||||||
next_comic = dir_list[comic_index + 1]
|
next_comic = dir_list[comic_index + 1]
|
||||||
@@ -167,9 +168,52 @@ class ComicBook(models.Model):
|
|||||||
content_type='image/gif')
|
content_type='image/gif')
|
||||||
page.save()
|
page.save()
|
||||||
i += 1
|
i += 1
|
||||||
|
|
||||||
return book
|
return book
|
||||||
|
|
||||||
|
class DirFile:
|
||||||
|
def __init__(self):
|
||||||
|
self.name = ''
|
||||||
|
self.isdir = False
|
||||||
|
self.icon = ''
|
||||||
|
self.iscb = False
|
||||||
|
self.location = ''
|
||||||
|
self.label = ''
|
||||||
|
self.cur_page = 0
|
||||||
|
|
||||||
|
def __str__(self):
|
||||||
|
return self.name
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def generate_directory(base_dir, comic_path):
|
||||||
|
files = []
|
||||||
|
for fn in get_ordered_dir_list(path.join(base_dir, comic_path)):
|
||||||
|
df = ComicBook.DirFile()
|
||||||
|
df.name = fn
|
||||||
|
if path.isdir(path.join(base_dir, comic_path, fn)):
|
||||||
|
df.isdir = True
|
||||||
|
df.icon = 'glyphicon-folder-open'
|
||||||
|
df.location = urlsafe_base64_encode(path.join(comic_path, fn))
|
||||||
|
elif fn.lower().endswith('cbz') or fn.lower().endswith('cbr'):
|
||||||
|
df.iscb = True
|
||||||
|
df.icon = 'glyphicon-book'
|
||||||
|
df.location = urlsafe_base64_encode(path.join(comic_path, fn))
|
||||||
|
try:
|
||||||
|
book = ComicBook.objects.get(file_name=fn)
|
||||||
|
last_page = book.last_read_page
|
||||||
|
if book.unread:
|
||||||
|
df.label = '<span class="label label-default pull-right">Unread</span>'
|
||||||
|
elif (last_page + 1) == book.page_count:
|
||||||
|
df.label = '<span class="label label-success pull-right">Read</span>'
|
||||||
|
df.cur_page = last_page
|
||||||
|
else:
|
||||||
|
label_text = '<span class="label label-primary pull-right">%s/%s</span>' % \
|
||||||
|
(last_page + 1, book.page_count)
|
||||||
|
df.label = label_text
|
||||||
|
df.cur_page = last_page
|
||||||
|
except ComicBook.DoesNotExist:
|
||||||
|
df.label = '<span class="label label-danger pull-right">Unprocessed</span>'
|
||||||
|
files.append(df)
|
||||||
|
return files
|
||||||
class Comic:
|
class Comic:
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.name = ''
|
self.name = ''
|
||||||
|
|||||||
@@ -1,7 +1,5 @@
|
|||||||
from django.utils.http import urlsafe_base64_encode
|
from django.utils.http import urlsafe_base64_encode
|
||||||
|
|
||||||
from comic.models import ComicBook
|
|
||||||
|
|
||||||
from os import path
|
from os import path
|
||||||
import os
|
import os
|
||||||
|
|
||||||
@@ -35,18 +33,7 @@ def generate_breadcrumbs(comic_path):
|
|||||||
return output
|
return output
|
||||||
|
|
||||||
|
|
||||||
class DirFile:
|
|
||||||
def __init__(self):
|
|
||||||
self.name = ''
|
|
||||||
self.isdir = False
|
|
||||||
self.icon = ''
|
|
||||||
self.iscb = False
|
|
||||||
self.location = ''
|
|
||||||
self.label = ''
|
|
||||||
self.cur_page = 0
|
|
||||||
|
|
||||||
def __str__(self):
|
|
||||||
return self.name
|
|
||||||
|
|
||||||
def get_ordered_dir_list(folder):
|
def get_ordered_dir_list(folder):
|
||||||
directories = []
|
directories = []
|
||||||
@@ -60,30 +47,4 @@ def get_ordered_dir_list(folder):
|
|||||||
print(directories)
|
print(directories)
|
||||||
return sorted(directories) + sorted(files)
|
return sorted(directories) + sorted(files)
|
||||||
|
|
||||||
def generate_directory(base_dir, comic_path):
|
|
||||||
files = []
|
|
||||||
for fn in get_ordered_dir_list(path.join(base_dir, comic_path)):
|
|
||||||
df = DirFile()
|
|
||||||
df.name = fn
|
|
||||||
if path.isdir(path.join(base_dir, comic_path, fn)):
|
|
||||||
df.isdir = True
|
|
||||||
df.icon = 'glyphicon-folder-open'
|
|
||||||
df.location = urlsafe_base64_encode(path.join(comic_path, fn))
|
|
||||||
elif fn.lower().endswith('cbz') or fn.lower().endswith('cbr'):
|
|
||||||
df.iscb = True
|
|
||||||
df.icon = 'glyphicon-book'
|
|
||||||
df.location = urlsafe_base64_encode(path.join(comic_path, fn))
|
|
||||||
try:
|
|
||||||
book = ComicBook.objects.get(file_name=fn)
|
|
||||||
if book.unread:
|
|
||||||
df.label = '<span class="label label-default pull-right">Unread</span>'
|
|
||||||
else:
|
|
||||||
last_page = book.last_read_page
|
|
||||||
label_text = '<span class="label label-primary pull-right">%s/%s</span>' % \
|
|
||||||
(last_page, book.page_count)
|
|
||||||
df.label = label_text
|
|
||||||
df.cur_page = last_page
|
|
||||||
except ComicBook.DoesNotExist:
|
|
||||||
df.label = '<span class="label label-danger pull-right">Unprocessed</span>'
|
|
||||||
files.append(df)
|
|
||||||
return files
|
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ from django.shortcuts import render
|
|||||||
from django.contrib.auth.decorators import login_required
|
from django.contrib.auth.decorators import login_required
|
||||||
|
|
||||||
from comic.models import Setting, ComicBook
|
from comic.models import Setting, ComicBook
|
||||||
from util import generate_breadcrumbs, generate_directory
|
from util import generate_breadcrumbs
|
||||||
|
|
||||||
from os import path
|
from os import path
|
||||||
|
|
||||||
@@ -14,7 +14,7 @@ def comic_list(request, comic_path=''):
|
|||||||
base_dir = Setting.objects.get(name='BASE_DIR').value
|
base_dir = Setting.objects.get(name='BASE_DIR').value
|
||||||
comic_path = urlsafe_base64_decode(comic_path)
|
comic_path = urlsafe_base64_decode(comic_path)
|
||||||
breadcrumbs = generate_breadcrumbs(comic_path)
|
breadcrumbs = generate_breadcrumbs(comic_path)
|
||||||
files = generate_directory(base_dir, comic_path)
|
files = ComicBook.generate_directory(base_dir, comic_path)
|
||||||
context = RequestContext(request, {
|
context = RequestContext(request, {
|
||||||
'file_list': files,
|
'file_list': files,
|
||||||
'breadcrumbs': breadcrumbs,
|
'breadcrumbs': breadcrumbs,
|
||||||
|
|||||||
Reference in New Issue
Block a user