mirror of
https://github.com/ajurna/cbwebreader.git
synced 2025-12-06 06:17:17 +00:00
added labels to comic list.
This commit is contained in:
20
comic/migrations/0004_comicbook_unread.py
Normal file
20
comic/migrations/0004_comicbook_unread.py
Normal file
@@ -0,0 +1,20 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.db import models, migrations
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('comic', '0003_comicbook_comicpage'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='comicbook',
|
||||
name='unread',
|
||||
field=models.BooleanField(default=True),
|
||||
preserve_default=False,
|
||||
),
|
||||
]
|
||||
@@ -1,9 +1,6 @@
|
||||
from django.db import models
|
||||
from django.db.models import Max
|
||||
from django.utils.http import urlsafe_base64_encode, urlsafe_base64_decode
|
||||
|
||||
|
||||
|
||||
from unrar import rarfile
|
||||
import zipfile
|
||||
from os import path
|
||||
@@ -24,6 +21,7 @@ class Setting(models.Model):
|
||||
class ComicBook(models.Model):
|
||||
file_name = models.CharField(max_length=100, unique=True)
|
||||
last_read_page = models.IntegerField()
|
||||
unread = models.BooleanField()
|
||||
|
||||
def __str__(self):
|
||||
return self.file_name
|
||||
@@ -40,11 +38,15 @@ class ComicBook(models.Model):
|
||||
return out
|
||||
|
||||
def is_last_page(self, page):
|
||||
page_count = ComicPage.objects.filter(Comic=self).count()
|
||||
if (page_count - 1) == page:
|
||||
if (self.page_count - 1) == page:
|
||||
return True
|
||||
return False
|
||||
|
||||
@property
|
||||
def page_count(self):
|
||||
page_count = ComicPage.objects.filter(Comic=self).count()
|
||||
return page_count
|
||||
|
||||
class Navigation:
|
||||
def __init__(self):
|
||||
self.next_index = 0
|
||||
@@ -93,8 +95,6 @@ class ComicBook(models.Model):
|
||||
prev_comic = dir_list[comic_index - 1]
|
||||
comic_path = path.join(directory, prev_comic)
|
||||
if not path.isdir(path.join(base_dir, prev_comic)):
|
||||
print path.join(base_dir, prev_comic)
|
||||
print path.join(base_dir, prev_comic)
|
||||
try:
|
||||
book = ComicBook.objects.get(file_name=prev_comic)
|
||||
except ComicBook.DoesNotExist:
|
||||
@@ -133,7 +133,8 @@ class ComicBook(models.Model):
|
||||
return False
|
||||
|
||||
book = ComicBook(file_name=comic_file_name,
|
||||
last_read_page=0)
|
||||
last_read_page=0,
|
||||
unread=True)
|
||||
book.save()
|
||||
i = 0
|
||||
for f in sorted([str(x) for x in cbx.namelist()], key=str.lower):
|
||||
|
||||
@@ -16,10 +16,10 @@
|
||||
{% if file_list %}
|
||||
{% for file in file_list %}
|
||||
{% if file.isdir %}
|
||||
<a href="/comic/{{ file.location }}/" class="glyphicon {{ file.icon }} list-group-item"> {{ file }}</a>
|
||||
<a href="/comic/{{ file.location }}/" class="glyphicon {{ file.icon }} list-group-item"> {{ file }}{{ file.label | safe }}</a>
|
||||
{% endif %}
|
||||
{% if file.iscb %}
|
||||
<a href="/comic/read/{{ file.location }}/0/" class="glyphicon {{ file.icon }} list-group-item"> {{ file }}</a>
|
||||
<a href="/comic/read/{{ file.location }}/{{ file.cur_page }}/" class="glyphicon {{ file.icon }} list-group-item"> {{ file }}{{ file.label | safe }}</a>
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
{% else %}
|
||||
|
||||
@@ -1,4 +1,7 @@
|
||||
from django.utils.http import urlsafe_base64_encode
|
||||
|
||||
from comic.models import ComicBook
|
||||
|
||||
from os import path
|
||||
import os
|
||||
|
||||
@@ -39,6 +42,8 @@ class DirFile:
|
||||
self.icon = ''
|
||||
self.iscb = False
|
||||
self.location = ''
|
||||
self.label = ''
|
||||
self.cur_page = 0
|
||||
|
||||
def __str__(self):
|
||||
return self.name
|
||||
@@ -57,5 +62,17 @@ def generate_directory(base_dir, comic_path):
|
||||
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
|
||||
|
||||
@@ -31,6 +31,7 @@ def read_comic(request, comic_path, page):
|
||||
book = ComicBook.objects.get(file_name=comic_file_name)
|
||||
except ComicBook.DoesNotExist:
|
||||
book = ComicBook.process_comic_book(base_dir, decoded_path, comic_file_name)
|
||||
book.unread = False
|
||||
book.last_read_page = page
|
||||
book.save()
|
||||
context = RequestContext(request, {
|
||||
|
||||
Reference in New Issue
Block a user