Ejemplo n.º 1
0
def view(request, tablename=None, rowid=None):
    klass = get_model(tablename)
    dbrow = webhelpers.get_row(klass, rowid)
    resp = framework.ResponseDocument(request,
                                      doc_constructor,
                                      title="Table %s %s" % (tablename, dbrow))
    NM = resp.nodemaker
    resp.new_para((
        NM("A", {"href": request.get_url(addentry, tablename=tablename)},
           resp.get_icon("add")),
        NM("A",
           {"href": request.get_url(edit, tablename=tablename, rowid=rowid)},
           resp.get_icon("edit")),
        NM("A",
           {"href": "javascript:doDeleteItem(%r, %r);" % (tablename, rowid)},
           resp.get_icon("delete")),
    ))
    cycler = itertools.cycle(["row1", "row2"])
    tbl = resp.doc.add_table(width="100%", class_="rowdisplay")
    tbl.caption("%s #%s" % (tablename, rowid))
    tbl.new_headings("Field", "Value")
    for metadata in sorted(models.get_metadata(klass)):
        row = tbl.new_row()
        setattr(row, "class_", cycler.next())
        row.new_column(metadata.colname)
        row.new_column(str(getattr(dbrow, metadata.colname)))
    return resp.finalize()
Ejemplo n.º 2
0
def updaterow(modelname, entry_id, data):
    klass = get_model(modelname)
    dbrow = webhelpers.get_row(klass, entry_id)
    try:
        webhelpers.update_row_from_data(data, klass, dbrow)
    except types.ValidationError, err:
        webhelpers.dbsession.rollback()
        logging.error(err)
        return False
Ejemplo n.º 3
0
 def get(self, request, tablename=None, rowid=None):
     klass = get_model(tablename)
     dbrow = webhelpers.get_row(klass, rowid)
     title = "Edit %s %s" % (tablename, dbrow)
     resp = self.get_response(request, title=title)
     resp.new_para(title)
     form = resp.add_form(action=request.get_url(edit, tablename=tablename, rowid=rowid))
     webhelpers.build_edit_form(form, klass, dbrow)
     return resp.finalize()
Ejemplo n.º 4
0
def related_add(modelname, entry_id, colname, relmodelname, rel_id):
    klass = get_model(modelname)
    relklass = get_model(relmodelname)
    metadata = models.get_column_metadata(klass, colname)
    # fetch parent and related objects
    dbrow = webhelpers.get_row(klass, entry_id)
    reldbrow = webhelpers.get_row(relklass, rel_id)
    # now add using appropriate semantics
    if metadata.uselist:
        col = getattr(dbrow, colname)
        col.append(reldbrow)
    else:
        setattr(dbrow, colname, reldbrow)
    try:
        webhelpers.dbsession.commit()
    except (DataError, IntegrityError), err:
        webhelpers.dbsession.rollback()
        raise
Ejemplo n.º 5
0
def related_remove(modelname, entry_id, colname, relmodelname, rel_id):
    klass = get_model(modelname)
    relklass = get_model(relmodelname)
    metadata = models.get_column_metadata(klass, colname)
    # fetch parent and related objects
    dbrow = webhelpers.get_row(klass, entry_id)
    if metadata.uselist:
        reldbrow = webhelpers.get_row(relklass, rel_id)
        col = getattr(dbrow, colname)
        col.remove(reldbrow)
    else:
        if metadata.nullable:
            setattr(dbrow, colname, None)
        else:
            raise DataError("Removing non-nullable relation")
    try:
        webhelpers.dbsession.commit()
    except (DataError, IntegrityError), err:
        webhelpers.dbsession.rollback()
        raise
Ejemplo n.º 6
0
 def post(self, request, tablename=None, rowid=None):
     klass = get_model(tablename)
     dbrow = webhelpers.get_row(klass, rowid)
     try:
         webhelpers.update_row(request.POST, klass, dbrow)
     except types.ValidationError, err:
         webhelpers.dbsession.rollback()
         title = "Re-edit %s %s" % (tablename, dbrow)
         resp = self.get_response(request, title=title)
         resp.new_para(title)
         form = resp.add_form(action=request.get_url(edit, tablename=tablename, rowid=rowid))
         webhelpers.build_edit_form(form, klass, dbrow, err)
         return resp.finalize()
Ejemplo n.º 7
0
def view(request, tablename=None, rowid=None):
    klass = get_model(tablename)
    dbrow = webhelpers.get_row(klass, rowid)
    resp = framework.ResponseDocument(request, doc_constructor,
             title="Table %s %s" % (tablename, dbrow))
    NM = resp.nodemaker
    resp.new_para(
            (NM("A", {"href": request.get_url(addentry, tablename=tablename)},
                resp.get_icon("add")),
            NM("A", {"href": request.get_url(edit, tablename=tablename, rowid=rowid)},
                resp.get_icon("edit")),
            NM("A", {"href": "javascript:doDeleteItem(%r, %r);" % (tablename, rowid)},
                resp.get_icon("delete")),
            ))
    cycler = itertools.cycle(["row1", "row2"])
    tbl = resp.doc.add_table(width="100%", class_="rowdisplay")
    tbl.caption("%s #%s" % (tablename, rowid))
    tbl.new_headings("Field", "Value")
    for metadata in sorted(models.get_metadata(klass)):
        row = tbl.new_row()
        setattr(row, "class_", cycler.next())
        row.new_column(metadata.colname)
        row.new_column(str(getattr(dbrow, metadata.colname)))
    return resp.finalize()
Ejemplo n.º 8
0
def get_row(modelname, entry_id):
    klass = get_model(modelname)
    return webhelpers.get_row(klass, entry_id)