コード例 #1
0
ファイル: bookwarm_server.py プロジェクト: apsz/BookWarm
 def find_book_by_isbn(self, isbn):
     with bookwarm.SQLSession(self._database_path) as session:
         books = session.query(bookwarm.Book).all()
         for book in books:
             if book.isbn == int(isbn):
                 return book
     return False
コード例 #2
0
ファイル: bookwarm_server.py プロジェクト: apsz/BookWarm
 def add_new_collection(self, user, collection_name):
     with bookwarm.SQLSession(self._database_path) as session:
         try:
             new_collection = bookwarm.BookCollection(user, collection_name, [])
             session.add(new_collection)
             session.commit()
             return (True, '')
         except Exception as add_collection_err:
             session.rollback()
             return (False, add_collection_err)
コード例 #3
0
ファイル: bookwarm_server.py プロジェクト: apsz/BookWarm
    def retrieve_book_details(self, isbn):
        book_attrs = ('title', 'author', 'genre', 'no_of_pages',
                      'year_published', 'edition', 'publisher')

        with bookwarm.SQLSession(self._database_path) as session:
            books = session.query(bookwarm.Book).all()
            for book in books:
                if book.isbn == int(isbn):
                    book_data = '\n'.join([str(book.__getattribute__(attr)) for attr in book_attrs])
                    return book_data
        return False
コード例 #4
0
ファイル: bookwarm_server.py プロジェクト: apsz/BookWarm
 def delete_collection(self, collection_name):
     with bookwarm.SQLSession(self._database_path) as session:
         try:
             collections = session.query(bookwarm.BookCollection).all()
             for collection in collections:
                 if collection.collection_name == collection_name:
                     session.delete(collection)
                     session.commit()
             return (True, '')
         except Exception as del_collection_err:
             session.rollback()
             return (False, del_collection_err)
コード例 #5
0
ファイル: bookwarm_server.py プロジェクト: apsz/BookWarm
 def delete_book(self, isbn):
     with bookwarm.SQLSession(self._database_path) as session:
         try:
             books = session.query(bookwarm.Book).all()
             for book in books:
                 if book.isbn == int(isbn):
                     session.delete(book)
                     session.commit()
             self._load_all_available_books()
             return (True, '')
         except Exception as del_book_err:
             session.rollback()
             return (False, del_book_err)
コード例 #6
0
ファイル: bookwarm_server.py プロジェクト: apsz/BookWarm
    def add_new_book(self, book_data):
        with bookwarm.SQLSession(self._database_path) as session:
            try:

                prepared_data = [int(value) if value.isdigit()
                                            else value for value in book_data.split()]
                new_book = bookwarm.Book(*prepared_data)
                session.add(new_book)
                session.commit()
                self._load_all_available_books()
                return (True, '')
            except Exception as add_book_err:
                session.rollback()
                return (False, add_book_err)
コード例 #7
0
ファイル: bookwarm_server.py プロジェクト: apsz/BookWarm
 def update_book(self, isbn, edition, publisher):
     with bookwarm.SQLSession(self._database_path) as session:
         try:
             books = session.query(bookwarm.Book).all()
             for book in books:
                 if book.isbn == int(isbn):
                     if not edition == 'None':
                         book.edition = int(edition)
                     if not publisher == 'None':
                         book.publisher = publisher
                     session.commit()
             self._load_all_available_books()
             return (True, '')
         except Exception as book_upd_err:
             session.rollback()
             return (False, book_upd_err)
コード例 #8
0
ファイル: bookwarm_server.py プロジェクト: apsz/BookWarm
 def get_collection_by_name(self, collection_name):
     with bookwarm.SQLSession(self._database_path) as session:
         return session.query(bookwarm.BookCollection).filter(
             bookwarm.BookCollection.collection_name == collection_name).all()
コード例 #9
0
ファイル: bookwarm_server.py プロジェクト: apsz/BookWarm
 def get_user_collections(self, user):
     with bookwarm.SQLSession(self._database_path) as session:
         return session.query(bookwarm.BookCollection).filter(
             bookwarm.BookCollection.user == user).all()
コード例 #10
0
ファイル: bookwarm_server.py プロジェクト: apsz/BookWarm
 def _load_all_available_books(self):
     with bookwarm.SQLSession(self._database_path) as session:
         self.__all_books = session.query(bookwarm.Book).all()