Esempio n. 1
0
def update_publisher():
    name = input('Please Enter publisher name: ')
    publisher = data_services.get_publisher(publisher=name)
    name = input('Please Enter publisher name: ')
    founded = input('Please Enter publisher founded: ')
    location = input('Please Enter publisher location: ')
    data_services.update_publisher(publisher=publisher,
                                   name=name,
                                   founded=founded,
                                   location=location)
Esempio n. 2
0
def edit_book(id):
    form = BookForm()
    book = data_services.get_book_by_id(id)
    if request.method == 'GET':
        authors = ""
        for author in book.author:
            authors = author + ", "
        form = BookForm(obj=book)
        form.author.data = authors
        subscribers = data_services.get_all_subscriber()
        form.subscriber.choices = [(subscriber.id, subscriber.email)
                                   for subscriber in subscribers]
        form.subscriber.process_data(subscribers[0].id)
        publishers = data_services.get_all_publishers()
        form.publisher.choices = [(publisher.id, publisher.name)
                                  for publisher in publishers]
        form.publisher.process_data(book.publisher.id)
        return render_template('edit_book.html', form=form, status='edit')
    elif request.method == 'POST':
        if form.update.data:
            if form.validate_on_submit():
                authors = []
                for a in form.author.data.split(","):
                    if a != "" and a != " ":
                        authors.append(a)
                publisher = data_services.get_publisher(form.publisher.data)
                data_services.update_book(bk=book,
                                          title=form.title.data,
                                          author=form.author.data,
                                          pages=form.pages.data,
                                          publish_date=form.publish_date.data,
                                          publisher=publisher)
                flash('Book created successfully', 'success')
            else:
                for k, v in form.errors.items():
                    flash(v[0], 'danger')
                return render_template('edit_book.html',
                                       form=form,
                                       status='edit')
        elif form.delete.data:
            data_services.delete_book(book)
            flash('Book deleted successfully', 'success')
        elif form.borrow.data:
            subscriber = data_services.get_subscriber_by_id(
                form.subscriber.data)
            data_services.book_add_subscriber(bk=book,
                                              subscriber=subscriber,
                                              start=form.start.data,
                                              end=form.end.data)
            flash('Book borrow created successfully', 'success')
        return redirect('/book/list')
Esempio n. 3
0
def update_book():
    title = input('Please Enter book name: ')
    book = data_services.get_book(bk=title)
    title = input('Please Enter book name: ')
    author = input('Please Enter book author: ')
    pages = input('Please Enter book pages: ')
    publish_date = input('Please Enter publish date (default is today: ')
    publisher = input('Please Enter publisher name: ')
    publisher = data_services.get_publisher(publisher)
    data_services.update_book(bk=book,
                              title=title,
                              author=author,
                              pages=pages,
                              publish_date=publish_date,
                              publisher=publisher)
Esempio n. 4
0
def create_book():
    title = input('Please Enter book name: ')
    author = input('Please Enter book author: ')
    pages = input('Please Enter book pages: ')
    publish_date = input('Please Enter publish date (default is today: ')
    publisher = input('Please Enter publisher name: ')
    publisher = data_services.get_publisher(publisher)
    book = data_services.create_book(title=title,
                                     author=author,
                                     pages=pages,
                                     publish_date=publish_date,
                                     publisher=publisher)
    if book:
        print('Book created successfully')
    else:
        print("Unable to create book")
Esempio n. 5
0
def new_book():
    form = BookForm()
    if request.method == 'GET':
        publishers = data_services.get_all_publishers()
        form.publisher.choices = [(publisher.id, publisher.name)
                                  for publisher in publishers]
        return render_template('edit_book.html', form=form, status='new')
    elif request.method == 'POST':
        if form.validate_on_submit():
            publisher = data_services.get_publisher(form.publisher.data)
            data_services.create_book(title=form.title.data,
                                      author=form.author.data,
                                      pages=form.pages.data,
                                      publish_date=form.publish_date.data,
                                      publisher=publisher)
            flash('Book created successfully', 'success')
        else:
            for k, v in form.errors.items():
                flash(v[0], 'danger')
            return render_template('edit_book.html', form=form, status='new')
        return redirect('/book/list')
Esempio n. 6
0
def edit_publisher(id):
    form = PublisherForm()
    publisher = data_services.get_publisher(id)
    if request.method == "GET":
        form = PublisherForm(obj=publisher)
        return render_template('edit_publisher.html', form=form, status='edit')
    elif request.method == 'POST':
        if form.update.data:
            if form.validate_on_submit():
                data_services.update_publisher(publisher=publisher,
                                               name=form.name.data,
                                               founded=form.founded.data,
                                               location=form.location.data)
                flash('Publisher created successfully', 'success')
            else:
                for k, v in form.errors.items():
                    flash(v[0], 'danger')
                return render_template('edit_publisher.html',
                                       form=form,
                                       status='edit')
        elif form.delete.data:
            data_services.delete_publisher(publisher=publisher)
            flash('Publisher deleted successfully', 'success')
        return redirect('/publisher/list')
Esempio n. 7
0
def delete_publisher():
    name = input('Please Enter publisher name: ')
    publisher = data_services.get_publisher(publisher=name)
    data_services.delete_publisher(publisher=publisher)
    print(f'Publisher deleted successfully')
Esempio n. 8
0
def find_publisher():
    name = input('Please Enter publisher name: ')
    publisher = data_services.get_publisher(publisher=name)
    print(
        f"Publisher {publisher.name} founded in {publisher.founded} and located in  {publisher.location}"
    )