Ejemplo n.º 1
0
def delete(instance, obj_id):
    obj = Record().give_child(instance)
    obj = obj.get_by_id_or_new(obj_id)
    obj.delete()
    if not request.is_xhr:
        return redirect('index/'+repr(obj))
    else:
        return "it ok"
Ejemplo n.º 2
0
def instantiate_and_form(request, instance, obj_id=None):
    """
    Abstracts common operations from actions add/<instance>, edit/<instance>.
    Instantiates blank model object obj by it's string name (i. e.
    instance=book will produce obj=Book()). Instantiates corresponding
    WTForm model_form object form. If obj_id provided, tries to populate
    obj with database data.
    Populates form with request.from data (if any). Than tries to modify
    obj with data in form. Returns ready to use obj, form to caller.
    """
    obj = Record().give_child(instance)
    form = obj.give_form()
    obj = obj.get_by_id_or_new(obj_id)
    form = form(request.form, obj=obj)
    obj.populate_with(form)
    return obj, form