Beispiel #1
0
def changelog_search():
    f = SearchForm(request.form)
    if f.modified_by.data != "" and f.targetTable.data != "" and f.target.data != "":
        changes = Changelog.findByUserAndTableAndId(f.modified_by.data,
                                                    f.targetTable.data,
                                                    f.target.data)
        f.setupChoices()
        f.setupTarget(f.targetTable.data)
        f.targetTable.default = f.targetTable.data
        return render_template("changelog/list.html", changes=changes, form=f)
    elif f.modified_by.data != "" and f.targetTable.data != "":
        changes = Changelog.findByUserAndTable(f.modified_by.data,
                                               f.targetTable.data)
        f.setupChoices()
        f.setupTarget(f.targetTable.data)
        f.targetTable.default = f.targetTable.data
        return render_template("changelog/list.html", changes=changes, form=f)
    elif f.modified_by.data != "":
        changes = Changelog.findByUser(f.modified_by.data)
        f.setupChoices()
        return render_template("changelog/list.html", changes=changes, form=f)
    elif f.targetTable.data != "":
        changes = Changelog.findByTable(f.targetTable.data)
        f.setupChoices()
        f.setupTarget(f.targetTable.data)
        f.targetTable.default = f.targetTable.data
        return render_template("changelog/list.html", changes=changes, form=f)
    else:
        changes = Changelog.findAll()
        f.setupChoices()
        return render_template("changelog/list.html", changes=changes, form=f)
Beispiel #2
0
def controllers_delete(controller_id): 
    log = Changelog(current_user.id, "Controller", "", controller_id, "Delete", Controller.query.get(controller_id).name, "")
    db.session().add(log)

    for c in Cable.query.filter_by(controller_a_id = controller_id):
        log = Changelog(current_user.id, "Cable", "", c.id, "Delete", Cable.query.get(c.id).name, "")
        db.session().add(log)

        for t in Thread.query.filter_by(cable_id = c.id):
            Thread.query.filter_by(cable_id=c.id).delete()

        Cable.query.filter_by(id=c.id).delete() 

    for c in Cable.query.filter_by(controller_b_id = controller_id):
        log = Changelog(current_user.id, "Cable", "", c.id, "Delete", Cable.query.get(c.id).name, "")
        db.session().add(log)

        for t in Thread.query.filter_by(cable_id = c.id):
            Thread.query.filter_by(cable_id=c.id).delete()
            
        Cable.query.filter_by(id=c.id).delete() 

    Controller.query.filter_by(id=controller_id).delete()   
    db.session().commit()
    
    return redirect(url_for("controllers_index"))
Beispiel #3
0
def cables_edit_one(cable_id):
    if request.method == "GET":
        c = Cable.query.get(cable_id)
        f = CableForm()
        f.setupChoices()
        f.controller_a_id.default = c.controller_a_id
        f.controller_b_id.default = c.controller_b_id
        f.size.default = c.size
        f.process()
        return render_template("cables/edit.html", form=f, cable=c)

    f = CableForm(request.form)
    c = Cable.query.get(cable_id)

    #Validoidaan CableFormin sisältämien kenttien datat, jos
    #niissä on häikkää, niin palautetaan cables/edit.html sivu
    #virheviestin kera.
    f.setupChoices()
    if not f.validate():
        return render_template("cables/edit.html", form=f, cable=c)
    nameNotEdited = True
    if (c.name != f.name.data):
        nameNotEdited = False
    if not f.validate2(nameNotEdited):
        return render_template("cables/edit.html", form=f, cable=c)

    if (c.name != f.name.data):
        log = Changelog(current_user.id, "Cable", "name", c.id, "Update",
                        c.name, f.name.data)
        db.session().add(log)
        c.name = f.name.data
    if (c.note != f.note.data):
        log = Changelog(current_user.id, "Cable", "note", c.id, "Update",
                        c.note, f.note.data)
        db.session().add(log)
        c.note = f.note.data
    if (c.controller_a_id != f.controller_a_id.data):
        log = Changelog(current_user.id, "Cable", "controller_a_id", c.id,
                        "Update", c.controller_a_id, f.controller_a_id.data)
        db.session().add(log)
        c.controller_a_id = f.controller_a_id.data
    if (c.controller_b_id != f.controller_b_id.data):
        log = Changelog(current_user.id, "Cable", "controller_b_id", c.id,
                        "Update", c.controller_b_id, f.controller_b_id.data)
        db.session().add(log)
        c.controller_b_id = f.controller_b_id.data

    db.session().commit()

    return redirect(url_for("cables_index"))
