Esempio n. 1
0
def deleteAllChores():
    try:
        num_rows_deleted = session.query(Chores).delete()
        session.commit()
        return "{} records deleted\n".format(num_rows_deleted)
    except:
        session.rollback()
Esempio n. 2
0
def get_chore(chore_id):
    try:
        chore = session.query(Chores).filter_by(chore_title=chore_id).one()
        if chore:
            return jsonify(chore.serialize)
    except:
        return "No such chores exist\n"
Esempio n. 3
0
def delete_all_chores():
    """It deletes all the chores from the database."""
    try:
        num_rows_deleted = session.query(Chores).delete()
        session.commit()
        return "{} records deleted\n".format(num_rows_deleted)
    except:
        session.rollback()
Esempio n. 4
0
def get_chore(chore_id):
    """This returns a chore with the chore id in the json format. However, the
    output will not display in the serialized form, as the question demands
    only the HEAD request"""
    try:
        chore = session.query(Chores).filter_by(chore_title=chore_id).one()
        if chore:
            return jsonify(chore.serialize)
    except:
        return "No such chores exist\n"
Esempio n. 5
0
def deleteAChore(choreid):
    try:
        choreToDelete = session.query(Chores).filter_by(
            chore_title=choreid).one()
    except:
        return "No such chores exist\n"

    session.delete(choreToDelete)
    session.commit()
    return "Removed Chore with id %s\n" % choreid
Esempio n. 6
0
def delete_a_chore(choreid):
    """It deletes a chore with the chore_title"""
    try:
        chore_to_delete = session.query(Chores).filter_by(
            chore_title=choreid).one()
    except:
        return "No such chores exist\n"

    session.delete(chore_to_delete)
    session.commit()
    return "Removed Chore with id %s\n" % choreid
Esempio n. 7
0
def updateChore(title, task):
    try:
        tobeUpdatedChore = session.query(Chores).filter_by(
            chore_title=title).one()
        tobeUpdatedChore.chore = task
        session.merge(tobeUpdatedChore)
    except:
        tobeUpdatedChore = Chores(chore_title=title, chore=task)
        session.add(tobeUpdatedChore)
    session.commit()
    return "Updated the chore with id %s\n" % title
Esempio n. 8
0
def update_a_chore(title, task):
    """This just update an existing chore with newer task"""
    try:
        tobe_updatedchore = session.query(Chores).filter_by(
            chore_title=title).one()
        tobe_updatedchore.chore = task
        session.merge(tobe_updatedchore)
    except:
        tobe_updatedchore = Chores(chore_title=title, chore=task)
        session.add(tobe_updatedchore)
    session.commit()
    return "Updated the chore with id %s\n" % title
Esempio n. 9
0
def makeANewChore(chore):
    title, task = chore.items()[0]
    addedchore = Chores(chore_title=title, chore=task)
    existing_titles = [
        elem.chore_title for elem in session.query(Chores).all()
    ]
    if addedchore.chore_title not in existing_titles:
        session.add(addedchore)
        session.commit()
        return jsonify(addedchore.serialize)
    else:
        return "Chore title already exist.\n"
Esempio n. 10
0
def make_a_new_chore(chore):
    """This adds a new chore in the database and also returns the json
    format of the chores added"""
    title, task = chore.items()[0]
    addedchore = Chores(chore_title=title, chore=task)
    existing_titles = [
        elem.chore_title for elem in session.query(Chores).all()
    ]
    if addedchore.chore_title not in existing_titles:
        session.add(addedchore)
        session.commit()
        return jsonify(addedchore.serialize)
    else:
        return "Chore title already exist.\n"
Esempio n. 11
0
from models import Model, Tag, Post, User
from populate_db import create_tag_or_user, fake, session

user = create_tag_or_user(1, User, fake.name)[0]
tags = [create_tag_or_user(1, Tag, fake.word)[0] for _ in range(2)]
post = Post(user=user, title=fake.sentence(), body=fake.text())
post.tags.extend(tags)
session.add(user)
session.add(tags[0])
session.add(tags[1])
session.add(post)
session.commit()

posts = session.query(Post).join(User).filter(User.name == user.name).filter(
    Post.tags.any(Tag.id.in_([tag.id for tag in tags]))).all()
print(posts)
Esempio n. 12
0
def get_chores():
    """This returns all the chores in the json format"""
    chores = session.query(Chores).all()
    return jsonify([c.serialize for c in chores])
Esempio n. 13
0
def get_chores():
    chores = session.query(Chores).all()
    return jsonify([c.serialize for c in chores])