def remove(key, tbl_name): """ Delete the <key> element in the <tbl_name> """ tbl_object = get_tbl_object(tbl_name) current = tbl_object.query.filter(tbl_object.primary_key + " == '" + key + "'").first() db_session.delete(current) db_session.commit() return redirect(get_listing_redirection(tbl_name))
def list_data(tbl_name): """ List data in table name """ try: tbl_object = get_tbl_object(tbl_name) objects = tbl_object.query.all() return render_template('list.html', list=objects, headers=tbl_object.header, action=tbl_name, key=tbl_object.primary_key) except Exception as e: return redirect(url_for('csoGestion.index'))
def add(tbl_name): """ Add a new entry in the tbl_name """ try: tbl_object = get_tbl_object(tbl_name) return render_template('formulaire.html', headers=tbl_object.header, is_boolean=tbl_object.is_boolean, action=tbl_name, object={}, key=tbl_object.primary_key, actionType="Ajouter") except Exception as e: return redirect(url_for('csoGestion.index'))
def get(tbl_name, get_element): """ Get a specific element in the tbl_name """ try: tbl_object = get_tbl_object(tbl_name) current = tbl_object.query.filter(tbl_object.primary_key + " == '" + get_element + "'").first() return render_template('formulaire.html', headers=tbl_object.header, is_boolean=tbl_object.is_boolean, action=tbl_name, key=tbl_object.primary_key, actionType="Modifier", object=current) except Exception as e: return redirect(url_for('csoGestion.index'))
def save(tbl_name): """ Save or update the Post data in the tbl_name """ post_value = request.form tbl_Object = get_tbl_object(tbl_name)() # Fill the object with post data for curHeader in tbl_Object.header: if post_value[curHeader] == "": val = None else: val = post_value[curHeader] setattr(tbl_Object, curHeader, val) # Save the object try: db_session.merge(tbl_Object) db_session.commit() except: db_session.rollback() return redirect(get_listing_redirection(tbl_name))