Beispiel #4
0
def cables_delete(cable_id): 
    log = Changelog(current_user.id, "Cable", "", 0, "Delete", Cable.query.get(cable_id).name, "")

    for t in Thread.query.filter_by(cable_id = cable_id):
        Changelog.deleteByTableAndId("Thread", t.id)
    Thread.query.filter_by(cable_id=cable_id).delete()
    db.session().commit()
    
    Changelog.deleteByTableAndId("Cable", cable_id)
    Cable.query.filter_by(id=cable_id).delete()
    db.session().add(log)   
    db.session().commit()
    
    return redirect(url_for("cables_index"))
Beispiel #5
0
def cables_create():
    if request.method == "GET":
        f = CableForm()
        f.setupChoices()
        return render_template("cables/new.html", form=f)

    form = CableForm(request.form)
    #Validoidaan CableFormin sisältämien kenttien datat, jos
    #niissä on häikkää, niin palautetaan cables/new.html sivu
    #virheviestin kera.
    form.setupChoices()
    if not form.validate():
        return render_template("cables/new.html", form=form)
    if not form.validate2(False):
        return render_template("cables/new.html", form=form)

    c = Cable(form.controller_a_id.data, form.controller_b_id.data,
              form.size.data, form.name.data, form.note.data)

    #Kerätään kaapelin size kentästä (esim 5x4) kaapelin säikeiden
    #lukumäärä ja luodaan sen mukaan kaapelin sisällä kulkevat
    #säikeet tietokantaan.
    tmp = form.size.data.split('x')
    n = int(tmp[0]) * int(tmp[1])
    for i in range(n):
        c.threads.append(Thread(i + 1, i + 1, i + 1, i + 1, "", ""))

    db.session().add(c)
    db.session().commit()

    log = Changelog(current_user.id, "Cable", "", c.id, "Create", "", "")
    db.session().add(log)
    db.session().commit()

    return redirect(url_for("cables_index"))
Beispiel #6
0
def crossconnections_create(controller_id):
    if request.method == "GET":
        f = CrossconnectionForm()
        f.setupChoices(controller_id)
        c = Controller.query.get(controller_id)
        return render_template("crossconnections/new.html", form = f, controller = c)

    f = CrossconnectionForm(request.form)
    f.setupChoices(controller_id)
    if not f.validate():
        c = Controller.query.get(controller_id)
        return render_template("crossconnections/new.html", form = f, controller = c)
    if not f.validate2():
        c = Controller.query.get(controller_id)
        return render_template("crossconnections/new.html", form = f, controller = c)
    
    cc = Crossconnection(controller_id, f.thread_a_id.data, f.thread_b_id.data, f.device_a.data, f.device_b.data)
    db.session().add(cc)
    db.session().commit()

    log = Changelog(current_user.id, "Crossconnection", "", cc.id, "Create", "", "")
    db.session().add(log)
    db.session().commit()

    return redirect(url_for("controllers_view_one", controller_id = controller_id))
