Example #1
0
def addReading(domain_id):
    """Add new reading to DB and re-render all the readings under the domain

    Args:
        domain ID

    Returns:
        checks if the user is logged in. If not, redirects to the
        login page.
        on POST: add the reading the the DB and redirects to the page
        which shows all the readings under the domain
        on GET: renders the page to add a reading
    """
    if 'username' not in login_session:
        return redirect('/login')
    if request.method == 'POST':
        try:
            author = session.query(Author).\
                filter_by(name=request.form['author']).one()
        except NoResultFound:
            author = Author(name=request.form['author'],
                            user_id=login_session['user_id'])
            session.add(author)
            session.commit()
        reading = ReadingItem(name=request.form['title'],
                              synopsis=request.form['synopsis'],
                              author_id=author.id,
                              domain_id=domain_id,
                              user_id=login_session['user_id'])
        session.add(reading)
        session.commit()
        return redirect(url_for('showReadings', domain_id=domain_id))
    else:
        return render_template('addReading.html')
def newTitle(genre_id):
    if request.method == 'POST':
        if request.form['title']:
            audiobook = Audiobook(title=request.form['title'],
                                  duration=request.form['duration'],
                                  price=request.form['price'],
                                  genre_id=genre_id)
            audiobook.recordOwner = login_session['profile']['email']
            session.add(audiobook)
            session.commit()

            book = \
                session.query(Audiobook).filter_by(title=audiobook.title).one()

            author = Author(name=request.form['author'], audiobook_id=book.id)
            session.add(author)
            session.commit()

            narrator = Narrator(name=request.form['narrator'],
                                audiobook_id=book.id)
            session.add(narrator)
            session.commit()

            link = Link(url=request.form['url'], audiobook_id=book.id)
            session.add(link)
            session.commit()

            flash('New Audiobook %s Successfully Added' % book.title)

            return redirect(url_for('showGenreBooks', genre_id=genre_id))
        else:
            flash('Title of the book is a required field')
            return render_template('addtitle.html')
    else:
        return render_template('addtitle.html')
Example #3
0
def createAuthor(login_session):
    newAuthor = Author(name=login_session['username'],
                       email=login_session['email'],
                       picture=login_session['picture'])
    session.add(newAuthor)
    session.commit()
    author = session.query(Author).filter_by(
        email=login_session['email']).one()
    return author.id
Example #4
0
def newAuthor():
    """Add new Author"""
    if 'username' not in login_session:
        return redirect('/login')

    user_id = login_session['user_id']

    if request.method == 'POST':
        newAuthor = Author(name=request.form['name'], user_id=user_id)
        session.add(newAuthor)
        flash('New Author %s Successfully Created' % newAuthor.name)
        session.commit()
        return redirect(url_for('aftershowCatalogue'))
    else:
        return render_template('createdetails.html')
Example #5
0
def add_author():
    """
    Handles data from "Add Author" form, adds new author to the database,
    and renders list of authors.
    """
    if 'username' not in login_session:
        return redirect('/login')

    if request.method == 'POST':
        if request.form['submit-button'] == 'Cancel':
            return redirect(url_for('show_authors_list'))
        if not request.form['new-author-name']:
            return render_template('add-author.html', empty_author_name=True)

        new_author = Author(name=request.form['new-author-name'],
                            user_id=login_session['user_id'])
        session.add(new_author)
        session.commit()
        return redirect(url_for('show_authors_list'))
    else:
        return render_template('add-author.html')
Example #6
0
def add_book(title, summary, current_genre_id, author_input, user_id, photo):

    new_book = Books(title=title,
                     summary=summary,
                     genre_id=current_genre_id,
                     user_id=user_id,
                     photo=photo)
    session.add(new_book)

    # check if author exists in the DB
    try:
        author = session.query(Author).filter_by(name=author_input).one()
        new_book.author_id = author.id
    # add author to DB if not
    except:
        new_author = Author(name=author_input)
        session.add(new_author)
        session.commit()

        new_book.author_id = new_author.id

    session.commit()
    return new_book
# session.rollback()
session = DBSession()


# Create user
User1 = User(name="George Nizharadze", email="*****@*****.**")
session.add(User1)
session.commit()

# Add theology domain and related readings
domain1 = Domain(name="Theology", user_id=1)

session.add(domain1)
session.commit()

author1 = Author(name="Davis, Ellen and Hays, Richard", user_id=1)

session.add(author1)
session.commit()

readingItem = ReadingItem(name="The Art of Reading Scripture", 
                            synopsis=("Exploration of the significance and understanding"
                                   "of the Bible in this post-modern world."),
                            user_id=1, domain_id=1, author_id=1)

session.add(readingItem)
session.commit()


author2 = Author(name="Williams, Rowan", user_id=1)
def user_create(email, username, picture):
    user = Author(email=email, username=username, picture=picture)
    session.add(user)
    session.commit()
    return session.query(Author).order_by(desc(Author.id)).first()
