diff --git a/comic/admin.py b/comic/admin.py
index 38c30ea..073e4a9 100644
--- a/comic/admin.py
+++ b/comic/admin.py
@@ -4,4 +4,5 @@ from comic.models import Setting
# Register your models here.
@admin.register(Setting)
class SettingAdmin(admin.ModelAdmin):
- list_display = ('name', 'value')
\ No newline at end of file
+ list_display = ('name', 'value')
+
diff --git a/comic/models.py b/comic/models.py
index 7962ae6..55f4e9e 100644
--- a/comic/models.py
+++ b/comic/models.py
@@ -9,3 +9,13 @@ class Setting(models.Model):
def __str__(self):
return '"%s":"%s"' % (self.name, self.value)
+
+class ComicBook(models.Model):
+ file_name = models.CharField(max_length=100, unique=True)
+ last_read_page = models.IntegerField()
+
+class ComicPage(models.Model):
+ Comic = models.ForeignKey(ComicBook)
+ index = models.IntegerField()
+ page_file_name = models.CharField(max_length=100, unique=False)
+ content_type = models.CharField(max_length=30)
diff --git a/comic/static/css/base.css b/comic/static/css/base.css
index 0691eab..dcd51b7 100644
--- a/comic/static/css/base.css
+++ b/comic/static/css/base.css
@@ -4,4 +4,29 @@ body {
.starter-template {
padding: 40px 15px;
text-align: center;
-}
\ No newline at end of file
+}
+/* Sticky footer styles
+-------------------------------------------------- */
+html {
+ position: relative;
+ min-height: 100%;
+}
+body {
+ /* Margin bottom by footer height */
+ margin-bottom: 60px;
+}
+.footer {
+ position: absolute;
+ bottom: 0;
+ width: 100%;
+ /* Set the fixed height of the footer here */
+ height: 60px;
+ background-color: #f5f5f5;
+}
+
+
+#dropdown-list{
+ max-height: 300px;
+ overflow: auto;
+ box-shadow: none;
+ }
\ No newline at end of file
diff --git a/comic/templates/base.html b/comic/templates/base.html
index 131495d..f631ed2 100644
--- a/comic/templates/base.html
+++ b/comic/templates/base.html
@@ -1,4 +1,3 @@
-
@@ -43,7 +42,7 @@
@@ -61,14 +60,18 @@
{% block content %}{% endblock %}
-
-
+
+
-
+
diff --git a/comic/templates/comic/index.html b/comic/templates/comic/index.html
index f028242..731f0fe 100644
--- a/comic/templates/comic/index.html
+++ b/comic/templates/comic/index.html
@@ -1,9 +1,13 @@
{% extends "base.html" %}
-{% block title %}My amazing blog{% endblock %}
+{% block title %}CBreader{% endblock %}
{% block breadcrumb %}
{% for crumb in breadcrumbs %}
- {{ crumb.name }}
+ {% if not forloop.last %}
+ {{ crumb.name }}
+ {% else %}
+ {{ crumb.name }}
+ {% endif %}
{% endfor %}
{% endblock %}
{% block content %}
diff --git a/comic/templates/comic/read_comic.html b/comic/templates/comic/read_comic.html
index bf0bfdf..03740fd 100644
--- a/comic/templates/comic/read_comic.html
+++ b/comic/templates/comic/read_comic.html
@@ -1,22 +1,35 @@
{% extends "base.html" %}
+{% block breadcrumb %}
+ {% for crumb in breadcrumbs %}
+ {% if not forloop.last %}
+ {{ crumb.name }}
+ {% else %}
+ {{ crumb.name }}
+ {% endif %}
+ {% endfor %}
+{% endblock %}
{% block content %}
-
+
-
-Prev
-{% if pages %}
-
-{% else %}
- No comics.
-{% endif %}
-Next
+
+
Prev
+ {% if pages %}
+
+
+
+
+ {% else %}
+
No comics.
+ {% endif %}
+
Next
+
{% endblock %}
\ No newline at end of file
diff --git a/comic/util.py b/comic/util.py
new file mode 100644
index 0000000..a6aba16
--- /dev/null
+++ b/comic/util.py
@@ -0,0 +1,55 @@
+from django.utils.http import urlsafe_base64_encode
+from os import path
+import os
+
+
+class Breadcrumb:
+ def __init__(self):
+ self.name = 'Home'
+ self.url = '/comic/'
+
+ def __str__(self):
+ return self.name
+
+class DirFile:
+ def __init__(self):
+ self.name = ''
+ self.isdir = False
+ self.icon = ''
+ self.iscb = False
+ self.location = ''
+
+ def __str__(self):
+ return self.name
+
+def generate_breadcrumbs(comic_path):
+ output = [Breadcrumb()]
+ prefix = '/comic/'
+ last = ''
+ comic_path = path.normpath(comic_path)
+ folders = comic_path.split(os.sep)
+ for item in folders:
+ if item == '.':
+ continue
+ bc = Breadcrumb()
+ bc.name = item
+ bc.url = prefix + urlsafe_base64_encode(item)
+ output.append(bc)
+ last = path.join(last, item)
+ return output
+
+def generate_directory(base_dir, comic_path):
+ files = []
+ for fn in os.listdir(path.join(base_dir.value, comic_path)):
+ df = DirFile()
+ df.name = fn
+ if path.isdir(path.join(base_dir.value, 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))
+ files.append(df)
+ return files
\ No newline at end of file
diff --git a/comic/views.py b/comic/views.py
index bdc3431..3370fda 100644
--- a/comic/views.py
+++ b/comic/views.py
@@ -1,12 +1,13 @@
from django.http import HttpResponse
from django.template import RequestContext, loader
-from django.utils.http import urlsafe_base64_decode, urlsafe_base64_encode
+from django.utils.http import urlsafe_base64_decode
+from django.shortcuts import render
from comic.models import Setting
+from util import generate_breadcrumbs, generate_directory
from unrar import rarfile
from zipfile import ZipFile
-import os
from os import path
class Comic:
@@ -18,52 +19,24 @@ class Navigation:
self.next = 0
self.prev = 0
self.cur = 0
-class DirFile:
- def __init__(self):
- self.name = ''
- self.isdir = False
- self.icon = ''
- self.iscb = False
- self.location = ''
- def __str__(self):
- return self.name
-
-
-# Create your views here.
def index(request, comic_path=''):
base_dir = Setting.objects.get(name='BASE_DIR')
comic_path = urlsafe_base64_decode(comic_path)
breadcrumbs = generate_breadcrumbs(comic_path)
-
-
- #list and classify files
- files = []
- for fn in os.listdir(path.join(base_dir.value, comic_path)):
- df = DirFile()
- df.name = fn
- if path.isdir(path.join(base_dir.value, 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))
- files.append(df)
- template = loader.get_template('comic/index.html')
+ files = generate_directory(base_dir, comic_path)
context = RequestContext(request, {
'file_list': files,
'breadcrumbs': breadcrumbs,
})
- return HttpResponse(template.render(context))
+ return render(request, 'comic/index.html', context)
def read_comic(request, comic_path, page):
encoded = comic_path
comic_path = urlsafe_base64_decode(comic_path)
+ breadcrumbs = generate_breadcrumbs(comic_path)
base_dir = Setting.objects.get(name='BASE_DIR')
- template = loader.get_template('comic/read_comic.html')
if comic_path.lower().endswith('cbr'):
cbx = rarfile.RarFile(path.join(base_dir.value, comic_path))
elif comic_path.lower().endswith('cbz'):
@@ -79,13 +52,15 @@ def read_comic(request, comic_path, page):
comic.name = name
comic.index = idx
pages.append(comic)
-
context = RequestContext(request, {
'pages': pages,
'file_name': encoded,
+ 'orig_file_name': pages[nav.cur].name,
'nav': nav,
+ 'breadcrumbs': breadcrumbs,
})
- return HttpResponse(template.render(context))
+ return render(request, 'comic/read_comic.html', context)
+
def get_image(request, comic_path, page):
base_dir = Setting.objects.get(name='BASE_DIR')
@@ -113,25 +88,4 @@ def get_image(request, comic_path, page):
img = cbx.open(page_file)
return HttpResponse(img.read(), content_type=content)
-class Breadcrumb:
- def __init__(self):
- self.name = 'Home'
- self.url = '/comic/'
- def __str__(self):
- return self.name
-def generate_breadcrumbs(comic_path):
- output = [Breadcrumb()]
- prefix = '/comic/'
- last = ''
- comic_path = path.normpath(comic_path)
- folders = comic_path.split(os.sep)
- for item in folders:
- if item == '.':
- continue
- bc = Breadcrumb()
- bc.name = item
- bc.url = prefix + urlsafe_base64_encode(item)
- output.append(bc)
- last = path.join(last, item)
- return output
\ No newline at end of file