Beispiel #7
0
def controllers_edit_one(controller_id):
    if request.method == "GET":
        return render_template("controllers/edit.html",
                               form=ControllerForm(),
                               controller=Controller.query.get(controller_id))

    f = ControllerForm(request.form)
    c = Controller.query.get(controller_id)

    #Validoidaan ControllerFormin sisältämien kenttien datat, jos
    #niissä on häikkää, niin palautetaan controllers/edit.html sivu
    #virheviestin kera.
    if not f.validate():
        return render_template("controllers/edit.html",
                               form=f,
                               controller=Controller.query.get(controller_id))
    nameNotEdited = True
    if (c.name != f.name.data):
        nameNotEdited = False
    if not f.validate2(nameNotEdited):
        return render_template("controllers/edit.html", form=f, controller=c)

    if (c.name != f.name.data):
        log = Changelog(current_user.id, "Controller", "name", c.id, "Update",
                        c.name, f.name.data)
        db.session().add(log)
        c.name = f.name.data
    if (c.note != f.note.data):
        log = Changelog(current_user.id, "Controller", "note", c.id, "Update",
                        c.note, f.note.data)
        db.session().add(log)
        c.note = f.note.data
    if (c.x != f.x.data):
        log = Changelog(current_user.id, "Controller", "x", c.id, "Update",
                        c.x, f.x.data)
        db.session().add(log)
        c.x = f.x.data
    if (c.y != f.y.data):
        log = Changelog(current_user.id, "Controller", "y", c.id, "Update",
                        c.y, f.y.data)
        db.session().add(log)
        c.y = f.y.data

    db.session().commit()

    return redirect(url_for("controllers_index"))
Beispiel #8
0
def crossconnections_delete(crossconnection_id): 
    c = Crossconnection.query.get(crossconnection_id)
    controller_id = c.controller_id
    log = None
    if c.thread_a_id == 0:
        cable_b = Cable.query.get(Thread.query.get(c.thread_b_id).cable_id)
        log = Changelog(current_user.id, "Crossconnection", "", 0, "Delete", " -- "+cable_b.name + "/" +str(Thread.query.get(c.thread_b_id).socket_a), "")
        
    elif c.thread_b_id == 0:
        cable_a = Cable.query.get(Thread.query.get(c.thread_a_id).cable_id)
        log = Changelog(current_user.id, "Crossconnection", "", 0, "Delete", cable_a.name + "/" +str(Thread.query.get(c.thread_a_id).socket_a) + " -- ", "")
    else:
        cable_a = Cable.query.get(Thread.query.get(c.thread_a_id).cable_id)
        cable_b = Cable.query.get(Thread.query.get(c.thread_b_id).cable_id)
        log = Changelog(current_user.id, "Crossconnection", "", 0, "Delete", cable_a.name + "/" +str(Thread.query.get(c.thread_a_id).socket_a) + " -- "+cable_b.name + "/" +str(Thread.query.get(c.thread_b_id).socket_a), "")
    
    Crossconnection.query.filter_by(id=c.id).delete()
    db.session().add(log)   
    db.session().commit()
    return redirect(url_for("controllers_view_one", controller_id = controller_id))
Beispiel #9
0
def crossconnections_edit_one(crossconnection_id):
    if request.method == "GET":
        c = Crossconnection.query.get(crossconnection_id)
        f = CrossconnectionForm()
        f.setupChoices(c.controller_id)
        f.thread_a_id.default=c.thread_a_id
        f.thread_b_id.default=c.thread_b_id
        f.process()
        return render_template("crossconnections/edit.html", form = f, crossconnection = c)

    f = CrossconnectionForm(request.form)
    c = Crossconnection.query.get(crossconnection_id)
    #Validoidaan CrossconnectionFormin sisältämien kenttien datat, jos
    #niissä on häikkää, niin palautetaan cables/edit.html sivu
    #virheviestin kera.
    f.setupChoices(c.controller_id)
    if not f.validate():
        return render_template("crossconnections/edit.html", form = f, crossconnection = c)
    if not f.validate2():
        return render_template("crossconnections/edit.html", form = f, crossconnection = c)
    
    if(c.thread_a_id != f.thread_a_id.data):
        log = Changelog(current_user.id, "Crossconnection", "thread_a_id", c.id, "Update", c.thread_a_id, f.thread_a_id.data)
        db.session().add(log)  
        c.thread_a_id = f.thread_a_id.data
    if(c.thread_b_id != f.thread_b_id.data):
        log = Changelog(current_user.id, "Crossconnection", "thread_b_id", c.id, "Update", c.thread_b_id, f.thread_b_id.data)
        db.session().add(log)  
        c.thread_b_id = f.thread_b_id.data
    if(c.device_a != f.device_a.data):
        log = Changelog(current_user.id, "Crossconnection", "device_a", c.id, "Update", c.device_a, f.device_a.data)
        db.session().add(log)  
        c.device_a = f.device_a.data
    if(c.device_b != f.device_b.data):
        log = Changelog(current_user.id, "Crossconnection", "device_b", c.id, "Update", c.device_b, f.device_b.data)
        db.session().add(log)  
        c.device_b = f.device_b.data

    db.session().commit()

    return redirect(url_for("controllers_view_one", controller_id = c.controller_id))
