From c330c6812b96f5d35a4d9b0ab1c55e0afd2d33bd Mon Sep 17 00:00:00 2001 From: Ajurna Date: Wed, 22 Nov 2017 15:56:39 +0000 Subject: [PATCH] fix for issue #2. --- comic/models.py | 12 ++++++--- comic/templates/comic/comic_list.html | 35 +++++++++++++++------------ comic/util.py | 28 +++++++++++++-------- comic_auth/forms.py | 5 ++-- requirements.txt | 3 ++- 5 files changed, 52 insertions(+), 31 deletions(-) diff --git a/comic/models.py b/comic/models.py index c8bdced..33af92a 100644 --- a/comic/models.py +++ b/comic/models.py @@ -203,6 +203,8 @@ class ComicBook(models.Model): book = ComicBook.process_comic_book(next_comic, self.directory) else: book = ComicBook.process_comic_book(next_comic) + if type(book) is str: + raise IndexError comic_path = urlsafe_base64_encode(book.selector.bytes) cs, _ = ComicStatus.objects.get_or_create(comic=book, user=user) index = cs.last_read_page @@ -258,12 +260,16 @@ class ComicBook(models.Model): comic_full_path = path.join(base_dir, directory.get_path(), comic_file_name) else: comic_full_path = path.join(base_dir, comic_file_name) + try: cbx = rarfile.RarFile(comic_full_path) except rarfile.NotRarFile: - cbx = zipfile.ZipFile(comic_full_path) - except zipfile.BadZipfile: - return False + cbx = None + if not cbx: + try: + cbx = zipfile.ZipFile(comic_full_path) + except zipfile.BadZipFile: + return comic_file_name with atomic(): if directory: book = ComicBook(file_name=comic_file_name, diff --git a/comic/templates/comic/comic_list.html b/comic/templates/comic/comic_list.html index f308b4b..851b8e3 100644 --- a/comic/templates/comic/comic_list.html +++ b/comic/templates/comic/comic_list.html @@ -46,18 +46,23 @@ $(document).ready(function() { "url": "{{ json_url }}", "data": function ( d ) { d.csrfmiddlewaretoken = Cookies.get('csrftoken'); - }, + } }, "rowCallback": function( row, data, index ) { var r = $(row); var cols = $('td:nth-child(n+2)', row); - cols.attr('data-href', data['url']); - cols.attr('style', 'cursor: pointer;') - cols.click(function() { - window.document.location = $(this).data("href"); - }); + + if (data['selector'] === '0') { + + } else { + cols.attr('data-href', data['url']); + cols.attr('style', 'cursor: pointer;'); + cols.click(function () { + window.document.location = $(this).data("href"); + }); + } var tds = $('td:eq(0)', row); - if (data['type'] == 'directory'){ + if (data['type'] === 'directory') { tds.html(''); } else { tds.html(''); @@ -65,25 +70,25 @@ $(document).ready(function() { cb.change(function() { $(this).closest('tr').toggleClass('info') }); - }; + } }, "drawCallback": function( settings ) { var tds = $('table tr td:first-child'); tds.click(function(event){ if (!$(event.target).is('input')) { - var $cb = $('input', this) + var $cb = $('input', this); $cb.click(); - }; + } }); }, "columns": [ { "data" : "blank", "orderable": false }, { "data" : "icon", "orderable": false }, { "data" : "name" }, - { "data" : "label" }, + {"data": "label"} ], - "order": [[ 2, 'asc' ]], + "order": [[2, 'asc']] }); $(".clickable-row").click(function() { window.document.location = $(this).data("href"); @@ -100,12 +105,12 @@ $(document).ready(function() { }); $('#select-all').click(function(event){ - var cb = $('input', this) + var cb = $('input', this); if (!$(event.target).is('input')) { cb.click(); - }; + } $('table tr td:first-child input').each(function(chkbx) { - row = $(this) + row = $(this); if (row.prop('checked') != cb.prop('checked')){ row.click(); } diff --git a/comic/util.py b/comic/util.py index 099596b..ccf118e 100644 --- a/comic/util.py +++ b/comic/util.py @@ -98,16 +98,24 @@ class DirFile: self.type = 'directory' def populate_comic(self, comic, user): - self.icon = 'glyphicon-book' - self.name = comic.file_name - status, created = ComicStatus.objects.get_or_create(comic=comic, user=user) - if created: - status.save() - self.selector = urlsafe_base64_encode(comic.selector.bytes).decode() - self.location = '/comic/read/{0}/{1}/'.format(self.selector, - status.last_read_page) - self.label = generate_label(comic, status) - self.type = 'book' + if type(comic) == str: + self.icon = 'glyphicon-remove' + self.name = comic + self.selector = '0' + self.location = '/' + self.label = '
Error
' + self.type = 'book' + else: + self.icon = 'glyphicon-book' + self.name = comic.file_name + status, created = ComicStatus.objects.get_or_create(comic=comic, user=user) + if created: + status.save() + self.selector = urlsafe_base64_encode(comic.selector.bytes).decode() + self.location = '/comic/read/{0}/{1}/'.format(self.selector, + status.last_read_page) + self.label = generate_label(comic, status) + self.type = 'book' def generate_directory(user, directory=False): diff --git a/comic_auth/forms.py b/comic_auth/forms.py index 6228970..c98c360 100644 --- a/comic_auth/forms.py +++ b/comic_auth/forms.py @@ -1,5 +1,6 @@ +from captcha.fields import CaptchaField from django import forms -from captcha.fields import ReCaptchaField + from comic.models import Setting @@ -33,7 +34,7 @@ class LoginForm(forms.Form): public_key = Setting.objects.get(name='RECAPTCHA_PUBLIC_KEY').value private_key = Setting.objects.get(name='RECAPTCHA_PRIVATE_KEY').value - captcha = ReCaptchaField( + captcha = CaptchaField( label='', public_key=public_key, private_key=private_key, diff --git a/requirements.txt b/requirements.txt index 18cd6b7..1b52458 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,2 +1,3 @@ ujson -django \ No newline at end of file +django +django-simple-captcha \ No newline at end of file