In general that seems fine. Note, in this case, you can also simplify to: {{if auth.user_id == mytable.author_id:}}
This is because auth.user_id returns the id of the current logged in user or None if the user isn't logged in. Of course, this assumes mytable.author_id is never None -- if it is, you would need: {{if auth.user and auth.user.id == mytable.author_id:}} Anthony On Wednesday, December 7, 2011 11:33:44 AM UTC-5, thodoris wrote: > > I have found myself doing multiple times in my views: > > {{if auth.user:}} # checking that a user in logged in and > {{if auth.user.id == my_table.author_id:}} # if he is the author of a > table entry > SHOW SOMETHING ONLY TO THE AUTHOR OF THIS TABLE > {{pass}} > {{pass}} > > I am thinking that repeating myself is a bad code practice and i am going > to make a function like > > is_author(auth.user, my_table.author_id) > > and in the view have > > {{if is_author(...):}} > > Could i hear some opinions on that? > > Also if there are parts of code that appear in multiple views, is it > better to make a function that returns html code in order to make the code > better??? >