Esempio n. 1
0
 def filter_queryset(self, request, queryset, view):
     qs = queryset
     trek = request.GET.get('near_trek', None)
     if trek is not None:
         contents_intersecting = intersecting(qs.model,
                                              Trek.objects.get(pk=trek))
         # qs = qs.intersecting(contents_intersecting)  #FIXME: cannot intersect MultilingualQuerySet
         qs = contents_intersecting.order_by('id')
     return qs
Esempio n. 2
0
 def cities(self):
     return uniquify(intersecting(City, self.zoning_property, distance=0))
Esempio n. 3
0
 def districts(self):
     return uniquify(intersecting(District, self.zoning_property, distance=0))
Esempio n. 4
0
        return self.published

    @property
    def pretty_period(self):
        return self.species.pretty_period()
    pretty_period_verbose_name = _("Period")

    @property
    def pretty_practices(self):
        return self.species.pretty_practices()
    pretty_practices_verbose_name = _("Practices")


if 'geotrek.core' in settings.INSTALLED_APPS:
    from geotrek.core.models import Topology
    Topology.add_property('sensitive_areas', lambda self: intersecting(SensitiveArea, self, settings.SENSITIVE_AREA_INTERSECTION_MARGIN, False), _("Sensitive areas"))
    Topology.add_property('published_sensitive_areas', lambda self: intersecting(SensitiveArea, self, settings.SENSITIVE_AREA_INTERSECTION_MARGIN, False).filter(published=True), _("Published sensitive areas"))

if 'geotrek.trekking' in settings.INSTALLED_APPS:
    from geotrek.trekking import models as trekking_models
    SensitiveArea.add_property('pois', lambda self: intersecting(trekking_models.POI, self, 0), _("POIs"))
    SensitiveArea.add_property('treks', lambda self: intersecting(trekking_models.Trek, self, 0), _("Treks"))
    SensitiveArea.add_property('services', lambda self: intersecting(trekking_models.Service, self, 0), _("Services"))

