def get_author(self, author):
     db = Data_base().library
     writer = str()
     for man in Author.objects(name__first=author.split()[0],
                               name__second=author.split()[-1]):
         writer = {
             'name': man.name,
             'born': man.born,
             'img': self.get_image(man.img),
             'description': man.description
         }
     return writer
 def get_img(self):
     buffered = BytesIO()
     db = Data_base().db
     img = 0
     for book in Book.objects():
         img = book.img
     img = Image.open(img)
     #print(img.title)
     img.save(buffered, format="JPEG")
     #print(base64.b64encode(buffered.getvalue()))
     return b"data:image/jpeg;base64," + base64.b64encode(
         buffered.getvalue())
Example #3
0
 def get_book(self, book):
     db = Data_base().library
     for book in Book.objects(title=book):
         return {
             'title': book.title,
             'author': book.author,
             'description': book.description,
             'publisher': book.publisher,
             'ganre': book.genre,
             'publishing_date': book.publishing_date,
             'image': self.get_image(book.img),
             'rating': book.rating,
             'price': book.price
         }
Example #4
0
 def get_books(self):
     db = Data_base().library
     books = list()
     for book in Book.objects.order_by('-rating'):
         books.append({
             'title': book.title,
             'author': book.author,
             'description': book.description,
             'publisher': book.publisher,
             'ganre': book.genre,
             'publishing_date': book.publishing_date,
             'image': self.get_image(book.img),
             'rating': book.rating
         })
     return books
Example #5
0
 def get_books(self, require):
     db = Data_base().library
     books = list()
     for book in Book.objects(title__icontains=require).order_by('-rating'):
         books.append(self.zip_book(book))
     for book in Book.objects(
             author__icontains=require).order_by('-rating'):
         books.append(self.zip_book(book))
         if books.count(books[-1]) > 1:
             del books[-1]
     for book in Book.objects(
             description__icontains=require).order_by('-rating'):
         books.append(self.zip_book(book))
         if books.count(books[-1]) > 1:
             del books[-1]
     return books
Example #6
0
from models.author import Author
from models.data_base import Data_base

if __name__ == '__main__':
    db = Data_base().library
    a = Author(
        {
            'first': input("F_name: "),
            'second': input("S_name: "),
            'addactive': input("Add_name: ") or None
        },
        {
            'day': 2,
            'month': 6,
            'year': 1920
        },
    )
    print(a.name['first'])
    date = [int(i) for i in input("date: ").split()]
    date.extend([None, None])
    a.born['day'], a.born['month'], a.born[
        'year'] = date[2] or None, date[1] or None, date[0] or None
    a.img = open(
        r"C:\Users\sashk\PycharmProjects\Library\static\image\\" +
        input("Img: "), 'rb')
    a.save()
Example #7
0
from models.book import Book
from models.data_base import Data_base

if __name__ == '__main__':
    base = Data_base().db
    print(base)
    # img = open('starwars.jpg', 'rb')
    # img.show()
    my_book = Book('New_book', 'Vasya Pupkin', 'Test defult cover',
                   'govno std', 'Zalupa', 2043)
    my_book.save()
    print(my_book.publishing_date)