def set_attributes(layer, attribute_map, overwrite=False, attribute_stats=None):
 from geonode.layers.models import Attribute
 attribute_map_dict = {'field': 0, 'ftype': 1, 'description': 2, 'label': 3, 'display_order': 4}
 for attribute in attribute_map:
  attribute.extend((None, None, 0))
 attributes = layer.attribute_set.all()
 for la in attributes:
  lafound = False
  for attribute in attribute_map:
   (field, ftype, description, label, display_order) = attribute
   if (field == la.attribute):
    lafound = True
    attribute[attribute_map_dict['description']] = la.description
    attribute[attribute_map_dict['label']] = la.attribute_label
    attribute[attribute_map_dict['display_order']] = la.display_order
  if (overwrite or (not lafound)):
   logger.debug('Going to delete [%s] for [%s]', la.attribute, layer.name.encode('utf-8'))
   la.delete()
 if (attribute_map is not None):
  iter = (len(Attribute.objects.filter(layer=layer)) + 1)
  for attribute in attribute_map:
   (field, ftype, description, label, display_order) = attribute
   if (field is not None):
    (la, created) = Attribute.objects.get_or_create(layer=layer, attribute=field, attribute_type=ftype, description=description, attribute_label=label, display_order=display_order)
    if created:
     if ((not attribute_stats) or (layer.name not in attribute_stats) or (field not in attribute_stats[layer.name])):
      result = None
     else:
      result = attribute_stats[layer.name][field]
     if (result is not None):
      logger.debug('Generating layer attribute statistics')
      la.count = result['Count']
      la.min = result['Min']
      la.max = result['Max']
      la.average = result['Average']
      la.median = result['Median']
      la.stddev = result['StandardDeviation']
      la.sum = result['Sum']
      la.unique_values = result['unique_values']
      la.last_stats_updated = datetime.datetime.now()
     la.visible = (ftype.find('gml:') != 0)
     la.display_order = iter
     la.save()
     iter += 1
     logger.debug('Created [%s] attribute for [%s]', field, layer.name.encode('utf-8'))
 else:
  logger.debug('No attributes found')

def set_attributes ( layer , attribute_map , overwrite = False , attribute_stats = None ) : from geonode . layers . models import Attribute attribute_map_dict = { 'field' : 0 , 'ftype' : 1 , 'description' : 2 , 'label' : 3 , 'display_order' : 4 } for attribute in attribute_map : attribute . extend ( ( None , None , 0 ) ) attributes = layer . attribute_set . all ( ) for la in attributes : lafound = False for attribute in attribute_map : ( field , ftype , description , label , display_order ) = attribute if ( field == la . attribute ) : lafound = True attribute [ attribute_map_dict [ 'description' ] ] = la . description attribute [ attribute_map_dict [ 'label' ] ] = la . attribute_label attribute [ attribute_map_dict [ 'display_order' ] ] = la . display_order if ( overwrite or ( not lafound ) ) : logger . debug ( 'Going to delete [%s] for [%s]' , la . attribute , layer . name . encode ( 'utf-8' ) ) la . delete ( ) if ( attribute_map is not None ) : iter = ( len ( Attribute . objects . filter ( layer = layer ) ) + 1 ) for attribute in attribute_map : ( field , ftype , description , label , display_order ) = attribute if ( field is not None ) : ( la , created ) = Attribute . objects . get_or_create ( layer = layer , attribute = field , attribute_type = ftype , description = description , attribute_label = label , display_order = display_order ) if created : if ( ( not attribute_stats ) or ( layer . name not in attribute_stats ) or ( field not in attribute_stats [ layer . name ] ) ) : result = None else : result = attribute_stats [ layer . name ] [ field ] if ( result is not None ) : logger . debug ( 'Generating layer attribute statistics' ) la . count = result [ 'Count' ] la . min = result [ 'Min' ] la . max = result [ 'Max' ] la . average = result [ 'Average' ] la . median = result [ 'Median' ] la . stddev = result [ 'StandardDeviation' ] la . sum = result [ 'Sum' ] la . unique_values = result [ 'unique_values' ] la . last_stats_updated = datetime . datetime . now ( ) la . visible = ( ftype . find ( 'gml:' ) != 0 ) la . display_order = iter la . save ( ) iter += 1 logger . debug ( 'Created [%s] attribute for [%s]' , field , layer . name . encode ( 'utf-8' ) ) else : logger . debug ( 'No attributes found' )
set attributes on an sqs queue .