def limit_validation_results(validation):
 messages = validation['messages']
 lim = settings.VALIDATOR_MESSAGE_LIMIT
 if (lim and (len(messages) > lim)):
  TYPES = {'error': 0, 'warning': 2, 'notice': 3}
  def message_key(message):
   if message.get('signing_severity'):
    return 1
   else:
    return TYPES.get(message.get('type'))
  messages.sort(key=message_key)
  leftover_count = (len(messages) - lim)
  del messages[lim:]
  if validation['errors']:
   msg_type = 'error'
  elif validation['warnings']:
   msg_type = 'warning'
  else:
   msg_type = 'notice'
  compat_type = (msg_type if any((msg.get('compatibility_type') for msg in messages)) else None)
  messages.insert(0, {'tier': 1, 'type': msg_type, 'id': ['validation', 'messages', 'truncated'], 'message': (_("Validation generated too many errors/warnings so %s messages were truncated. After addressing the visible messages, you'll be able to see the others.") % leftover_count), 'description': [], 'compatibility_type': compat_type})

def limit_validation_results ( validation ) : messages = validation [ 'messages' ] lim = settings . VALIDATOR_MESSAGE_LIMIT if ( lim and ( len ( messages ) > lim ) ) : TYPES = { 'error' : 0 , 'warning' : 2 , 'notice' : 3 } def message_key ( message ) : if message . get ( 'signing_severity' ) : return 1 else : return TYPES . get ( message . get ( 'type' ) ) messages . sort ( key = message_key ) leftover_count = ( len ( messages ) - lim ) del messages [ lim : ] if validation [ 'errors' ] : msg_type = 'error' elif validation [ 'warnings' ] : msg_type = 'warning' else : msg_type = 'notice' compat_type = ( msg_type if any ( ( msg . get ( 'compatibility_type' ) for msg in messages ) ) else None ) messages . insert ( 0 , { 'tier' : 1 , 'type' : msg_type , 'id' : [ 'validation' , 'messages' , 'truncated' ] , 'message' : ( _ ( "Validation generated too many errors/warnings so %s messages were truncated. After addressing the visible messages, you'll be able to see the others." ) % leftover_count ) , 'description' : [ ] , 'compatibility_type' : compat_type } )
limit the number of messages displayed in a set of validation results .