diff options
Diffstat (limited to 'app/unused_apps/trips')
-rw-r--r-- | app/unused_apps/trips/__init__.py | 0 | ||||
-rw-r--r-- | app/unused_apps/trips/admin.py | 34 | ||||
-rw-r--r-- | app/unused_apps/trips/migrations/0001_initial.py | 31 | ||||
-rw-r--r-- | app/unused_apps/trips/migrations/__init__.py | 0 | ||||
-rw-r--r-- | app/unused_apps/trips/models.py | 40 | ||||
-rw-r--r-- | app/unused_apps/trips/urls.py | 24 | ||||
-rw-r--r-- | app/unused_apps/trips/views.py | 101 |
7 files changed, 230 insertions, 0 deletions
diff --git a/app/unused_apps/trips/__init__.py b/app/unused_apps/trips/__init__.py new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/app/unused_apps/trips/__init__.py diff --git a/app/unused_apps/trips/admin.py b/app/unused_apps/trips/admin.py new file mode 100644 index 0000000..54991f6 --- /dev/null +++ b/app/unused_apps/trips/admin.py @@ -0,0 +1,34 @@ +from django.contrib import admin +from django.contrib.gis.admin import OSMGeoAdmin + +from .models import Trip + +from utils.widgets import OLAdminBase +from utils.util import get_latlon +from utils.widgets import LGEntryForm + +@admin.register(Trip) +class TripAdmin(OSMGeoAdmin): + list_display = ('title', 'slug') + prepopulated_fields = {'slug': ('title',)} + ordering = ('title',) + search_fields = ['title'] + list_select_related = True + fieldsets = ( + ('Trip', { + 'fields': ( + 'title', + 'subtitle', + 'dek_markdown', + 'route', + 'slug', + 'start_date', + 'end_date', + 'pub_date', + ), + 'classes': ( + 'show', + 'extrapretty' + ) + }), + ) diff --git a/app/unused_apps/trips/migrations/0001_initial.py b/app/unused_apps/trips/migrations/0001_initial.py new file mode 100644 index 0000000..3d3c222 --- /dev/null +++ b/app/unused_apps/trips/migrations/0001_initial.py @@ -0,0 +1,31 @@ +# Generated by Django 2.1.7 on 2019-06-15 09:17 + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + initial = True + + dependencies = [ + ('locations', '0018_auto_20190414_2124'), + ] + + operations = [ + migrations.CreateModel( + name='Trip', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('title', models.CharField(max_length=50)), + ('subtitle', models.CharField(blank=True, max_length=200)), + ('slug', models.SlugField(unique_for_date='pub_date')), + ('dek_markdown', models.TextField()), + ('dek_html', models.TextField(blank=True, null=True)), + ('pub_date', models.DateTimeField(verbose_name='Date published')), + ('start_date', models.DateTimeField(verbose_name='Date started')), + ('end_date', models.DateTimeField(verbose_name='Date ended')), + ('route', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='locations.Route')), + ], + ), + ] diff --git a/app/unused_apps/trips/migrations/__init__.py b/app/unused_apps/trips/migrations/__init__.py new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/app/unused_apps/trips/migrations/__init__.py diff --git a/app/unused_apps/trips/models.py b/app/unused_apps/trips/models.py new file mode 100644 index 0000000..76941f2 --- /dev/null +++ b/app/unused_apps/trips/models.py @@ -0,0 +1,40 @@ +import json +import requests +from django import forms +from django.urls import reverse +from django.apps import apps +from django.contrib.gis.geos import GEOSGeometry, fromstr, MultiPolygon +from django.contrib.gis.db import models +from django.contrib.sitemaps import Sitemap +from django.utils.safestring import mark_safe +from django.utils import timezone +from django.conf import settings + +from utils.util import render_images, extract_main_image, markdown_to_html +from locations.models import Route + + +class Trip(models.Model): + """Model to define trips""" + title = models.CharField(max_length=50) + subtitle = models.CharField(max_length=200, blank=True) + slug = models.SlugField(unique_for_date='pub_date') + dek_markdown = models.TextField() + dek_html = models.TextField(null=True, blank=True) + pub_date = models.DateTimeField('Date published') + start_date = models.DateTimeField('Date started') + end_date = models.DateTimeField('Date ended') + route = models.ForeignKey(Route, on_delete=models.CASCADE) + + def get_absolute_url(self): + return "/trips/%s/" % (self.slug) + + def __str__(self): + return self.title + + def save(self, *args, **kwargs): + created = self.pk is None + if not created: + md = render_images(self.dek_markdown) + self.dek_html = markdown_to_html(md) + super(Trip, self).save(*args, **kwargs) diff --git a/app/unused_apps/trips/urls.py b/app/unused_apps/trips/urls.py new file mode 100644 index 0000000..205c450 --- /dev/null +++ b/app/unused_apps/trips/urls.py @@ -0,0 +1,24 @@ +from django.urls import path, re_path + +from . import views + +app_name = "trips" + +urlpatterns = [ + path( + r'<str:slug>', + views.LocationDetail.as_view(), + name="location-detail" + ), + path( + r'mapdata/', + views.MapDataList.as_view(), + name="mapdata" + ), + re_path(r'data/(?P<id>\d+)/$', views.data_json), + path( + r'', + views.MapList.as_view(), + name="maplist" + ), +] 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 |