summaryrefslogtreecommitdiff
path: root/app/unused_apps/trips/views.py
diff options
context:
space:
mode:
Diffstat (limited to 'app/unused_apps/trips/views.py')
-rw-r--r--app/unused_apps/trips/views.py101
1 files changed, 101 insertions, 0 deletions
diff --git a/app/unused_apps/trips/views.py b/app/unused_apps/trips/views.py
new file mode 100644
index 0000000..3a93c0d
--- /dev/null
+++ b/app/unused_apps/trips/views.py
@@ -0,0 +1,101 @@
+from django.shortcuts import render_to_response
+from django.template import RequestContext
+from django.views.generic import ListView
+from django.views.generic.detail import DetailView
+from django.conf import settings
+from django.db.models import Q
+
+from jrnl.models import Entry
+from projects.shortcuts import render_to_geojson
+from sightings.models import Sighting
+
+from .models import Country, Region, Route, Location
+
+def map_list(request):
+ context = {
+ 'object_list': Entry.objects.filter(status__exact=1),
+ 'country_list': Country.objects.filter(visited=True).exclude(name='default'),
+ 'route_list': Route.objects.all(),
+ 'region_list': Region.objects.all()
+ }
+ return render_to_response(
+ 'archives/map.html',
+ context,
+ context_instance=RequestContext(request)
+ )
+
+class MapList(ListView):
+ """
+ Return list of Entries on map
+ """
+ context_object_name = 'object_list'
+ queryset = Entry.objects.filter(status__exact=1)
+ template_name = 'archives/map.html'
+
+ def get_context_data(self, **kwargs):
+ # Call the base implementation first to get a context
+ context = super(MapList, self).get_context_data(**kwargs)
+ context['country_list'] = Country.objects.filter(visited=True).exclude(name='default'),
+ context['route_list'] = Route.objects.all(),
+ context['region_list'] = Region.objects.all()
+ context['IMAGES_URL'] = settings.IMAGES_URL
+ return context
+
+
+class MapDataList(ListView):
+ """
+ Build data file for Entries on map
+ """
+ context_object_name = 'object_list'
+ queryset = Entry.objects.filter(status__exact=1)
+ template_name = 'archives/map_data.html'
+
+ def get_context_data(self, **kwargs):
+ # Call the base implementation first to get a context
+ context = super(MapDataList, self).get_context_data(**kwargs)
+ context['country_list'] = Country.objects.filter(visited=True).exclude(name='default'),
+ context['route_list'] = Route.objects.all(),
+ context['region_list'] = Region.objects.all()
+ context['IMAGES_URL'] = settings.IMAGES_URL
+ return context
+
+def map_data(request):
+ context = {
+ 'object_list': Entry.objects.filter(status__exact=1),
+ 'route_list': Route.objects.all(),
+ 'country_list': Country.objects.filter(visited=True).exclude(name='default'),
+ 'region_list': Region.objects.all()
+ }
+ return render_to_response(
+ 'archives/map_data.html',
+ context,
+ context_instance=RequestContext(request)
+ )
+
+
+def data_json(request, id):
+ qs = Route.objects.filter(pk=id)
+ return render_to_geojson(
+ qs,
+ included_fields=['id', ],
+ geom_attribute='geometry',
+ mimetype='application/json',
+ pretty_print=True
+ )
+
+
+class LocationDetail(DetailView):
+ model = Location
+ template_name = "details/location.html"
+
+ def get_context_data(self, **kwargs):
+ context = super(LocationDetail, self).get_context_data(**kwargs)
+ context['entry_list'] = Entry.objects.filter(
+ Q(location=self.get_object()) |
+ Q(location__in=Location.objects.filter(parent=self.get_object()))
+ )
+ context['sighting_list'] = Sighting.objects.filter(
+ Q(location=self.get_object()) |
+ Q(location__in=Location.objects.filter(parent=self.get_object()))
+ ).order_by('ap_id', 'ap__apclass__kind').distinct("ap")
+ return context