示例#1
0
 def kml(self):
     """ Exports trek into KML format, add geometry as linestring and POI
     as place marks """
     kml = simplekml.Kml()
     # Main itinerary
     geom = self.geom.transform(4326, clone=True)  # KML uses WGS84
     line = kml.newlinestring(name=self.name, description=plain_text(self.description), coords=geom.coords)
     line.style.linestyle.color = simplekml.Color.red  # Red
     line.style.linestyle.width = 4  # pixels
     # Place marks
     for poi in self.pois:
         place = poi.geom_as_point()
         place.transform(settings.API_SRID)
         kml.newpoint(name=poi.name, description=plain_text(poi.description), coords=[place.coords])
     return kml._genkml()
示例#2
0
 def serialize_pois(self, pois):
     for poi in pois:
         self.xml.startElement(
             "poi",
             {
                 "date_creation": timestamp(poi.date_insert),
                 "date_modification": timestamp(poi.date_update),
                 "id_poi": str(poi.pk),
             },
         )
         if poi.type.cirkwi:
             self.xml.startElement("categories", {})
             self.serialize_field("categorie", str(poi.type.cirkwi.eid), {"nom": poi.type.cirkwi.name})
             self.xml.endElement("categories")
         orig_lang = translation.get_language()
         self.xml.startElement("informations", {})
         for lang in poi.published_langs:
             translation.activate(lang)
             self.xml.startElement("information", {"langue": lang})
             self.serialize_field("titre", poi.name)
             self.serialize_field("description", plain_text(poi.description))
             self.serialize_medias(self.request, poi.serializable_pictures)
             self.xml.endElement("information")
         translation.activate(orig_lang)
         self.xml.endElement("informations")
         self.xml.startElement("adresse", {})
         self.xml.startElement("position", {})
         coords = poi.geom.transform(4326, clone=True).coords
         self.serialize_field("lat", coords[1])
         self.serialize_field("lng", coords[0])
         self.xml.endElement("position")
         self.xml.endElement("adresse")
         self.xml.endElement("poi")
 def serialize_description(self, trek):
     description = trek.description_teaser
     if description and trek.description:
         description += u'\n\n'
         description += trek.description
     if description:
         self.serialize_field('description', plain_text(description))
示例#4
0
 def serialize_pois(self, pois):
     for poi in pois:
         self.xml.startElement('poi', {
             'date_creation': timestamp(poi.date_insert),
             'date_modification': timestamp(poi.date_update),
             'id_poi': str(poi.pk),
         })
         if poi.type.cirkwi:
             self.xml.startElement('categories', {})
             self.serialize_field('categorie', str(poi.type.cirkwi.eid), {'nom': poi.type.cirkwi.name})
             self.xml.endElement('categories')
         orig_lang = translation.get_language()
         self.xml.startElement('informations', {})
         for lang in poi.published_langs:
             translation.activate(lang)
             self.xml.startElement('information', {'langue': lang})
             self.serialize_field('titre', poi.name)
             self.serialize_field('description', plain_text(poi.description))
             self.serialize_medias(self.request, poi.serializable_pictures)
             self.xml.endElement('information')
         translation.activate(orig_lang)
         self.xml.endElement('informations')
         self.xml.startElement('adresse', {})
         self.xml.startElement('position', {})
         coords = poi.geom.transform(4326, clone=True).coords
         self.serialize_field('lat', coords[1])
         self.serialize_field('lng', coords[0])
         self.xml.endElement('position')
         self.xml.endElement('adresse')
         self.xml.endElement('poi')
 def serialize_pois(self, pois):
     if not pois:
         return
     for poi in pois:
         self.xml.startElement(
             'poi', {
                 'date_creation': timestamp(poi.date_insert),
                 'date_modification': timestamp(poi.date_update),
                 'id_poi': str(poi.pk),
             })
         if poi.type.cirkwi:
             self.xml.startElement('categories', {})
             self.serialize_field('categorie', str(poi.type.cirkwi.eid),
                                  {'nom': poi.type.cirkwi.name})
             self.xml.endElement('categories')
         orig_lang = translation.get_language()
         self.xml.startElement('informations', {})
         for lang in poi.published_langs:
             translation.activate(lang)
             self.xml.startElement('information', {'langue': lang})
             self.serialize_field('titre', poi.name)
             self.serialize_field('description',
                                  plain_text(poi.description))
             self.serialize_medias(self.request, poi.serializable_pictures)
             self.xml.endElement('information')
         translation.activate(orig_lang)
         self.xml.endElement('informations')
         self.xml.startElement('adresse', {})
         self.xml.startElement('position', {})
         coords = poi.geom.transform(4326, clone=True).coords
         self.serialize_field('lat', coords[1])
         self.serialize_field('lng', coords[0])
         self.xml.endElement('position')
         self.xml.endElement('adresse')
         self.xml.endElement('poi')