Beispiel #10
0
def controllers_create():
    f = ControllerForm(request.form)

    #Validoidaan ControllerFormin sisältämien kenttien datat, jos
    #niissä on häikkää, niin palautetaan controllers/new.html sivu
    #virheviestin kera.
    if not f.validate():
        return render_template("controllers/new.html", form=f)
    if not f.validate2(False):
        return render_template("controllers/new.html", form=f)

    c = Controller(f.name.data, f.note.data, f.x.data, f.y.data)
    db.session().add(c)
    db.session().commit()

    log = Changelog(current_user.id, "Controller", "", c.id, "Create", "", "")
    db.session().add(log)
    db.session().commit()

    return redirect(url_for("controllers_index"))
Beispiel #11
0
def threads_edit_one(thread_id):
    if request.method == "GET":
        f = ThreadForm()
        t = Thread.query.get(thread_id)
        return render_template("threads/edit.html", form=f, thread=t)

    f = ThreadForm(request.form)
    t = Thread.query.get(thread_id)

    #Validoidaan ThreadFormin sisältämien kenttien datat, jos
    #niissä on häikkää, niin palautetaan threads/edit.html sivu
    #virheviestin kera.
    if not f.validate():
        return render_template("threads/edit.html", form=f, thread=t)

    if (t.number_a != f.number_a.data):
        log = Changelog(current_user.id, "Thread", "number_a", t.id, "Update",
                        t.number_a, f.number_a.data)
        db.session().add(log)
        t.number_a = f.number_a.data
    if (t.number_b != f.number_b.data):
        log = Changelog(current_user.id, "Thread", "number_b", t.id, "Update",
                        t.number_b, f.number_b.data)
        db.session().add(log)
        t.number_b = f.number_b.data
    if (t.socket_a != f.socket_a.data):
        log = Changelog(current_user.id, "Thread", "socket_a", t.id, "Update",
                        t.socket_a, f.socket_a.data)
        db.session().add(log)
        t.socket_a = f.socket_a.data
    if (t.socket_b != f.socket_b.data):
        log = Changelog(current_user.id, "Thread", "socket_b", t.id, "Update",
                        t.socket_b, f.socket_b.data)
        db.session().add(log)
        t.socket_b = f.socket_b.data
    if (t.data != f.data.data):
        log = Changelog(current_user.id, "Thread", "data", t.id, "Update",
                        t.data, f.data.data)
        db.session().add(log)
        t.data = f.data.data
    if (t.note != f.note.data):
        log = Changelog(current_user.id, "Thread", "note", t.id, "Update",
                        t.note, f.note.data)
        db.session().add(log)
        t.note = f.note.data

    db.session().commit()

    return redirect(url_for("cables_view_one", cable_id=t.cable_id))
Beispiel #12
0
def changelog_index():
    f = SearchForm()
    f.setupChoices()
    return render_template("changelog/list.html",
                           changes=Changelog.findAll(),
                           form=f)