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 = '