示例#6
0
 def serialize_description(self, trek):
     description = trek.description_teaser
     if description and trek.description:
         description += u'\n\n'
         description += trek.description
     if description:
         self.serialize_field('description', plain_text(description))
示例#7
0
def plain_text_preserve_linebreaks(value):
    value = re.sub(ur'\s*<br\s*/?>\s*', u'##~~~~~~##', value)
    value = re.sub(ur'\s*<p>\s*', u'##~~~~~~####~~~~~~##', value)
    value = re.sub(ur'\s*</p>\s*', u'', value)
    value = plain_text(value)
    value = re.sub(ur'\s+', ' ', value)
    value = re.sub(u'##~~~~~~##', u'\n', value)
    value = value.strip()
    return value
示例#8
0
def plain_text_preserve_linebreaks(value):
    value = re.sub(ur'\s*<br\s*/?>\s*', u'##~~~~~~##', value)
    value = re.sub(ur'\s*<p>\s*', u'##~~~~~~####~~~~~~##', value)
    value = re.sub(ur'\s*</p>\s*', u'', value)
    value = plain_text(value)
    value = re.sub(ur'\s+', ' ', value)
    value = re.sub(u'##~~~~~~##', u'\n', value)
    value = value.strip()
    return value
 def serialize_additionnal_info(self, trek, name):
     value = getattr(trek, name)
     if not value:
         return
     value = plain_text(value)
     self.xml.startElement('information_complementaire', {})
     self.serialize_field('titre', trek._meta.get_field(name).verbose_name)
     self.serialize_field('description', value)
     self.xml.endElement('information_complementaire')
示例#10
0
 def serialize_additionnal_info(self, trek, name):
     value = getattr(trek, name)
     if not value:
         return
     value = plain_text(value)
     self.xml.startElement('information_complementaire', {})
     self.serialize_field('titre', trek._meta.get_field(name).verbose_name)
     self.serialize_field('description', value)
     self.xml.endElement('information_complementaire')
示例#11
0
 def kml(self):
     """ Exports trek into KML format, add geometry as linestring and POI
     as place marks """
     kml = simplekml.Kml()
     # Main itinerary
     geom3d = self.geom_3d.transform(4326, clone=True)  # KML uses WGS84
     line = kml.newlinestring(name=self.name,
                              description=plain_text(self.description),
                              coords=geom3d.coords)
     line.style.linestyle.color = simplekml.Color.red  # Red
     line.style.linestyle.width = 4  # pixels
     # Place marks
     for poi in self.pois:
         place = poi.geom_3d.transform(settings.API_SRID, clone=True)
         kml.newpoint(name=poi.name,
                      description=plain_text(poi.description),
                      coords=[place.coords])
     return kml.kml()
示例#12
0
 def get_context_data(self, **kwargs):
     context = super(TrekDocumentPublic, self).get_context_data(**kwargs)
     # Replace HTML text with plain text
     trek = self.get_object()
     for attr in ['description', 'description_teaser', 'ambiance', 'advice', 'access',
                  'public_transport', 'advised_parking', 'disabled_infrastructure']:
         setattr(trek, attr, plain_text(getattr(trek, attr)))
     context['object'] = trek
     context['trek'] = trek
     return context
