mirror of
https://github.com/ajurna/cbwebreader.git
synced 2025-12-06 14:17:19 +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 import models
|
||||||
from django.db.models import Max
|
|
||||||
from django.utils.http import urlsafe_base64_encode, urlsafe_base64_decode
|
from django.utils.http import urlsafe_base64_encode, urlsafe_base64_decode
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
from unrar import rarfile
|
from unrar import rarfile
|
||||||
import zipfile
|
import zipfile
|
||||||
from os import path
|
from os import path
|
||||||
@@ -24,6 +21,7 @@ class Setting(models.Model):
|
|||||||
class ComicBook(models.Model):
|
class ComicBook(models.Model):
|
||||||
file_name = models.CharField(max_length=100, unique=True)
|
file_name = models.CharField(max_length=100, unique=True)
|
||||||
last_read_page = models.IntegerField()
|
last_read_page = models.IntegerField()
|
||||||
|
unread = models.BooleanField()
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return self.file_name
|
return self.file_name
|
||||||
@@ -40,11 +38,15 @@ class ComicBook(models.Model):
|
|||||||
return out
|
return out
|
||||||
|
|
||||||
def is_last_page(self, page):
|
def is_last_page(self, page):
|
||||||
page_count = ComicPage.objects.filter(Comic=self).count()
|
if (self.page_count - 1) == page:
|
||||||
if (page_count - 1) == page:
|
|
||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
@property
|
||||||
|
def page_count(self):
|
||||||
|
page_count = ComicPage.objects.filter(Comic=self).count()
|
||||||
|
return page_count
|
||||||
|
|
||||||
class Navigation:
|
class Navigation:
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.next_index = 0
|
self.next_index = 0
|
||||||
@@ -93,8 +95,6 @@ class ComicBook(models.Model):
|
|||||||
prev_comic = dir_list[comic_index - 1]
|
prev_comic = dir_list[comic_index - 1]
|
||||||
comic_path = path.join(directory, prev_comic)
|
comic_path = path.join(directory, prev_comic)
|
||||||
if not path.isdir(path.join(base_dir, 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:
|
try:
|
||||||
book = ComicBook.objects.get(file_name=prev_comic)
|
book = ComicBook.objects.get(file_name=prev_comic)
|
||||||
except ComicBook.DoesNotExist:
|
except ComicBook.DoesNotExist:
|
||||||
@@ -133,7 +133,8 @@ class ComicBook(models.Model):
|
|||||||
return False
|
return False
|
||||||
|
|
||||||
book = ComicBook(file_name=comic_file_name,
|
book = ComicBook(file_name=comic_file_name,
|
||||||
last_read_page=0)
|
last_read_page=0,
|
||||||
|
unread=True)
|
||||||
book.save()
|
book.save()
|
||||||
i = 0
|
i = 0
|
||||||
for f in sorted([str(x) for x in cbx.namelist()], key=str.lower):
|
for f in sorted([str(x) for x in cbx.namelist()], key=str.lower):
|
||||||
|
|||||||
@@ -16,10 +16,10 @@
|
|||||||
{% if file_list %}
|
{% if file_list %}
|
||||||
{% for file in file_list %}
|
{% for file in file_list %}
|
||||||
{% if file.isdir %}
|
{% 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 %}
|
{% endif %}
|
||||||
{% if file.iscb %}
|
{% 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 %}
|
{% endif %}
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
{% else %}
|
{% else %}
|
||||||
|
|||||||
@@ -1,4 +1,7 @@
|
|||||||
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
|
||||||
|
|
||||||
@@ -39,6 +42,8 @@ class DirFile:
|
|||||||
self.icon = ''
|
self.icon = ''
|
||||||
self.iscb = False
|
self.iscb = False
|
||||||
self.location = ''
|
self.location = ''
|
||||||
|
self.label = ''
|
||||||
|
self.cur_page = 0
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return self.name
|
return self.name
|
||||||
@@ -57,5 +62,17 @@ def generate_directory(base_dir, comic_path):
|
|||||||
df.iscb = True
|
df.iscb = True
|
||||||
df.icon = 'glyphicon-book'
|
df.icon = 'glyphicon-book'
|
||||||
df.location = urlsafe_base64_encode(path.join(comic_path, fn))
|
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)
|
files.append(df)
|
||||||
return files
|
return files
|
||||||
|
|||||||
@@ -31,6 +31,7 @@ def read_comic(request, comic_path, page):
|
|||||||
book = ComicBook.objects.get(file_name=comic_file_name)
|
book = ComicBook.objects.get(file_name=comic_file_name)
|
||||||
except ComicBook.DoesNotExist:
|
except ComicBook.DoesNotExist:
|
||||||
book = ComicBook.process_comic_book(base_dir, decoded_path, comic_file_name)
|
book = ComicBook.process_comic_book(base_dir, decoded_path, comic_file_name)
|
||||||
|
book.unread = False
|
||||||
book.last_read_page = page
|
book.last_read_page = page
|
||||||
book.save()
|
book.save()
|
||||||
context = RequestContext(request, {
|
context = RequestContext(request, {
|
||||||
|
|||||||
Reference in New Issue
Block a user