Commit 562d7304 authored by Dmitry Shelepnev's avatar Dmitry Shelepnev
Browse files

Fix processfile: now novalid book not added in Database

parent 62b5352a
Loading
Loading
Loading
Loading
+63 −57
Original line number Diff line number Diff line
@@ -32,6 +32,7 @@ class opdsScanner:
        self.arch_scanned = 0
        self.arch_skipped = 0
        self.bad_archives = 0
        self.bad_books = 0
        self.books_in_archives = 0

    def init_parser(self):
@@ -49,6 +50,7 @@ class opdsScanner:
        self.t2=datetime.timedelta(seconds=time.time())
        self.logger.info('Books added      : '+str(self.books_added))
        self.logger.info('Books skipped    : '+str(self.books_skipped))
        self.logger.info('Bad books        : '+str(self.bad_books))
        if settings.DELETE_LOGICAL:
            self.logger.info('Books deleted    : '+str(self.books_deleted))
        else:
@@ -147,6 +149,7 @@ class opdsScanner:
                lang=''
                annotation=''
                docdate=''
                book_is_valid = True

                if e.lower()=='.fb2' and settings.FB2PARSE:
                    if isinstance(file, str):
@@ -168,7 +171,10 @@ class opdsScanner:
                    if self.fb2parser.parse_error!=0:
                        errormsg=''
                        self.logger.warning(rel_path+' - '+name+' fb2 parse error ['+errormsg+']')
                        book_is_valid = False
                        self.bad_books+=1

                if book_is_valid:
                   if title=='': title=n

                   book=opdsdb.addbook(name,rel_path,cat,e,title,annotation,docdate,lang,file_size,archive)
+1 −0
Original line number Diff line number Diff line
This not fb2 file for tests
+1 −0
Original line number Diff line number Diff line
@@ -96,6 +96,7 @@ class scanTestCase(TestCase):
        scanner = opdsScanner()
        scanner.scan_all()
        self.assertEquals(scanner.books_added, 4)
        self.assertEquals(scanner.bad_books, 1)
        self.assertEquals(Book.objects.all().count(), 4)
        self.assertEquals(Author.objects.all().count(), 4)
        self.assertEquals(Genre.objects.all().count(), 4)