示例#13
0
 def kml(self):
     """ Exports path into KML format, add geometry as linestring """
     kml = simplekml.Kml()
     geom3d = self.geom_3d.transform(4326, clone=True)  # KML uses WGS84
     line = kml.newlinestring(name=self.name,
                              description=plain_text(self.comments),
                              coords=simplify_coords(geom3d.coords))
     line.style.linestyle.color = simplekml.Color.red  # Red
     line.style.linestyle.width = 4  # pixels
     return kml.kml()
示例#14
0
 def kml(self):
     """ Exports path into KML format, add geometry as linestring """
     kml = simplekml.Kml()
     geom3d = self.geom_3d.transform(4326, clone=True)  # KML uses WGS84
     line = kml.newlinestring(name=self.name,
                              description=plain_text(self.comments),
                              coords=geom3d.coords)
     line.style.linestyle.color = simplekml.Color.red  # Red
     line.style.linestyle.width = 4  # pixels
     return kml.kml()
示例#15
0
    def get_context_data(self, **kwargs):
        context = super(TrekDocumentPublic, self).get_context_data(**kwargs)

        trek = self.get_object()
        context['object'] = trek
        context['trek'] = trek
        context['mapimage_ratio'] = settings.TREK_EXPORT_MAP_IMAGE_SIZE
        context['headerimage_ratio'] = settings.TREK_EXPORT_HEADER_IMAGE_SIZE

        information_desks = list(trek.information_desks.all())
        if settings.TREK_EXPORT_INFORMATION_DESK_LIST_LIMIT > 0:
            information_desks = information_desks[:settings.
                                                  TREK_EXPORT_INFORMATION_DESK_LIST_LIMIT]
        context['information_desks'] = information_desks

        pois = list(trek.pois)
        if settings.TREK_EXPORT_POI_LIST_LIMIT > 0:
            pois = pois[:settings.TREK_EXPORT_POI_LIST_LIMIT]
        context['pois'] = pois

        # Replace HTML text with plain text
        for attr in [
                'description', 'description_teaser', 'ambiance', 'advice',
                'access', 'public_transport', 'advised_parking',
                'disabled_infrastructure'
        ]:
            setattr(trek, attr, plain_text(getattr(trek, attr)))
        for poi in context['pois']:
            setattr(poi, 'description', plain_text(getattr(poi,
                                                           'description')))

        #
        # POIs enumeration, like shown on the map
        # https://github.com/makinacorpus/Geotrek/issues/871
        enumeration = {}
        letters = alphabet_enumeration(len(trek.pois))
        for i, p in enumerate(trek.pois):
            enumeration[p.pk] = letters[i]
        context['enumeration'] = enumeration

        return context
示例#16
0
 def kml(self):
     """Exports sensitivearea into KML format"""
     kml = simplekml.Kml()
     geom = self.geom
     if geom.geom_type == 'Point':
         geom = geom.buffer(self.species.radius or settings.SENSITIVITY_DEFAULT_RADIUS, 4)
     geom = geom.transform(4326, clone=True)  # KML uses WGS84
     line = kml.newpolygon(name=self.species.name,
                           description=plain_text(self.description),
                           outerboundaryis=geom.coords[0])
     line.style.linestyle.color = simplekml.Color.red  # Red
     line.style.linestyle.width = 4  # pixels
     return kml.kml()