Example #9
0
session = DBSession()


# Biography
genre1 = Genre(name="Biography")
genre1.recordOwner = "*****@*****.**"
session.add(genre1)
session.commit()
# Book 1
book1 = Audiobook(title="Proud: My Fight for an Unlikely American Dream",
                  duration="9h:12m", price="$29.65", genre=genre1)
book1.recordOwner = "*****@*****.**"
session.add(book1)
session.commit()
# Author 1
author1 = Author(name="Ibtihaj Muhammad, Lori L. Tharps",
                 audiobook=book1)

session.add(author1)
session.commit()
# Narrator 1
narrator1 = Narrator(name="Ibtihaj Muhammad", audiobook=book1)
narrator1.recordOwner = "*****@*****.**"
session.add(narrator1)
session.commit()
# Link 1
link1 = Link(url="https://www.audible.com/pd/Proud-Audiobook/B07BGDGY6C?qid=\
1557949041&sr=1-4&ref=a_search_c3_lProduct_1_4&pf_rd_p=e81b7c27-6880-467a\
-b5a7-13cef5d729fe&pf_rd_r=SQYFMKHTWT59P5GH37PZ",
             audiobook=book1)
link1.recordOwner = "*****@*****.**"
session.add(link1)
Example #10
0
today = date.today()

TEXT_1 = "By so delight of showing neither believe he present. Deal sigh up in shew away when. Pursuit express no or prepare replied. Wholly formed old latter future but way she. Day her likewise smallest expenses judgment building man carriage gay. Considered introduced themselves mr to discretion at. Means among saw hopes for. Death mirth in oh learn he equal on. He as compliment unreserved projecting. Between had observe pretend delight for believe. Do newspaper questions consulted sweetness do. Our sportsman his unwilling fulfilled departure law. Now world own total saved above her cause table. Wicket myself her square remark the should far secure sex. Smiling cousins warrant law explain for whether. Throwing consider dwelling bachelor joy her proposal laughter. Raptures returned disposed one entirely her men ham. By to admire vanity county an mutual as roused. Of an thrown am warmly merely result depart supply. Required honoured trifling eat pleasure man relation."
TEXT_2 = "Carried nothing on am warrant towards. Polite in of in oh needed itself silent course. Assistance travelling so especially do prosperous appearance mr no celebrated. Wanted easily in my called formed suffer. Songs hoped sense as taken ye mirth at. Believe fat how six drawing pursuit minutes far. Same do seen head am part it dear open to. Whatever may scarcely judgment had. Manor we shall merit by chief wound no or would. Oh towards between subject passage sending mention or it. Sight happy do burst fruit to woody begin at. Assurance perpetual he in oh determine as. The year paid met him does eyes same. Own marianne improved sociable not out. Thing do sight blush mr an. Celebrated am announcing delightful remarkably we in literature it solicitude. Design use say piqued any gay supply. Front sex match vexed her those great."

newArticle1 = Article(title="The very first test article",
                      subtitle="The first subtitle",
                      publish_date=date(today.year, today.month, today.day),
                      url_desc="the-very-first",
                      html_text=TEXT_1,
                      on_home=True,
                      featured=True)
session.add(newArticle1)
session.commit()

newAuthor1 = Author(name="Corey Poff")
session.add(newAuthor1)
session.commit()

newAuthor2 = Author(name="Jonah G.-S.")
session.add(newAuthor2)
session.commit()

newArticleAuthor1 = ArticleAuthor(article_id=newArticle1.id,
                                  author_id=newAuthor1.id)
session.add(newArticleAuthor1)
session.commit()

newArticleAuthor2 = ArticleAuthor(article_id=newArticle1.id,
                                  author_id=newAuthor2.id)
session.add(newArticleAuthor2)
artauth3 = ArticleAuthor(
    article_id=3,
    author_id=3
)

res4 = ArticleResource(
  name="StAgnesAnonymous",
  article_id="4",
  caption="St. Agnes and Female Saint by Anonymous (From The Met Archives)",
  resource_type="JPG",
  resource_location="/static/articles/4/StAgnesAnonymous.jpg",
  is_title_img=True
)

auth4 = Author(
    name="Jeannine M. Pitas",
    bio="Jeannine M. Pitas is a writer, teacher, and Spanish-English literary translator currently living in Iowa, where she teaches at the University of Dubuque."
)

artauth4 = ArticleAuthor(
    article_id=4,
    author_id=4
)

res5 = ArticleResource(
  name="Felix",
  article_id="5",
  caption="Photo by Janice Sevre-Duszynska",
  resource_type="JPG",
  resource_location="/static/articles/5/Felix.jpg",
  is_title_img=True
)
Example #12
0
# session.rollback()
session = DBSession()

# Create dummy user
User1 = User(name="STOOPID",
             email="*****@*****.**",
             picture='https://i.ytimg.com/vi/JSpMHjCe_CM/maxresdefault.jpg')
