Esempio n. 1
0
    def get_context_data(self, **kwargs):
        if self.request.is_ajax():
            context = {}
        else:
            context = super().get_context_data(**kwargs)
            activities = Activity.objects.values("id", "name").order_by("id")
            context["activities"] = [{
                "id": -1,
                "name": _("All activities")
            }] + list(activities)
            context["selected_activity"] = self.get_selected_activity()

            context["locations"] = [{
                "location_id": -1,
                "name": "All locations"
            }] + list(
                self.organization.locations.values("location_id",
                                                   "name").order_by("name"))
            context["selected_location"] = self.get_selected_location()

            context["default_sport"] = self.get_query("activity") or 1
            context["map_style"] = "admin-trail-list"
            context["poi_categories"] = get_poi_categories()

        trails = self.get_trails()
        context["geo_json"] = serialize(
            "geojson",
            trails.filter(shape__isnull=False),
            geometry_field="shape",
            fields=("pk", "trail_id", "name"),
        )
        context["trails"] = TrailThinSerializer(trails, many=True).data
        return context
Esempio n. 2
0
 def get_context_data(self, **kwargs):
     context = super().get_context_data(**kwargs)
     activities = Activity.objects.values("id", "name").order_by("id")
     context["activities"] = list(activities)
     context["types"] = Trail.PATH_TYPES
     context["difficulties"] = TrailActivity.DIFFICULTY_CHOICES
     context["no_footer"] = True
     context["map_style"] = "results"
     context["poi_categories"] = get_poi_categories()
     context["default_sport"] = 1
     return context
Esempio n. 3
0
 def get_context_data(self, **kwargs):
     context = super().get_context_data(**kwargs)
     locations = self.organization.locations.all()
     context["default_sport"] = 1
     context["geo_json"] = serialize(
         "geojson",
         locations,
         geometry_field="shape",
         fields=("pk", "location_id", "name"),
     )
     context["map_style"] = "admin-location-list"
     context["poi_categories"] = get_poi_categories()
     context["locations"] = list(
         locations.values("location_id", "name", "modified_date"))
     return context
Esempio n. 4
0
    def get_context_data(self, **kwargs):
        context = super().get_context_data(**kwargs)
        self.calculate_difficulty_and_duration()
        self.object.refresh_from_db()
        context["banner"] = static("img/accueil-1.jpeg")
        banner = self.object.banner
        if banner and banner.image:
            context["banner"] = self.request.build_absolute_uri(
                banner.image.url)
        context["geo_json"] = serialize(
            "geojson",
            self.model.objects.filter(pk=self.object.pk),
            geometry_field="shape",
        )
        context["map_style"] = "trail"
        context["trail_location"] = {
            "location_id": getattr(self.object.location, "location_id", 0),
            "name": getattr(self.object.location, "name", ""),
        }
        context["poi_categories"] = get_poi_categories()
        context["default_sport"] = 1
        shape = self.object.shape
        if shape:
            if isinstance(shape, LineString):
                lat = shape[0][1]
                lng = shape[0][0]
            elif isinstance(shape, MultiLineString):
                lat = shape[0][0][1]
                lng = shape[0][0][0]
            else:
                center = shape.centroid
                lat = center.y
                lng = center.x

            context["stay22"] = {"lat": lat, "lng": lng}
        return context
Esempio n. 5
0
 def __init__(self, **kwargs):
     super().__init__(**kwargs)
     self.poi_categories = get_poi_categories()