示例#17
0
文件: views.py 项目: Pitchs/Geotrek
    def get_context_data(self, **kwargs):
        context = super(TrekDocumentPublic, self).get_context_data(**kwargs)
        trek = self.get_object()

        context['headerimage_ratio'] = settings.EXPORT_HEADER_IMAGE_SIZE['trek']

        information_desks = list(trek.information_desks.all())
        if settings.TREK_EXPORT_INFORMATION_DESK_LIST_LIMIT > 0:
            information_desks = information_desks[:settings.TREK_EXPORT_INFORMATION_DESK_LIST_LIMIT]
        context['information_desks'] = information_desks

        pois = list(trek.pois.filter(published=True))
        if settings.TREK_EXPORT_POI_LIST_LIMIT > 0:
            pois = pois[:settings.TREK_EXPORT_POI_LIST_LIMIT]
        context['pois'] = pois

        # Replace HTML text with plain text
        for attr in ['description', 'description_teaser', 'ambiance', 'advice', 'access',
                     'public_transport', 'advised_parking', 'disabled_infrastructure']:
            setattr(trek, attr, plain_text(getattr(trek, attr)))

        for poi in context['pois']:
            setattr(poi, 'description', plain_text(getattr(poi, 'description')))

        #
        # POIs enumeration, like shown on the map
        # https://github.com/makinacorpus/Geotrek/issues/871
        enumeration = {}
        letters = alphabet_enumeration(len(trek.pois))
        for i, p in enumerate(trek.pois):
            enumeration[p.pk] = letters[i]
        context['enumeration'] = enumeration

        context['object'] = context['trek'] = trek

        return context
示例#18
0
 def get_context_data(self, **kwargs):
     context = super(TrekDocumentPublic, self).get_context_data(**kwargs)
     # Replace HTML text with plain text
     trek = self.get_object()
     for attr in ['description', 'description_teaser', 'ambiance', 'advice', 'access',
                  'public_transport', 'advised_parking', 'disabled_infrastructure']:
         setattr(trek, attr, plain_text(getattr(trek, attr)))
     context['object'] = trek
     context['trek'] = trek
     ratio = trek.get_geom_aspect_ratio()
     if ratio > 1.0:
         mapimage_ratio = (12, 12/ratio)
     else:
         mapimage_ratio = (10*ratio, 10)
     context['mapimage_ratio'] = mapimage_ratio
     return context
示例#19
0
 def kml(self):
     """Exports sensitivearea into KML format"""
     kml = simplekml.Kml()
     geom = self.geom
     if geom.geom_type == 'Point':
         geom = geom.buffer(self.species.radius or settings.SENSITIVITY_DEFAULT_RADIUS, 4)
     if self.species.radius:
         geometry = ()
         for coords in geom.coords[0]:
             coords += (self.species.radius, )
             geometry += (coords, )
         geom = GEOSGeometry(Polygon(geometry), srid=settings.SRID)
     geom = geom.transform(4326, clone=True)  # KML uses WGS84
     line = kml.newpolygon(name=self.species.name,
                           description=plain_text(self.description),
                           altitudemode=simplekml.AltitudeMode.relativetoground,
                           outerboundaryis=simplify_coords(geom.coords[0]))
     line.style.linestyle.color = simplekml.Color.red  # Red
     line.style.linestyle.width = 4  # pixels
     return kml.kml()
示例#20
0
 def kml(self):
     """Exports sensitivearea into KML format"""
     kml = simplekml.Kml()
     geom = self.geom
     if geom.geom_type == 'Point':
         geom = geom.buffer(self.species.radius or settings.SENSITIVITY_DEFAULT_RADIUS, 4)
     if self.species.radius:
         geometry = ()
         for coords in geom.coords[0]:
             coords += (self.species.radius, )
             geometry += (coords, )
         geom = GEOSGeometry(Polygon(geometry), srid=settings.SRID)
     geom = geom.transform(4326, clone=True)  # KML uses WGS84
     line = kml.newpolygon(name=self.species.name,
                           description=plain_text(self.description),
                           altitudemode=simplekml.AltitudeMode.relativetoground,
                           outerboundaryis=geom.coords[0])
     line.style.linestyle.color = simplekml.Color.red  # Red
     line.style.linestyle.width = 4  # pixels
     return kml.kml()
示例#21
0
 def meta_description(self):
     return plain_text(self.ambiance or self.description_teaser or self.description)[:500]
示例#22
0
 def meta_description(self):
     return plain_text(self.content)[:500]
示例#23
0
 def meta_description(self):
     return plain_text(self.content)[:500]
示例#24
0
 def meta_description(self):
     return plain_text(self.ambiance or self.description_teaser
                       or self.description)[:500]