session.add(User1)
session.commit()
# Book for Philosophy
category1 = Book(user_id=1, name="About Philosophy")

session.add(category1)
session.commit()

author1 = Author(name="Jordan Peterson")

session.add(author1)
session.commit()

menuItem1 = MenuItem(user_id=1,
                     name="12 Rules of Life",
                     description="When JP teaches how to live, \
you just listen.",
                     price="12.99",
                     book=category1,
                     author=author1,
                     author_name="Jordan Peterson")

session.add(menuItem1)
session.commit()
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker
from database_setup import Base, Author, Books_Data

engine = create_engine('sqlite:///bookscatalogue.db')
Base.metadata.bind = engine
DBSession = sessionmaker(bind=engine)
session = DBSession()

Firstauthor = Author(id="1", name="Vineet")

session.add(Firstauthor)

firstbook = Books_Data(bname="War and Peace",
                       genre="Historical",
                       desc="It is regarded as a central work of world\
                       literature and one of Tolstoy's finest literary\
                       achievements",
                       author_id="1")

session.add(firstbook)

secondbook = Books_Data(bname="Emma",
                        genre="Romantic",
                        desc="novel about youthful hubris and the perils\
                        of misconstrued romance.",
                        author_id="1")

session.add(secondbook)

Secondauthor = Author(id="2", name="Varun")
Example #14
0
def add_author(name):
    author = Author(name=name)
    session.add(author)
    session.commit()
    return author.id
Example #15
0
Base.metadata.bind = engine

DBSession = sessionmaker(bind=engine)
# A DBSession() instance establishes all conversations with the database
# and represents a "staging zone" for all the objects loaded into the
# database session object. Any change made against the objects in the
# session won't be persisted into the database until you call
# session.commit(). If you're not happy about the changes, you can
# revert all of them back to the last commit by calling
# session.rollback()
session = DBSession()

# Create Author 1
author1 = Author(
    name="Nasa",
    email="*****@*****.**",
    picture=
    'http://t0.gstatic.com/images?q=tbn:ANd9GcQ9u48pu-6IB2FnnYl_H-15le_g8Dkt5d5RN-VWiWIl_-dyJdaa'
)
session.add(author1)
session.commit()

# Post 1
post1 = Post(author_id=1,
             title="First step on moon",
             description='''Apollo 11 was the spaceflight that landed the first
             two people on the Moon. Mission commander Neil Armstrong and pilot
             Buzz Aldrin, both American, landed the lunar module Eagle on July
             20, 1969, at 20:17 UTC. Armstrong became the first person to step
             onto the lunar surface six hours after landing on July 21 at
             02:56:15 UTC; Aldrin joined him about 20 minutes later. They spent
             about two and a quarter hours together outside the spacecraft, and
Example #16
0
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker

from database_setup import Base, Author, Book, User

engine = create_engine('sqlite:///books.db')
Base.metadata.bind = engine

DBSession = sessionmaker(bind=engine)
session = DBSession()

author1 = Author(
    firstName="J.K.",
    lastName="Rolling",
    profilePic=
    "https://cdn-images-1.medium.com/max/2000/0*jCMeqyKliSaz_4sl.jpg",
    birthday="July 31, 1965")
session.add(author1)
author2 = Author(
    firstName="Mark",
    lastName="Twain",
    profilePic=
    "http://www.highplainschautauqua.org/Data/Sites/1/mark-twain.jpg",
    birthday="November 30, 1835")
session.add(author2)
author3 = Author(
    firstName="Dr.",
    lastName="Seuss",
    profilePic=
    "https://www.stmuhistorymedia.org/wp-content/uploads/2017/04/Dr-seuss-ew-770x476.jpg",
    birthday="March 2, 1904")
from database_setup import Base, User, Book, Author

engine = create_engine('sqlite:///books.db')
Base.metadata.bind = engine

DBSession = sessionmaker(bind=engine)
session = DBSession()

#Create dummy user
dummy_user = User(name="John Johnson", email="*****@*****.**")

session.add(dummy_user)
session.commit()

# Books by John Grisham
john_grisham = Author(user_id=1, name="John Grisham")

session.add(john_grisham)
session.commit()

camino_island = Book(
    title="Camino Island",
    description=
    "Bruce Cable owns a popular bookstore in the sleepy resort town of Santa Rosa on Camino Island in Florida. He makes his real money, though, as a prominent dealer in rare books. Very few people know that he occasionally dabbles in the black market of stolen books and manuscripts. Mercer Mann is a young novelist with a severe case of writer's block who has recently been laid off from her teaching position. She is approached by an elegant, mysterious woman working for an even more mysterious company. A generous offer of money convinces Mercer to go undercover and infiltrate Bruce Cable's circle of literary friends, ideally getting close enough to him to learn his secrets. But eventually Mercer learns far too much.",
    author=john_grisham)

session.add(camino_island)
session.commit()

the_whistler = Book(
    title="The Whistler",