
v^		                 @   s   d  d l  m Z d  d l m Z d  d l m Z m Z d  d l m Z m	 Z	 d  d l
 m Z d  d l m Z m Z d  d l m Z d d	 e d
 d  Z d e d d  Z d S)    )apps)GeometryField)AsKML	Transform)render_to_kmlrender_to_kmz)FieldDoesNotExist)DEFAULT_DB_ALIASconnections)Http404NFc             C   s  g  } y t  j | |  } Wn( t k
 rF t d | | f   Yn X| r y+ | j j |  } t | t  sw t  Wn t k
 r t d   Yn Xt	 | }	 |	 j
 j r | j j |  j d t |   } n g  } |	 j
 j r#| j j |  j d | t | d  i   }
 | d 7} n | j j |  j   }
 x0 |
 D]( } t | |  j | _ | j |  qBW| r}t } n t } | d d | i  S)	z
    This view generates KML for the given app label, model, and field name.

    The field name must be that of a geographic field.
    z?You must supply a valid app label and module name.  Got "%s.%s"zInvalid geometry field.kmlz%s_4326i  Z_4326zgis/kml/placemarks.kmlZplaces)r   Z	get_modelLookupErrorr   Z_meta	get_field
isinstancer   r   r
   featuresZhas_AsKML_functionZ_default_managerusingZannotater   Zhas_Transform_functionr   allgetattrr   appendr   r   )requestlabelmodel
field_namecompressr   Z
placemarksklassfield
connectionqsmodrender r    C/tmp/pip-build-8lau8j11/django/django/contrib/gis/sitemaps/views.pyr   
   s8    

'	r   c          	   C   s   t  |  | | | d d d | S)zD
    Return KMZ for the given app label, model, and field name.
    r   Tr   )r   )r   r   r   r   r   r    r    r!   kmz9   s    r"   )Zdjango.appsr   Z#django.contrib.gis.db.models.fieldsr   Z&django.contrib.gis.db.models.functionsr   r   Zdjango.contrib.gis.shortcutsr   r   Zdjango.core.exceptionsr   Z	django.dbr	   r
   Zdjango.httpr   r   r"   r    r    r    r!   <module>   s   /