@contextfunction
def messaging_unread(context):
 request = context['request']
 user = None
 if request.user.username:
  try:
   user = request.user.profile
  except Exception:
   pass
 unread = 0
 messaging = None
 if user:
  modules = user.get_perspective().get_modules()
  messaging = modules.filter(name='treeio.messaging')
  if messaging:
   unread = Object.filter_permitted(user, Message.objects.filter(reply_to__isnull=True).exclude(read_by=user)).count()
 response_format = 'html'
 if ('response_format' in context):
  response_format = context['response_format']
 return Markup(render_to_string('messaging/tags/unread', {'messaging': messaging, 'unread': unread}, context_instance=RequestContext(request), response_format=response_format))

@ contextfunction def messaging_unread ( context ) : request = context [ 'request' ] user = None if request . user . username : try : user = request . user . profile except Exception : pass unread = 0 messaging = None if user : modules = user . get_perspective ( ) . get_modules ( ) messaging = modules . filter ( name = 'treeio.messaging' ) if messaging : unread = Object . filter_permitted ( user , Message . objects . filter ( reply_to__isnull = True ) . exclude ( read_by = user ) ) . count ( ) response_format = 'html' if ( 'response_format' in context ) : response_format = context [ 'response_format' ] return Markup ( render_to_string ( 'messaging/tags/unread' , { 'messaging' : messaging , 'unread' : unread } , context_instance = RequestContext ( request ) , response_format = response_format ) )
print a number of unread messages .