Esempio n. 1
0
def new():
    form = PublicationForm(request.form)
    if request.method == 'POST' and form.validate():
        if  form.pubtype.data == 'smag':
            title = form.title.data
            type = form.pubtype.data
            category = form.category.data
            status = form.status.data
            frequency = form.frequency.data
            publisher = form.publisher.data
            created_by = "U0001" # hardcoded value

            mag = Magazine(title, publisher, status, created_by, category, type, frequency)

            mag_db = root.child('publications')
            mag_db.push({
                    'title': mag.get_title(),
                    'type': mag.get_type(),
                    'category': mag.get_category(),
                    'status': mag.get_status(),
                    'frequency': mag.get_frequency(),
                    'publisher': mag.get_publisher(),
                    'created_by': mag.get_created_by(),
                    'create_date': mag.get_created_date()
            })

            flash('Magazine Inserted Sucessfully.', 'success')

        elif form.pubtype.data == 'sbook':
            title = form.title.data
            type = form.pubtype.data
            category = form.category.data
            status = form.status.data
            isbn = form.isbn.data
            author = form.author.data
            synopsis = form.synopsis.data
            publisher = form.publisher.data
            created_by = "U0001"  # hardcoded value

            book = Book(title, publisher, status, created_by, category, type, synopsis, author, isbn)
            book_db = root.child('publications')
            book_db.push({
                'title': book.get_title(),
                'type': book.get_type(),
                'category': book.get_category(),
                'status': book.get_status(),
                'author': book.get_author(),
                'publisher': book.get_publisher(),
                'isbn': book.get_isbnno(),
                'synopsis': book.get_synopsis(),
                'created_by': book.get_created_by(),
                'create_date': book.get_created_date()
            })

            flash('Book Inserted Sucessfully.', 'success')

        return redirect(url_for('viewpublications'))


    return render_template('create_publication.html', form=form)
Esempio n. 2
0
def viewpublications():
    publications = root.child('publications').get()
    list = []  #create a list to store all the publication objects
    print(publications)
    for pubid in publications:

        eachpublication = publications[pubid]

        if eachpublication['type'] == 'smag':
            magazine = Magazine(
                eachpublication['title'], eachpublication['publisher'],
                eachpublication['status'], eachpublication['created_by'],
                eachpublication['category'], eachpublication['type'],
                eachpublication['frequency'])
            magazine.set_pubid(pubid)
            print(magazine.get_pubid())
            list.append(magazine)
        else:
            book = Book(eachpublication['title'], eachpublication['publisher'],
                        eachpublication['status'],
                        eachpublication['created_by'],
                        eachpublication['category'], eachpublication['type'],
                        eachpublication['synopsis'], eachpublication['author'],
                        eachpublication['isbn'])
            book.set_pubid(pubid)
            list.append(book)

    return render_template('view_all_publications.html', publications=list)
Esempio n. 3
0
    #gêneros
    adventure = Genre('Aventura')
    fantasy = Genre('Fantasia')
    philosophy = Genre('Filosofia')
    science = Genre('Ciências')

    #autores
    jkrowling = Author('J.K. Rowling')
    cortella = Author('Mario Sérgio Cortella')
    karnal = Author('Leandro Karnal')
    ponde = Author('Luiz Felipe Pondé')

    #livros
    harrypotter = Book('Harry Potter e a pedra filosofal', 2019,
                       [adventure.name, fantasy.name], 230, '5433-1',
                       [jkrowling])
    felicidade = Book('Felicidade: modos de usar', 2019, [philosophy], 100,
                      '4351-2', [cortella, karnal, ponde])
    harrypotter.show_info()
    harrypotter.calculate_days_to_read(30)
    print('\n')
    felicidade.show_info()
    felicidade.calculate_days_to_read(50)
    print('\n')

    #revistas
    mundoestranho = Magazine('Mundo Estranho', 'Jan / 2019', [science], 50,
                             129)
    mundoestranho.show_info()
    mundoestranho.get_next_edition()
    mundoestranho.get_previous_edition()
Esempio n. 4
0
def update_publication(id):
    form = PublicationForm(request.form)
    if request.method == 'POST' and form.validate():
        if form.pubtype.data == 'smag':
            title = form.title.data
            type = form.pubtype.data
            category = form.category.data
            status = form.status.data
            frequency = form.frequency.data
            publisher = form.publisher.data
            created_by = "U0001"  # hardcoded value
            mag = Magazine(title, publisher, status, created_by, category, type, frequency)
            # create the magazine object
            mag_db = root.child('publications/' + id)
            mag_db.set({
                    'title': mag.get_title(),
                    'type': mag.get_type(),
                    'category': mag.get_category(),
                    'status': mag.get_status(),
                    'frequency': mag.get_frequency(),
                    'publisher': mag.get_publisher(),
                    'created_by': mag.get_created_by(),
                    'create_date': mag.get_created_date()
            })

            flash('Magazine Updated Sucessfully.', 'success')

        elif form.pubtype.data == 'sbook':
            title = form.title.data
            type = form.pubtype.data
            category = form.category.data
            status = form.status.data
            isbn = form.isbn.data
            author = form.author.data
            synopsis = form.synopsis.data
            publisher = form.publisher.data
            created_by = "U0001"  # hardcoded value

            book = Book(title, publisher, status, created_by, category, type, synopsis, author, isbn)
            mag_db = root.child('publications/' + id)
            mag_db.set({
                'title': book.get_title(),
                'type': book.get_type(),
                'category': book.get_category(),
                'status': book.get_status(),
                'author': book.get_author(),
                'publisher': book.get_publisher(),
                'isbn': book.get_isbnno(),
                'synopsis': book.get_synopsis(),
                'created_by': book.get_created_by(),
                'create_date': book.get_created_date()
            })

            flash('Book Updated Successfully.', 'success')

        return redirect(url_for('viewpublications'))

    else:
        url = 'publications/' + id
        eachpub = root.child(url).get()

        if eachpub['type'] == 'smag':
            magazine = Magazine(eachpub['title'], eachpub['publisher'], eachpub['status'], eachpub['created_by'],
                                eachpub['category'], eachpub['type'], eachpub['frequency'])

            magazine.set_pubid(id)
            form.title.data = magazine.get_title()
            form.pubtype.data = magazine.get_type()
            form.category.data = magazine.get_category()
            form.publisher.data = magazine.get_publisher()
            form.status.data = magazine.get_status()
            form.frequency.data = magazine.get_frequency()
        elif eachpub['type'] == 'sbook':
            book = Book(eachpub['title'], eachpub['publisher'], eachpub['status'], eachpub['created_by'],
                        eachpub['category'], eachpub['type'],
                        eachpub['synopsis'], eachpub['author'], eachpub['isbn'])
            book.set_pubid(id)
            form.title.data = book.get_title()
            form.pubtype.data = book.get_type()
            form.category.data = book.get_category()
            form.publisher.data = book.get_publisher()
            form.status.data = book.get_status()
            form.synopsis.data = book.get_synopsis()
            form.author.data = book.get_author()
            form.isbn.data = book.get_isbnno()

        return render_template('update_publication.html', form=form)