def add_views_to_resource(context, resource_dict, dataset_dict=None, view_types=[], create_datastore_views=False):
 if (not dataset_dict):
  dataset_dict = logic.get_action('package_show')(context, {'id': resource_dict['package_id']})
 if (not view_types):
  view_plugins = get_default_view_plugins(create_datastore_views)
 else:
  view_plugins = get_view_plugins(view_types)
 if (not view_plugins):
  return []
 existing_views = p.toolkit.get_action('resource_view_list')(context, {'id': resource_dict['id']})
 existing_view_types = ([v['view_type'] for v in existing_views] if existing_views else [])
 created_views = []
 for view_plugin in view_plugins:
  view_info = view_plugin.info()
  if (view_info['name'] in existing_view_types):
   continue
  if view_plugin.can_view({'resource': resource_dict, 'package': dataset_dict}):
   view = {'resource_id': resource_dict['id'], 'view_type': view_info['name'], 'title': view_info.get('default_title', _('View')), 'description': view_info.get('default_description', '')}
   view_dict = p.toolkit.get_action('resource_view_create')(context, view)
   created_views.append(view_dict)
 return created_views

def add_views_to_resource ( context , resource_dict , dataset_dict = None , view_types = [ ] , create_datastore_views = False ) : if ( not dataset_dict ) : dataset_dict = logic . get_action ( 'package_show' ) ( context , { 'id' : resource_dict [ 'package_id' ] } ) if ( not view_types ) : view_plugins = get_default_view_plugins ( create_datastore_views ) else : view_plugins = get_view_plugins ( view_types ) if ( not view_plugins ) : return [ ] existing_views = p . toolkit . get_action ( 'resource_view_list' ) ( context , { 'id' : resource_dict [ 'id' ] } ) existing_view_types = ( [ v [ 'view_type' ] for v in existing_views ] if existing_views else [ ] ) created_views = [ ] for view_plugin in view_plugins : view_info = view_plugin . info ( ) if ( view_info [ 'name' ] in existing_view_types ) : continue if view_plugin . can_view ( { 'resource' : resource_dict , 'package' : dataset_dict } ) : view = { 'resource_id' : resource_dict [ 'id' ] , 'view_type' : view_info [ 'name' ] , 'title' : view_info . get ( 'default_title' , _ ( 'View' ) ) , 'description' : view_info . get ( 'default_description' , '' ) } view_dict = p . toolkit . get_action ( 'resource_view_create' ) ( context , view ) created_views . append ( view_dict ) return created_views
creates the provided views on the provided resource views to create are provided as a list of view_types .