#NEWLINE# def serialize_user( user , node = None , admin = False , full = False , is_profile = False ) : #NEWLINE# #INDENT# '\n    Return a dictionary representation of a registered user.\n\n    :param User user: A User object\n    :param bool full: Include complete user properties\n    ' #NEWLINE# fullname = user . display_full_name ( node = node ) #NEWLINE# ret = { #NEWLINE# #INDENT# 'id' : str ( user . _primary_key ) , #NEWLINE# 'registered' : user . is_registered , #NEWLINE# 'surname' : user . family_name , #NEWLINE# 'fullname' : fullname , #NEWLINE# 'shortname' : ( fullname if ( len ( fullname ) < 50 ) else ( ( fullname [ : 23 ] + '...' ) + fullname [ ( - 23 ) : ] ) ) , #NEWLINE# 'gravatar_url' : gravatar ( user , use_ssl = True , size = settings . PROFILE_IMAGE_MEDIUM ) , #NEWLINE# 'active' : user . is_active , #NEWLINE# #UNINDENT# } #NEWLINE# if ( node is not None ) : #NEWLINE# #INDENT# if admin : #NEWLINE# #INDENT# flags = { #NEWLINE# #INDENT# 'visible' : False , #NEWLINE# 'permission' : 'read' , #NEWLINE# #UNINDENT# } #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# flags = { #NEWLINE# #INDENT# 'visible' : ( user . _id in node . visible_contributor_ids ) , #NEWLINE# 'permission' : reduce_permissions ( node . get_permissions ( user ) ) , #NEWLINE# #UNINDENT# } #NEWLINE# #UNINDENT# ret . update ( flags ) #NEWLINE# #UNINDENT# if user . is_registered : #NEWLINE# #INDENT# ret . update ( { #NEWLINE# #INDENT# 'url' : user . url , #NEWLINE# 'absolute_url' : user . absolute_url , #NEWLINE# 'display_absolute_url' : user . display_absolute_url , #NEWLINE# 'date_registered' : user . date_registered . strftime ( '%Y-%m-%d' ) , #NEWLINE# #UNINDENT# } ) #NEWLINE# #UNINDENT# if full : #NEWLINE# #INDENT# if each : #NEWLINE# #INDENT# ret [ 'emails' ] = ( [ { #NEWLINE# #INDENT# 'address' : each , #NEWLINE# 'primary' : ( each . strip ( ) . lower ( ) == user . username . strip ( ) . lower ( ) ) , #NEWLINE# 'confirmed' : True , #NEWLINE# #UNINDENT# } for each in user . emails ] + [ { #NEWLINE# #INDENT# 'address' : each , #NEWLINE# 'primary' : ( each . strip ( ) . lower ( ) == user . username . strip ( ) . lower ( ) ) , #NEWLINE# 'confirmed' : False , #NEWLINE# #UNINDENT# } for each in user . unconfirmed_emails ] ) #NEWLINE# #UNINDENT# if user . is_merged : #NEWLINE# #INDENT# merger = user . merged_by #NEWLINE# merged_by = { #NEWLINE# #INDENT# 'id' : str ( merger . _primary_key ) , #NEWLINE# 'url' : merger . url , #NEWLINE# 'absolute_url' : merger . absolute_url , #NEWLINE# #UNINDENT# } #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# merged_by = None #NEWLINE# #UNINDENT# ret . update ( { #NEWLINE# #INDENT# 'number_projects' : len ( get_projects ( user ) ) , #NEWLINE# 'number_public_projects' : len ( get_public_projects ( user ) ) , #NEWLINE# 'activity_points' : user . get_activity_points ( ) , #NEWLINE# 'gravatar_url' : gravatar ( user , use_ssl = True , size = settings . PROFILE_IMAGE_LARGE ) , #NEWLINE# 'is_merged' : user . is_merged , #NEWLINE# 'merged_by' : merged_by , #NEWLINE# #UNINDENT# } ) #NEWLINE# #UNINDENT# return ret