MCPcopy
hub / github.com/django/django / _build_kml_sources

Method _build_kml_sources

django/contrib/gis/sitemaps/kml.py:20–51  ·  view source on GitHub ↗

Go through the given sources and return a 3-tuple of the application label, module name, and field name of every GeometryField encountered in the sources. If no sources are provided, then all models.

(self, sources)

Source from the content-addressed store, hash-verified

18 self.locations = self._build_kml_sources(locations)
19
20 def _build_kml_sources(self, sources):
21 """
22 Go through the given sources and return a 3-tuple of the application
23 label, module name, and field name of every GeometryField encountered
24 in the sources.
25
26 If no sources are provided, then all models.
27 """
28 kml_sources = []
29 if sources is None:
30 sources = apps.get_models()
31 for source in sources:
32 if isinstance(source, models.base.ModelBase):
33 for field in source._meta.fields:
34 if isinstance(field, GeometryField):
35 kml_sources.append(
36 (
37 source._meta.app_label,
38 source._meta.model_name,
39 field.name,
40 )
41 )
42 elif isinstance(source, (list, tuple)):
43 if len(source) != 3:
44 raise ValueError(
45 "Must specify a 3-tuple of (app_label, module_name, "
46 "field_name)."
47 )
48 kml_sources.append(source)
49 else:
50 raise TypeError("KML Sources must be a model or a 3-tuple.")
51 return kml_sources
52
53 def get_urls(self, page=1, site=None, protocol=None):
54 """

Callers 1

__init__Method · 0.95

Calls 2

get_modelsMethod · 0.45
appendMethod · 0.45

Tested by

no test coverage detected