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)
Beispiel #2
0
def readDatabase(Inventory):
    filename = raw_input("What's the name of the database file?")
    fileIn = open(filename, 'r')
    # for each line in file
    for line in fileIn:
        # initialize our assets, author&title are formatted in class
        tempList = line.split('$')
        author = ""
        # format the author's name
        author += tempList[0] + ", " + tempList[1]
        # format the book's title
        title = tempList[2]
        quantity = tempList[3]
        price = tempList[4]
        tempBook = Book(author, title, quantity, price)
        # we check to see if the author exists in the dictionary
        if Inventory.has_key(tempBook.get_author()):
            Inventory[tempBook.get_author()].append(Book(author, title, \
                                                         quantity, price))
        else:
            Inventory[tempBook.get_author()] = [Book(author, title, \
                                                     quantity, price)]
    None
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)
Beispiel #4
0
from Book import Book

if __name__ == '__main__':
    x = Book('HBP', 2003, ['fantasy'], 'JKR', 607)
    print(x.get_name())
    print(x.get_author())