Пример #1
0
def sim(simId):
    r"""Add a new simulation from the beginning or through a template"""

    editing_sim_list = list(sm.getSimsInState('editing'))
    id_value = request.args.get(
        'id')  #get simulation id from html GET HTTP method.

    for simIdFound in editing_sim_list:
        if id_value is None:
            if simIdFound == simId:
                selectedSim = hyde.Sim(simIdFound)
            #end
        else:
            if simIdFound == f'{id_value}':
                selectedSim = hyde.Sim(simIdFound)
            #end
        #end
    #end

    # if a user wants to create a new simulation, selectedSim -> default name&blank input file
    # otherwise, selectedSim -> sim object
    return render_template(
        'sim.html',
        selectedSim=selectedSim,
        simulation=[hyde.Sim(simId) for simId in editing_sim_list])
Пример #2
0
def adding():
    """adding a new simulation/modifying a new simulation"""

    editing_sim_list = list(sm.getSimsInState('editing'))

    id_value = request.json[
        "id"]  # retrieve sim id, name and input file from sim.html
    name = request.json["name"]
    print(name)
    inpFile = request.json['inpFile']

    for simIdFound in editing_sim_list:
        if simIdFound == id_value:
            hyde.Sim(simIdFound).rename(name)
            hyde.Sim(simIdFound).updateInpFile(inpFile)
            simId = simIdFound
        #end
    #end
    return "adding completed"
Пример #3
0
def deleting():
    id_value = request.json['id']
    editing_sim_list = list(sm.getSimsInState('editing'))
    if id_value is not None:
        for simId in editing_sim_list:
            if simId == id_value:
                sm.removeSim(hyde.Sim(simId))
            #end
        #end
    #end
    return "deleted"
Пример #4
0
def main():
    r""" main page. ask users to choose following options
    1. Add : add a new simulation
    2. Example: add new simulation from template
    3. Delete: delete simulations from the sidebar/DB
    """
    editing_sim_list = list(
        sm.getSimsInState('editing')
    )  #returns a list of simulation ids with the state of 'editing'
    return render_template(
        'index.html',
        simulation=[hyde.Sim(simId) for simId in editing_sim_list])
Пример #5
0
def main():
    r""" main page. ask users to choose following options
    1. Add : add a new simulation
    2. Example: add new simulation from template
    3. Delete: delete simulations from the sidebar/DB
    """
    if 'username' in session:
        #     current_user_id=session["id"]
        flash('you are logged in!')
    else:
        return redirect(url_for('login'))

    print(hyde.User(current_user_id).simList('editing'))
    for ex in sm.getExampleSims():
        exampleSimId = ex.simId


#        client.acl_setuser(hyde.User(current_user_id).name(), keys=f'sim:{exampleSimId}')
    editing_sim_list = list(
        sm.getSimsInState('editing')
    )  #returns a list of simulation ids with the state of 'editing'
    r"""this allows me to restrict the user to only
    the simulations they created/edited
    """

    editing_sim_list = hyde.User(current_user_id).simList('editing')
    r"""
    
    for simid in editing_sim_list:
        editing_key_list.append(f'sim:{simid}')
    for key in client.acl_getuser(hyde.User(current_user_id).name())['keys']:
        for key1 in editing_key_list:
            count=0
            if key1 != key:
                count= count+1
            if count==0:
                ind = editing_key_list.index(key1)
                editing_key_list.pop(ind)
                editing_sim_list.pop(ind)
    """
    return render_template(
        'index.html',
        simulation=[hyde.Sim(simId) for simId in editing_sim_list])