Exemplo n.º 1
0
 def addChoreToDB(self):
     self.chore1 = Chore.createChore("Cleaning")
     self.chore2 = Chore.createChore("Sweeping", completed=True)
     self.chore3 = Chore.createChore("Tidying")
     self.group1.addChore(self.chore1)
     self.group1.addChore(self.chore2)
     self.group2.addChore(self.chore3)
Exemplo n.º 2
0
def createChore():
    """
    Create a new Chore object and add it to the database.
    
    :param name: name of the chore
    :param groupID: the unique ID of the group where the chore will be added
    :param description: (optional) more information about the chore
    
    :type name: str
    :type groupID: int
    :type description: str
    
    :return: chore ID, status code
    :rtype: str, int
    
    :raises KeyError: name or group ID was not specified
    :raises sqlalchemy.orm.exc.NoResultFound: user or group does not exist
    """
    data = request.data
    dataDict = loads(data)

    try:
        choreName = dataDict['name']
        groupID = dataDict['groupID']
    except KeyError:
        error = "Name or group ID not specified"
        return error, 400

    try:
        group = Group.getGroup(groupID)
    except NoResultFound:
        error = "Group not found"
        return error, 404

    if 'description' in dataDict:
        choreDescription = dataDict['description']
    else:
        choreDescription = None

    chore = Chore.createChore(choreName, description=choreDescription)
    group.addChore(chore)

    return str(chore.id)
Exemplo n.º 3
0
 def addChoreToDB(self, name):
     chore = Chore.createChore(name)
     self.group.addChore(chore)