當前位置: 首頁>>代碼示例>>Python>>正文


Python Node.layer_name方法代碼示例

本文整理匯總了Python中nodeshot.core.nodes.models.Node.layer_name方法的典型用法代碼示例。如果您正苦於以下問題:Python Node.layer_name方法的具體用法?Python Node.layer_name怎麽用?Python Node.layer_name使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在nodeshot.core.nodes.models.Node的用法示例。


在下文中一共展示了Node.layer_name方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: get_nodes

# 需要導入模塊: from nodeshot.core.nodes.models import Node [as 別名]
# 或者: from nodeshot.core.nodes.models.Node import layer_name [as 別名]
 def get_nodes(self, class_name, params):
     """ get nodes """
     # determine if response is going to be JSON or GeoJSON
     if 'geojson' in class_name.lower():
         response_format = 'geojson'
         SerializerClass = OpenLaborGeoSerializer
     else:
         response_format = 'json'
         SerializerClass = OpenLaborSerializer
     
     layer_name = self.layer.name
     cache_key = 'layer_%s_nodes.%s' % (self.layer.id, response_format)
     serialized_nodes = cache.get(cache_key, False)
     
     if serialized_nodes is False:            
         try:
             response = requests.get(
                 self.get_url,
                 verify=self.config.get('verify_SSL', True)
             )
         except requests.exceptions.ConnectionError as e:
             return {
                 'error': _('external layer not reachable'),
                 'exception': list(e.message)
             }
         
         try:
             response.data = json.loads(response.content)
         except json.scanner.JSONDecodeError as e:
             return {
                 'error': _('external layer is experiencing some issues because it returned invalid data'),
                 'exception': list(e)
             }
         
         nodes = []
         
         # loop over all the entries and convert to nodeshot format
         for job in response.data:
             # skip records which do not have geographic information
             if not job.get('latitude', False) or not job.get('longitude', False):
                 continue
             # convert response in nodeshot format
             node_dictionary = self.to_nodeshot(job)
             # create Node model instance (needed for rest_framework serializer)
             node = Node(**node_dictionary)
             node.layer_name = layer_name  # hack to avoid too many queries to get layer name each time
             nodes.append(node)
         
         # serialize with rest framework to achieve consistency
         serialized_nodes = SerializerClass(nodes, many=True).data
         cache.set(cache_key, serialized_nodes, 86400)  # cache for 1 day
     
     return serialized_nodes
開發者ID:CristianCantoro,項目名稱:nodeshot,代碼行數:55,代碼來源:OpenLabor.py


注:本文中的nodeshot.core.nodes.models.Node.layer_name方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。