I would suggest something like this (not tested and I don't know if I got 
the logic correct):

def index(): 
    session.sort = request.vars.sort or 'Views'
    if session.sort=='Date':
        rows=db().select(db.Article.ALL, orderby=~db.Article.Submitted,
            limitby=(0,5))
    else:
        rows=db().select(db.Article.ALL, orderby=~db.Article.Submitted,
            limitby=(0,5)).sort(lambda row:row.Views, reverse=True)
    return dict(Articles=rows)


{{extend 'layout.html'}}
<h1>Index</h1>
<div class='Myheader'>
sort by
{{if session.sort=='Date':}}
    {{=A('Views', _href=URL('index'), vars={'sort': 'Views'})}}
{{else:}}
    {{=A('Date', _href=URL('index'), vars={'sort': 'Date'})}}
{{pass}}
</div><br>
latest articles sorted by {{=session.sort}}:<br><br>
{{for i in Articles:}}
    {{=i.Title}} <br>
{{pass}}

Reply via email to