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 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)