diff --git a/comic/migrations/0004_comicbook_unread.py b/comic/migrations/0004_comicbook_unread.py
new file mode 100644
index 0000000..83b68ab
--- /dev/null
+++ b/comic/migrations/0004_comicbook_unread.py
@@ -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,
+ ),
+ ]
diff --git a/comic/models.py b/comic/models.py
index db320ca..ec4ee92 100644
--- a/comic/models.py
+++ b/comic/models.py
@@ -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):
diff --git a/comic/templates/comic/comic_list.html b/comic/templates/comic/comic_list.html
index 731f0fe..17a8a1e 100644
--- a/comic/templates/comic/comic_list.html
+++ b/comic/templates/comic/comic_list.html
@@ -16,10 +16,10 @@
{% if file_list %}
{% for file in file_list %}
{% if file.isdir %}
- {{ file }}
+ {{ file }}{{ file.label | safe }}
{% endif %}
{% if file.iscb %}
- {{ file }}
+ {{ file }}{{ file.label | safe }}
{% endif %}
{% endfor %}
{% else %}
diff --git a/comic/util.py b/comic/util.py
index 7d5473a..4c8bcd2 100644
--- a/comic/util.py
+++ b/comic/util.py
@@ -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 = 'Unread'
+ else:
+ last_page = book.last_read_page
+ label_text = '%s/%s' % \
+ (last_page, book.page_count)
+ df.label = label_text
+ df.cur_page = last_page
+ except ComicBook.DoesNotExist:
+ df.label = 'Unprocessed'
files.append(df)
return files
diff --git a/comic/views.py b/comic/views.py
index bca7982..d346c46 100644
--- a/comic/views.py
+++ b/comic/views.py
@@ -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, {