def _serialize_discussion_entities(request, context, discussion_entities, requested_fields, discussion_entity_type):
 results = []
 usernames = []
 include_profile_image = _include_profile_image(requested_fields)
 for entity in discussion_entities:
  if (discussion_entity_type == DiscussionEntity.thread):
   serialized_entity = ThreadSerializer(entity, context=context).data
  elif (discussion_entity_type == DiscussionEntity.comment):
   serialized_entity = CommentSerializer(entity, context=context).data
  results.append(serialized_entity)
  if include_profile_image:
   if (serialized_entity['author'] and (serialized_entity['author'] not in usernames)):
    usernames.append(serialized_entity['author'])
   if (('endorsed' in serialized_entity) and serialized_entity['endorsed'] and ('endorsed_by' in serialized_entity) and serialized_entity['endorsed_by'] and (serialized_entity['endorsed_by'] not in usernames)):
    usernames.append(serialized_entity['endorsed_by'])
 results = _add_additional_response_fields(request, results, usernames, discussion_entity_type, include_profile_image)
 return results

def _serialize_discussion_entities ( request , context , discussion_entities , requested_fields , discussion_entity_type ) : results = [ ] usernames = [ ] include_profile_image = _include_profile_image ( requested_fields ) for entity in discussion_entities : if ( discussion_entity_type == DiscussionEntity . thread ) : serialized_entity = ThreadSerializer ( entity , context = context ) . data elif ( discussion_entity_type == DiscussionEntity . comment ) : serialized_entity = CommentSerializer ( entity , context = context ) . data results . append ( serialized_entity ) if include_profile_image : if ( serialized_entity [ 'author' ] and ( serialized_entity [ 'author' ] not in usernames ) ) : usernames . append ( serialized_entity [ 'author' ] ) if ( ( 'endorsed' in serialized_entity ) and serialized_entity [ 'endorsed' ] and ( 'endorsed_by' in serialized_entity ) and serialized_entity [ 'endorsed_by' ] and ( serialized_entity [ 'endorsed_by' ] not in usernames ) ) : usernames . append ( serialized_entity [ 'endorsed_by' ] ) results = _add_additional_response_fields ( request , results , usernames , discussion_entity_type , include_profile_image ) return results
it serializes discussion entity and add additional data if requested .