Usefult shortcuts to define in the model:

user_id = auth.user.id if auth.user else 0
item_id = request.args[0] if request.args else 0
now = request.now

def url(f,args=[]):
    return URL(r=request,f=f,args=args)

def goto(f,args=[],flash=None):
    """ usage: goto('index',flash='hello world') """
    if flash: session.flash=flash
    redirect(url(f,args))

def unique(field):
    """ usage: unique(db.table.field) """
    field.requires = [IS_NOT_EMPTY(),IS_NOT_IN_DB(field._db,field)]

def linked(field, name='name'):
    """ usage: linked(db.table.field) """
    tablename = field.type[10:]
    keys='%%(%s)s' % name
    field.requires = IS_IN_DB(field._db,tablename+'.id',keys)

def editable(field):
    """ usage: editable(db.table.id) makes a [edit] close to the ID in
tables."""
    field.represent=lambda value,field=field: SPAN(value,' [',A
('edit',_href=url('update',[field._tablename,value])),']')


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"web2py Web Framework" group.
To post to this group, send email to web2py@googlegroups.com
To unsubscribe from this group, send email to 
web2py+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/web2py?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to