added labels to comic list.

This commit is contained in:
2015-06-19 13:32:07 +01:00
parent 654af1f402
commit e6791bf41a
5 changed files with 49 additions and 10 deletions

View File

@@ -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