Ejemplo n.º 1
0
def main():
    #------------------Remove Actions-----------------
    #Test Language: Remove Spanish from SU Buenos Aires
    Program.find_by_name("SU Buenos Aires").remove_language(
        Language.find_by_name("Spanish"))
    db.session.commit()

    #Test Loaction: Remove Lisbon, Portugal from SU European Cultural Exploration
    Program.find_by_name("SU European Cultural Exploration").remove_location(
        Location.find_by_name("Lisbon", "Portugal"))
    db.session.commit()
    #Removed the connection, but didnt remove Lisbon from the database

    #Test Area: Remove Biology from SU London
    Program.find_by_name("SU London").remove_area(Area.find_by_name("Biology"))
    db.session.commit()

    #Test Term: Remove Summer 1 from SU Amsterdam
    Program.find_by_name("SU Amsterdam").remove_term(
        Term.find_by_name("Summer 1"))
    db.session.commit()

    #------------------Modify Actions-----------------
    #Test removing Description from SU European Cultural Exploration
    Program.find_by_name("SU European Cultural Exploration").description = None
    db.session.commit()

    #Test Changing community engagement learning opportunity to False for SU Amsterdam
    Program.find_by_name("SU Amsterdam").comm_eng = False
    db.session.commit()

    #Test removing provider
    Provider.find_by_name("A1").remove_program(
        Program.find_by_name("SU Amsterdam"))
    db.session.commit()

    #------------------Add Actions-----------------
    #Add Spanish and French to SU ECE
    languages = ["Spanish", "French"]
    for i in languages:
        if (Language.get_language_id(i) == -1):
            tempLanguage = Language(i)
            tempLanguage.save_to_db()
        else:
            tempLanguage = Language.find_by_name(i)

        Program.find_by_name("SU European Cultural Exploration").add_language(
            tempLanguage)
        db.session.commit()
def remove_programs_from_provider(providerName, programs):

    prov = Provider.find_by_name(providerName)
    if (prov == None):
        raise ValueError

    for i in programs:
        tempProgram = Program.find_by_name(i)

        if (tempProgram == None):
            raise ValueError

        prov.remove_program(tempProgram)
        prov.save_to_db()

    #This if statement checks to see if the resulting Provider has any more existing relationships
    #   If there are none, then delete the provider from the database
    if (Provider.query.join(Programs_Providers).filter(
        (Programs_Providers.c.provider_id == prov.id)).first() == None):
        db.session.delete(prov)

    db.session.commit()
    return True
def create_new_program(providerName, programName, com, res, intern, cost,
                       cost_stipulations, description, url, areas, terms,
                       languages, locations):
    #-----------------------------PROVIDER RELATIONSHIP----------------------------
    # Check if the provider already exist, if it doesn't then make a new provider
    if (Provider.get_provider_id(providerName) == -1):
        prov = Provider(providerName)
        prov.save_to_db()
    else:
        prov = Provider.find_by_name(providerName)

    # Check if the program already exist, if it doesn't then make a new program
    if (Program.get_program_id(programName) == -1):
        prog = Program(programName, com, res, intern, cost, cost_stipulations,
                       description, url)
        prog.save_to_db()
    else:
        prog = Program.find_by_name(programName)

    #Add the program to the provider
    prov.add_program(prog)
    prov.save_to_db()

    #-----------------------------PROGRAM RELATIONSHIPS----------------------------
    # AREA, TERM, LANGUAGES, LOCATION

    # AREA:
    # Cyle through all area names: check to see if the area already exist in the db,
    #    if it doesn't, add it to the program and create the relationship.
    for i in areas:
        if (Area.get_area_id(i) == -1):
            tempArea = Area(i)
            tempArea.save_to_db()
        else:
            tempArea = Area.find_by_name(i)

        prog.add_area(tempArea)
        prog.save_to_db()
        #might need save to db methods

    # TERM:
    # Cyle through all term names: check to see if the term already exist in the db,
    #    if it doesn't, add it to the program and create the relationship.
    for i in terms:
        if (Term.get_term_id(i) == -1):
            tempTerm = Term(i)
            tempTerm.save_to_db()
        else:
            tempTerm = Term.find_by_name(i)

        prog.add_term(tempTerm)
        prog.save_to_db()
        #might need save to db methods

    # LANGUAGES:
    # Cyle through all term names: check to see if the term already exist in the db,
    #    if it doesn't, add it to the program and create the relationship.
    for i in languages:
        if (Language.get_language_id(i) == -1):
            tempLanguage = Language(i)
            tempLanguage.save_to_db()
        else:
            tempLanguage = Language.find_by_name(i)

        prog.add_language(tempLanguage)
        prog.save_to_db()
        #might need save to db methods

    # LOCATION:
    # Cyle through all term names: check to see if the term already exist in the db,
    #    if it doesn't, add it to the program and create the relationship.
    for i in locations:
        if (Location.get_location_id(i[0], i[1]) == -1):
            tempLocation = Location(i[0], i[1])
            tempLocation.save_to_db()
        else:
            tempLocation = Location.find_by_name(i[0], i[1])

        prog.add_location(tempLocation)
        prog.save_to_db()
def home():
    providers = Provider.return_all_providers()
    json_list = [i.serialize for i in providers]
    return jsonify(json_list)