def edit():
    name = request.args['name']
    _id = request.args['uuid']
    Component = models.components[name]
    Form = forms.create_component_form(Component)
    form = Form()
    component = Component.query.get(_id)
    if form.validate_on_submit():
        form.populate_obj(component)
        db.session.add(component)
        db.session.commit()
        flash("The component was edited successfully.", "success")
        return redirect(url_for('table', name=name))
    form = Form(obj=component)
    return render_template('edit.html',  tables = models.components.keys(), form=form, sch=library.sym, ftpt=library.ftpt)
def new():
    name = request.args['name']
    Component = models.components[name]
    Form = forms.create_component_form(Component)

    # Pop the form with template data if this is a duplicate
    template = request.args.get('template', None)        
    if template:
        template_component = Component.query.get(int(template))
        form = Form(obj=template_component)
    else:
        form = Form()

    if form.validate_on_submit():
        component = Component()
        form.populate_obj(component)
        component.uuid = str(uuid.uuid4())
        db.session.add(component)
        db.session.commit()
        flash('The new component was created successfully.', 'success')
        return redirect(url_for('table', name=name))
    return render_template('edit.html',  tables = models.components.keys(), form=form, sch=library.sym, ftpt=library.ftpt)