if 'geotrek.diving' in settings.INSTALLED_APPS:
    from geotrek.diving.models import Dive
    Dive.add_property('sensitive_areas', lambda self: intersecting(SensitiveArea, self, settings.SENSITIVE_AREA_INTERSECTION_MARGIN, False), _("Sensitive areas"))
    Dive.add_property('published_sensitive_areas', lambda self: intersecting(SensitiveArea, self, settings.SENSITIVE_AREA_INTERSECTION_MARGIN, False).filter(published=True), _("Published sensitive areas"))
    SensitiveArea.add_property('dives', lambda self: intersecting(Dive, self, 0), _("Dives"))
    SensitiveArea.add_property('published_dives',
                               lambda self: intersecting(Dive, self, 0).filter(published=True),
Esempio n. 5
0
    @property
    def type(self):
        """Fake type to simulate POI for mobile app v1"""
        return self.category

    @property
    def min_elevation(self):
        return 0

    @property
    def max_elevation(self):
        return 0


Topology.add_property('touristic_contents',
                      lambda self: intersecting(TouristicContent, self),
                      _(u"Touristic contents"))
Topology.add_property(
    'published_touristic_contents',
    lambda self: intersecting(TouristicContent, self).filter(published=True),
    _(u"Published touristic contents"))
TouristicContent.add_property(
    'touristic_contents', lambda self: intersecting(TouristicContent, self),
    _(u"Touristic contents"))
TouristicContent.add_property(
    'published_touristic_contents',
    lambda self: intersecting(TouristicContent, self).filter(published=True),
    _(u"Published touristic contents"))


class TouristicEventType(OptionalPictogramMixin):
Esempio n. 6
0
    def type2_label(self):
        return self.category.type2_label

    @property
    def types1_display(self):
        return ', '.join([unicode(n) for n in self.type1.all()])

    @property
    def types2_display(self):
        return ', '.join([unicode(n) for n in self.type2.all()])

    @property
    def prefixed_category_id(self):
        return self.category.prefixed_id

Topology.add_property('touristic_contents', lambda self: intersecting(TouristicContent, self, distance=settings.TOURISM_INTERSECTION_MARGIN), _(u"Touristic contents"))
Topology.add_property('published_touristic_contents', lambda self: intersecting(TouristicContent, self, distance=settings.TOURISM_INTERSECTION_MARGIN).filter(published=True), _(u"Published touristic contents"))
TouristicContent.add_property('touristic_contents', lambda self: intersecting(TouristicContent, self, distance=settings.TOURISM_INTERSECTION_MARGIN), _(u"Touristic contents"))
TouristicContent.add_property('published_touristic_contents', lambda self: intersecting(TouristicContent, self, distance=settings.TOURISM_INTERSECTION_MARGIN).filter(published=True), _(u"Published touristic contents"))


class TouristicEventType(OptionalPictogramMixin):

    type = models.CharField(verbose_name=_(u"Type"), max_length=128, db_column='type')

    class Meta:
        db_table = 't_b_evenement_touristique_type'
        verbose_name = _(u"Touristic event type")
        verbose_name_plural = _(u"Touristic event types")
        ordering = ['type']
Esempio n. 7
0
                          .filter(aggregations__path=path).distinct('pk')

    @classmethod
    def topology_area_edges(cls, topology):
        return cls.overlapping(topology)\
                  .select_related('restricted_area')\
                  .select_related('restricted_area__area_type')


if settings.TREKKING_TOPOLOGY_ENABLED:
    Path.add_property('area_edges', RestrictedAreaEdge.path_area_edges, _(u"Restricted area edges"))
    Path.add_property('areas', lambda self: uniquify(map(attrgetter('restricted_area'), self.area_edges)),
                      _(u"Restricted areas"))
    Topology.add_property('area_edges', RestrictedAreaEdge.topology_area_edges, _(u"Restricted area edges"))
    Topology.add_property('areas', lambda self: uniquify(
        intersecting(RestrictedArea, self)) if self.ispoint() else uniquify(
        map(attrgetter('restricted_area'), self.area_edges)), _(u"Restricted areas"))
    Intervention.add_property('area_edges', lambda self: self.topology.area_edges if self.topology else [],
                              _(u"Restricted area edges"))
    Intervention.add_property('areas', lambda self: self.topology.areas if self.topology else [],
                              _(u"Restricted areas"))
    Project.add_property('area_edges', lambda self: self.edges_by_attr('area_edges'), _(u"Restricted area edges"))
    Project.add_property('areas', lambda self: uniquify(map(attrgetter('restricted_area'), self.area_edges)),
                         _(u"Restricted areas"))
else:
    Topology.add_property('areas', lambda self: uniquify(intersecting(RestrictedArea, self, distance=0)),
                          _(u"Restricted areas"))

TouristicContent.add_property('areas', lambda self: intersecting(RestrictedArea, self, distance=0),
                              _(u"Restricted areas"))
TouristicEvent.add_property('areas', lambda self: intersecting(RestrictedArea, self, distance=0),
Esempio n. 8
0
        else:
            return Practice.id_prefix

    def get_map_image_url(self):
        return reverse('diving:dive_map_image', args=[str(self.pk), get_language()])

    @classmethod
    def get_create_label(cls):
        return _("Add a new dive")

    @property
    def levels_display(self):
        return ", ".join([str(level) for level in self.levels.all()])


Topology.add_property('dives', lambda self: intersecting(Dive, self), _("Dives"))
Topology.add_property('published_dives', lambda self: intersecting(Dive, self).filter(published=True), _("Published dives"))
Dive.add_property('dives', lambda self: intersecting(Dive, self), _("Dives"))
Dive.add_property('published_dives', lambda self: intersecting(Dive, self).filter(published=True), _("Published dives"))
Dive.add_property('treks', lambda self: intersecting(Trek, self), _("Treks"))
Dive.add_property('published_treks', lambda self: intersecting(Trek, self).filter(published=True), _("Published treks"))

Dive.add_property('pois', lambda self: intersecting(POI, self), _("POIs"))
Dive.add_property('published_pois', lambda self: intersecting(POI, self).filter(published=True), _("Published POIs"))

Dive.add_property('services', lambda self: intersecting(Service, self), _("Services"))
Dive.add_property('published_services', lambda self: intersecting(Service, self).filter(published=True), _("Published Services"))

if 'geotrek.tourism' in settings.INSTALLED_APPS:
    from geotrek.tourism import models as tourism_models
    tourism_models.TouristicContent.add_property('dives', lambda self: intersecting(Dive, self), _("Dives"))
Esempio n. 9
0
                                   blank=True)
    type2 = models.ManyToManyField(TouristicContentType, related_name='contents2',
                                   verbose_name=_(u"Type 2"), db_table="t_r_contenu_touristique_type2",
                                   blank=True)

    objects = NoDeleteMixin.get_manager_cls(models.GeoManager)()

    class Meta:
        db_table = 't_t_contenu_touristique'
        verbose_name = _(u"Touristic content")
        verbose_name_plural = _(u"Touristic contents")

    def __unicode__(self):
        return self.name

Topology.add_property('touristic_contents', lambda self: intersecting(TouristicContent, self, distance=settings.TOURISM_INTERSECTION_MARGIN))
TouristicContent.add_property('touristic_contents', lambda self: intersecting(TouristicContent, self, distance=settings.TOURISM_INTERSECTION_MARGIN))


class TouristicEventType(models.Model):

    type = models.CharField(verbose_name=_(u"Type"), max_length=128, db_column='type')

    class Meta:
        db_table = 't_b_evenement_touristique_type'
        verbose_name = _(u"Touristic event type")
        verbose_name_plural = _(u"Touristic event types")
        ordering = ['type']

    def __unicode__(self):
        return self.type
Esempio n. 10
0
    @classmethod
    def get_create_label(cls):
        return _("Add a new outdoor site")

    @property
    def published_children(self):
        if not settings.PUBLISHED_BY_LANG:
            return self.children.filter(published=True)
        q = Q()
        for lang in settings.MODELTRANSLATION_LANGUAGES:
            q |= Q(**{'published_{}'.format(lang): True})
        return self.children.filter(q)


Path.add_property('sites', lambda self: intersecting(Site, self), _("Sites"))
Topology.add_property('sites', lambda self: intersecting(Site, self),
                      _("Sites"))
TouristicContent.add_property('sites', lambda self: intersecting(Site, self),
                              _("Sites"))
TouristicEvent.add_property('sites', lambda self: intersecting(Site, self),
                            _("Sites"))

Site.add_property('sites', lambda self: intersecting(Site, self), _("Sites"))
Site.add_property('treks', lambda self: intersecting(Trek, self), _("Treks"))
Site.add_property('pois', lambda self: intersecting(POI, self), _("POIs"))
Site.add_property('trails', lambda self: intersecting(Trail, self),
                  _("Trails"))
Site.add_property('infrastructures',
                  lambda self: intersecting(Infrastructure, self),
                  _("Infrastructures"))
Esempio n. 11
0
        return settings.TOURISM_INTERSECTION_MARGIN

    @property
    def type(self):
        """Fake type to simulate POI for mobile app v1"""
        return self.category

    @property
    def min_elevation(self):
        return 0

    @property
    def max_elevation(self):
        return 0

Topology.add_property('touristic_contents', lambda self: intersecting(TouristicContent, self), _(u"Touristic contents"))
Topology.add_property('published_touristic_contents', lambda self: intersecting(TouristicContent, self).filter(published=True), _(u"Published touristic contents"))
TouristicContent.add_property('touristic_contents', lambda self: intersecting(TouristicContent, self), _(u"Touristic contents"))
TouristicContent.add_property('published_touristic_contents', lambda self: intersecting(TouristicContent, self).filter(published=True), _(u"Published touristic contents"))


class TouristicEventType(OptionalPictogramMixin):

    type = models.CharField(verbose_name=_(u"Type"), max_length=128, db_column='type')

    class Meta:
        db_table = 't_b_evenement_touristique_type'
        verbose_name = _(u"Touristic event type")
        verbose_name_plural = _(u"Touristic event types")
        ordering = ['type']
Esempio n. 12
0
        return treks.order_by('topo_object').distinct('topo_object')

    @classmethod
    def topology_treks(cls, topology):
        if settings.TREKKING_TOPOLOGY_ENABLED:
            qs = cls.overlapping(topology)
        else:
            area = topology.geom.buffer(settings.TREK_POI_INTERSECTION_MARGIN)
            qs = cls.objects.filter(geom__intersects=area)
        return qs

Path.add_property('treks', Trek.path_treks)
Topology.add_property('treks', Trek.topology_treks)
Intervention.add_property('treks', lambda self: self.topology.treks if self.topology else [])
Project.add_property('treks', lambda self: self.edges_by_attr('treks'))
tourism_models.TouristicContent.add_property('treks', lambda self: intersecting(Trek, self, distance=settings.TOURISM_INTERSECTION_MARGIN))
tourism_models.TouristicEvent.add_property('treks', lambda self: intersecting(Trek, self, distance=settings.TOURISM_INTERSECTION_MARGIN))


class TrekRelationshipManager(models.Manager):
    use_for_related_fields = True

    def get_queryset(self):
        # Select treks foreign keys by default
        qs = super(TrekRelationshipManager, self).get_queryset().select_related('trek_a', 'trek_b')
        # Exclude deleted treks
        return qs.exclude(trek_a__deleted=True).exclude(trek_b__deleted=True)


class TrekRelationship(models.Model):
    """
Esempio n. 13
0
if settings.TREKKING_TOPOLOGY_ENABLED:
    Path.add_property('area_edges', RestrictedAreaEdge.path_area_edges,
                      _("Restricted area edges"))
    Path.add_property(
        'areas', lambda self: uniquify(
            map(attrgetter('restricted_area'), self.area_edges)),
        _("Restricted areas"))
    Path.add_property(
        'published_areas',
        lambda self: [area for area in self.areas if area.published],
        _("Published areas"))
    Topology.add_property('area_edges', RestrictedAreaEdge.topology_area_edges,
                          _("Restricted area edges"))
    Topology.add_property(
        'areas', lambda self: uniquify(intersecting(RestrictedArea, self))
        if self.ispoint() else uniquify(
            map(attrgetter('restricted_area'), self.area_edges)),
        _("Restricted areas"))
    Intervention.add_property(
        'area_edges', lambda self: self.target.area_edges
        if self.target and self.target else [], _("Restricted area edges"))
    Intervention.add_property(
        'areas', lambda self: self.target.areas
        if self.target and self.target else [], _("Restricted areas"))
    Project.add_property('area_edges',
                         lambda self: self.edges_by_attr('area_edges'),
                         _("Restricted area edges"))
    Project.add_property(
        'areas', lambda self: uniquify(
            map(attrgetter('restricted_area'), self.area_edges)),
Esempio n. 14
0
        return [o for o, _o in self.ORIENTATION_CHOICES
                if o in orientation]  # Sorting

    @property
    def super_wind(self):
        "Return wind of itself and its descendants"
        wind = set(
            sum(
                self.get_descendants(include_self=True).values_list('wind',
                                                                    flat=True),
                []))
        return [o for o, _o in self.ORIENTATION_CHOICES
                if o in wind]  # Sorting


Path.add_property('sites', lambda self: intersecting(Site, self), _("Sites"))
Topology.add_property('sites', lambda self: intersecting(Site, self),
                      _("Sites"))
TouristicContent.add_property('sites', lambda self: intersecting(Site, self),
                              _("Sites"))
TouristicEvent.add_property('sites', lambda self: intersecting(Site, self),
                            _("Sites"))

Site.add_property('sites', lambda self: intersecting(Site, self), _("Sites"))
Site.add_property('treks', lambda self: intersecting(Trek, self), _("Treks"))
Site.add_property('pois', lambda self: intersecting(POI, self), _("POIs"))
Site.add_property('trails', lambda self: intersecting(Trail, self),
                  _("Trails"))
Site.add_property('infrastructures',
                  lambda self: intersecting(Infrastructure, self),
                  _("Infrastructures"))
Esempio n. 15
0
    def extent(self):
        return self.geom.buffer(10).transform(settings.API_SRID,
                                              clone=True).extent

    @property
    def rando_url(self):
        category_slug = _('touristic-content')
        return '{}/{}/'.format(category_slug, self.slug)

    @property
    def meta_description(self):
        return plain_text(self.description_teaser or self.description)[:500]


Topology.add_property(
    'touristic_contents', lambda self: intersecting(TouristicContent, self).
    order_by(*settings.TOURISTIC_CONTENTS_API_ORDER), _("Touristic contents"))
Topology.add_property(
    'published_touristic_contents',
    lambda self: intersecting(TouristicContent, self).filter(
        published=True).order_by(*settings.TOURISTIC_CONTENTS_API_ORDER),
    _("Published touristic contents"))
TouristicContent.add_property(
    'touristic_contents', lambda self: intersecting(TouristicContent, self).
    order_by(*settings.TOURISTIC_CONTENTS_API_ORDER), _("Touristic contents"))
TouristicContent.add_property(
    'published_touristic_contents',
    lambda self: intersecting(TouristicContent, self).filter(
        published=True).order_by(*settings.TOURISTIC_CONTENTS_API_ORDER),
    _("Published touristic contents"))

Esempio n. 16
0
        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()

    def is_public(self):
        return self.published

    @property
    def pretty_period(self):
        return self.species.pretty_period()
    pretty_period_verbose_name = _("Period")

    @property
    def pretty_practices(self):
        return self.species.pretty_practices()
    pretty_practices_verbose_name = _("Practices")


if 'geotrek.core' in settings.INSTALLED_APPS:
    from geotrek.core.models import Topology
    Topology.add_property('sensitive_areas', lambda self: intersecting(SensitiveArea, self, settings.SENSITIVE_AREA_INTERSECTION_MARGIN), _(u"Sensitive areas"))
    Topology.add_property('published_sensitive_areas', lambda self: intersecting(SensitiveArea, self, settings.SENSITIVE_AREA_INTERSECTION_MARGIN).filter(published=True), _(u"Published sensitive areas"))
Esempio n. 17
0
                          .filter(aggregations__path=path).distinct('pk')

    @classmethod
    def topology_area_edges(cls, topology):
        return cls.overlapping(topology)\
                  .select_related('restricted_area')\
                  .select_related('restricted_area__area_type')


if settings.TREKKING_TOPOLOGY_ENABLED:
    Path.add_property('area_edges', RestrictedAreaEdge.path_area_edges, _("Restricted area edges"))
    Path.add_property('areas', lambda self: uniquify(map(attrgetter('restricted_area'), self.area_edges)),
                      _("Restricted areas"))
    Topology.add_property('area_edges', RestrictedAreaEdge.topology_area_edges, _("Restricted area edges"))
    Topology.add_property('areas', lambda self: uniquify(
        intersecting(RestrictedArea, self)) if self.ispoint() else uniquify(
        map(attrgetter('restricted_area'), self.area_edges)), _("Restricted areas"))
    Intervention.add_property('area_edges', lambda self: self.topology.area_edges if self.topology else [],
                              _("Restricted area edges"))
    Intervention.add_property('areas', lambda self: self.topology.areas if self.topology else [],
                              _("Restricted areas"))
    Project.add_property('area_edges', lambda self: self.edges_by_attr('area_edges'), _("Restricted area edges"))
    Project.add_property('areas', lambda self: uniquify(map(attrgetter('restricted_area'), self.area_edges)),
                         _("Restricted areas"))
else:
    Topology.add_property('areas', lambda self: uniquify(intersecting(RestrictedArea, self, distance=0)),
                          _("Restricted areas"))
    Project.add_property('areas', lambda self: uniquify(intersecting(RestrictedArea, self, distance=0)),
                         _("Restricted areas"))
    Intervention.add_property('areas', lambda self: uniquify(intersecting(RestrictedArea, self, distance=0)),
                              _("Restricted areas"))
Esempio n. 18
0
    @property
    def extent(self):
        return self.geom.transform(
            settings.API_SRID, clone=True).extent if self.geom.extent else None


Path.add_property('treks', Trek.path_treks, _(u"Treks"))
Topology.add_property('treks', Trek.topology_treks, _(u"Treks"))
if settings.HIDE_PUBLISHED_TREKS_IN_TOPOLOGIES:
    Topology.add_property('published_treks', lambda self: [],
                          _(u"Published treks"))
else:
    Topology.add_property(
        'published_treks',
        lambda self: intersecting(Trek, self).filter(published=True),
        _(u"Published treks"))
Intervention.add_property(
    'treks', lambda self: self.topology.treks if self.topology else [],
    _(u"Treks"))
Project.add_property('treks', lambda self: self.edges_by_attr('treks'),
                     _(u"Treks"))
tourism_models.TouristicContent.add_property(
    'treks', lambda self: intersecting(Trek, self), _(u"Treks"))
tourism_models.TouristicContent.add_property(
    'published_treks',
    lambda self: intersecting(Trek, self).filter(published=True),
    _(u"Published treks"))
tourism_models.TouristicEvent.add_property(
    'treks', lambda self: intersecting(Trek, self), _(u"Treks"))
tourism_models.TouristicEvent.add_property(
Esempio n. 19
0
        return 0

    @property
    def max_elevation(self):
        return 0

    @property
    def portal_display(self):
        return ', '.join([unicode(portal) for portal in self.portal.all()])

    @property
    def source_display(self):
        return ','.join([unicode(source) for source in self.source.all()])


Topology.add_property('touristic_contents', lambda self: intersecting(TouristicContent, self), _(u"Touristic contents"))
Topology.add_property('published_touristic_contents', lambda self: intersecting(TouristicContent, self).filter(published=True), _(u"Published touristic contents"))
TouristicContent.add_property('touristic_contents', lambda self: intersecting(TouristicContent, self), _(u"Touristic contents"))
TouristicContent.add_property('published_touristic_contents', lambda self: intersecting(TouristicContent, self).filter(published=True), _(u"Published touristic contents"))


class TouristicEventType(OptionalPictogramMixin):

    type = models.CharField(verbose_name=_(u"Type"), max_length=128, db_column='type')

    class Meta:
        db_table = 't_b_evenement_touristique_type'
        verbose_name = _(u"Touristic event type")
        verbose_name_plural = _(u"Touristic event types")
        ordering = ['type']
Esempio n. 20
0
                if not field.primary_key and not hasattr(field, 'through'):
                    field_names.add(field.attname)
            old_trek = Trek.objects.get(pk=self.pk)
            if self.geom is not None and old_trek.geom.equals_exact(self.geom, tolerance=0.00001):
                field_names.remove('geom')
            if self.geom_3d is not None and old_trek.geom_3d.equals_exact(self.geom_3d, tolerance=0.00001):
                field_names.remove('geom_3d')
            return super(Trek, self).save(update_fields=field_names, *args, **kwargs)
        super(Trek, self).save(*args, **kwargs)

Path.add_property('treks', Trek.path_treks, _(u"Treks"))
Topology.add_property('treks', Trek.topology_treks, _(u"Treks"))
if settings.HIDE_PUBLISHED_TREKS_IN_TOPOLOGIES:
    Topology.add_property('published_treks', lambda self: [], _(u"Published treks"))
else:
    Topology.add_property('published_treks', lambda self: intersecting(Trek, self).filter(published=True), _(u"Published treks"))
Intervention.add_property('treks', lambda self: self.topology.treks if self.topology else [], _(u"Treks"))
Project.add_property('treks', lambda self: self.edges_by_attr('treks'), _(u"Treks"))
tourism_models.TouristicContent.add_property('treks', lambda self: intersecting(Trek, self), _(u"Treks"))
tourism_models.TouristicContent.add_property('published_treks', lambda self: intersecting(Trek, self).filter(published=True), _(u"Published treks"))
tourism_models.TouristicEvent.add_property('treks', lambda self: intersecting(Trek, self), _(u"Treks"))
tourism_models.TouristicEvent.add_property('published_treks', lambda self: intersecting(Trek, self).filter(published=True), _(u"Published treks"))


class TrekRelationshipManager(models.Manager):
    use_for_related_fields = True

    def get_queryset(self):
        # Select treks foreign keys by default
        qs = super(TrekRelationshipManager, self).get_queryset().select_related('trek_a', 'trek_b')
        # Exclude deleted treks
Esempio n. 21
0
        return self.species.pretty_period()

    pretty_period_verbose_name = _("Period")

    @property
    def pretty_practices(self):
        return self.species.pretty_practices()

    pretty_practices_verbose_name = _("Practices")


if 'geotrek.core' in settings.INSTALLED_APPS:
    from geotrek.core.models import Topology
    Topology.add_property(
        'sensitive_areas',
        lambda self: intersecting(SensitiveArea, self, settings.
                                  SENSITIVE_AREA_INTERSECTION_MARGIN, False),
        _("Sensitive areas"))
    Topology.add_property(
        'published_sensitive_areas', lambda self: intersecting(
            SensitiveArea, self, settings.SENSITIVE_AREA_INTERSECTION_MARGIN,
            False).filter(published=True), _("Published sensitive areas"))

if 'geotrek.trekking' in settings.INSTALLED_APPS:
    from geotrek.trekking import models as trekking_models
    SensitiveArea.add_property(
        'pois', lambda self: intersecting(trekking_models.POI, self, 0),
        _("POIs"))
    SensitiveArea.add_property(
        'treks', lambda self: intersecting(trekking_models.Trek, self, 0),
        _("Treks"))
    SensitiveArea.add_property(
Esempio n. 22
0
        return cls.overlapping(topology)\
                  .select_related('restricted_area')\
                  .select_related('restricted_area__area_type')


if settings.TREKKING_TOPOLOGY_ENABLED:
    Path.add_property('area_edges', RestrictedAreaEdge.path_area_edges)
    Path.add_property('areas', lambda self: uniquify(map(attrgetter('restricted_area'), self.area_edges)))
    Topology.add_property('area_edges', RestrictedAreaEdge.topology_area_edges)
    Topology.add_property('areas', lambda self: uniquify(map(attrgetter('restricted_area'), self.area_edges)))
    Intervention.add_property('area_edges', lambda self: self.topology.area_edges if self.topology else [])
    Intervention.add_property('areas', lambda self: self.topology.areas if self.topology else [])
    Project.add_property('area_edges', lambda self: self.edges_by_attr('area_edges'))
    Project.add_property('areas', lambda self: uniquify(map(attrgetter('restricted_area'), self.area_edges)))
else:
    Topology.add_property('areas', lambda self: intersecting(RestrictedArea, self))

TouristicContent.add_property('areas', lambda self: intersecting(RestrictedArea, self))
TouristicEvent.add_property('areas', lambda self: intersecting(RestrictedArea, self))


class City(models.Model):
    code = models.CharField(primary_key=True, max_length=6, db_column='insee')
    name = models.CharField(max_length=128, db_column='commune', verbose_name=_(u"Name"))
    geom = models.MultiPolygonField(srid=settings.SRID, spatial_index=False)

    # Override default manager
    objects = models.GeoManager()

    class Meta:
        db_table = 'l_commune'
Esempio n. 23
0
 def areas(self):
     return uniquify(intersecting(RestrictedArea, self.zoning_property, distance=0))
Esempio n. 24
0
            maplayers.append(ugettext(u"POIs"))
        if settings.SHOW_SERVICES_ON_MAP_SCREENSHOT:
            maplayers.append(ugettext(u"Services"))
        if settings.SHOW_SIGNAGES_ON_MAP_SCREENSHOT:
            maplayers.append(ugettext(u"Signages"))
        if settings.SHOW_INFRASTRUCTURES_ON_MAP_SCREENSHOT:
            maplayers.append(ugettext(u"Infrastructures"))
        return {"maplayers": maplayers}


Path.add_property('treks', Trek.path_treks, _(u"Treks"))
Topology.add_property('treks', Trek.topology_treks, _(u"Treks"))
if settings.HIDE_PUBLISHED_TREKS_IN_TOPOLOGIES:
    Topology.add_property('published_treks', lambda self: [], _(u"Published treks"))
else:
    Topology.add_property('published_treks', lambda self: intersecting(Trek, self).filter(published=True), _(u"Published treks"))
Intervention.add_property('treks', lambda self: self.topology.treks if self.topology else [], _(u"Treks"))
Project.add_property('treks', lambda self: self.edges_by_attr('treks'), _(u"Treks"))
tourism_models.TouristicContent.add_property('treks', lambda self: intersecting(Trek, self), _(u"Treks"))
tourism_models.TouristicContent.add_property('published_treks', lambda self: intersecting(Trek, self).filter(published=True), _(u"Published treks"))
tourism_models.TouristicEvent.add_property('treks', lambda self: intersecting(Trek, self), _(u"Treks"))
tourism_models.TouristicEvent.add_property('published_treks', lambda self: intersecting(Trek, self).filter(published=True), _(u"Published treks"))


class TrekRelationshipManager(models.Manager):
    use_for_related_fields = True

    def get_queryset(self):
        # Select treks foreign keys by default
        qs = super(TrekRelationshipManager, self).get_queryset().select_related('trek_a', 'trek_b')
        # Exclude deleted treks
Esempio n. 25
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()

    def is_public(self):
        return self.published

    @property
    def pretty_period(self):
        return self.species.pretty_period()
    pretty_period_verbose_name = _("Period")

    @property
    def pretty_practices(self):
        return self.species.pretty_practices()
    pretty_practices_verbose_name = _("Practices")


if 'geotrek.core' in settings.INSTALLED_APPS:
    from geotrek.core.models import Topology
    Topology.add_property('sensitive_areas', lambda self: intersecting(SensitiveArea, self, settings.SENSITIVE_AREA_INTERSECTION_MARGIN), _(u"Sensitive areas"))
    Topology.add_property('published_sensitive_areas', lambda self: intersecting(SensitiveArea, self, settings.SENSITIVE_AREA_INTERSECTION_MARGIN).filter(published=True), _(u"Published sensitive areas"))