docs: def apply_template_to_network(template_id, network_id, **kwargs):
      """
          For each node and link in a network, check whether it matches
          a type in a given template. If so, assign the type to the node / link.
      """
  
      net_i = db.DBSession.query(Network).filter(Network.id==network_id).one()
      #There should only ever be one matching type, but if there are more,
      #all we can do is pick the first one.
      try:
          network_type_id = db.DBSession.query(TemplateType.id).filter(TemplateType.template_id==template_id,
                                                                         TemplateType.resource_type=='NETWORK').one()
          assign_type_to_resource(network_type_id.id, 'NETWORK', network_id,**kwargs)
      except NoResultFound:
          log.debug("No network type to set.")
          pass
  
      for node_i in net_i.nodes:
          templates = get_types_by_attr(node_i, template_id)
          if len(templates) > 0:
              assign_type_to_resource(templates[0].id, 'NODE', node_i.id,**kwargs)
      for link_i in net_i.links:
          templates = get_types_by_attr(link_i, template_id)
          if len(templates) > 0:
              assign_type_to_resource(templates[0].id, 'LINK', link_i.id,**kwargs)
  
      for group_i in net_i.resourcegroups:
          templates = get_types_by_attr(group_i, template_id)
          if len(templates) > 0:
              assign_type_to_resource(templates[0].id, 'GROUP', group_i.id,**kwargs)
  
      db.DBSession.flush()