summaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
Diffstat (limited to 'app')
-rw-r--r--app/jrnl/admin.py3
-rw-r--r--app/jrnl/views.py8
-rw-r--r--app/locations/admin.py8
-rw-r--r--app/locations/migrations/0004_location_child.py19
-rw-r--r--app/locations/migrations/0005_auto_20180629_1714.py18
-rw-r--r--app/locations/migrations/0006_auto_20180629_1739.py18
-rw-r--r--app/locations/models.py1
-rw-r--r--app/locations/urls.py5
-rw-r--r--app/locations/views.py28
9 files changed, 97 insertions, 11 deletions
diff --git a/app/jrnl/admin.py b/app/jrnl/admin.py
index 9a39114..e77b931 100644
--- a/app/jrnl/admin.py
+++ b/app/jrnl/admin.py
@@ -29,13 +29,12 @@ class EntryAdmin(OSMGeoAdmin):
search_fields = ['title', 'body_markdown']
prepopulated_fields = {"slug": ('title',)}
list_filter = ('pub_date', 'enable_comments', 'status', 'location__state__country__lux_region')
- filter_horizontal = ('field_notes','books')
+ filter_horizontal = ('field_notes', 'books')
fieldsets = (
('Entry', {
'fields': (
'title',
'body_markdown',
- #'body_html',
('pub_date', 'status'),
'slug',
'point'
diff --git a/app/jrnl/views.py b/app/jrnl/views.py
index 01167db..94d887c 100644
--- a/app/jrnl/views.py
+++ b/app/jrnl/views.py
@@ -4,11 +4,12 @@ from django.views.generic.dates import YearArchiveView, MonthArchiveView
from django.contrib.syndication.views import Feed
from django.shortcuts import get_object_or_404
from django.conf import settings
+from django.db.models import Q
from utils.views import PaginatedListView
from .models import Entry, HomepageCurrator
-from locations.models import CheckIn, Country, Region
+from locations.models import CheckIn, Country, Region, Location
from sightings.models import Sighting
@@ -82,7 +83,10 @@ class EntryDetailView(DetailView):
def get_context_data(self, **kwargs):
context = super(EntryDetailView, self).get_context_data(**kwargs)
- context['wildlife'] = Sighting.objects.filter(location=self.get_object().location).order_by('ap_id', 'ap__apclass__kind').distinct("ap")
+ context['wildlife'] = Sighting.objects.filter(
+ Q(location=self.get_object().location) |
+ Q(location__in=Location.objects.filter(parent=self.get_object().location))
+ ).order_by('ap_id', 'ap__apclass__kind').distinct("ap")
return context
diff --git a/app/locations/admin.py b/app/locations/admin.py
index b538657..4adb836 100644
--- a/app/locations/admin.py
+++ b/app/locations/admin.py
@@ -161,10 +161,11 @@ admin.site.register(State, StateAdmin)
class LocationAdmin(OSMGeoAdmin):
- list_display = ('name', 'slug', 'state', 'pub_date')
+ list_display = ('name', 'pub_date', 'parent', 'state', 'slug')
prepopulated_fields = {'slug': ('name',)}
search_fields = ('name', 'state')
- ordering = ('name',)
+ ordering = ('pub_date', 'name')
+ list_filter = ('pub_date', 'state__country__lux_region', 'state')
save_as = True
search_fields = ['name']
list_select_related = True
@@ -174,7 +175,8 @@ class LocationAdmin(OSMGeoAdmin):
'name',
'slug',
'pub_date',
- 'state'
+ 'state',
+ 'parent'
),
'classes': ('show', 'extrapretty')
}),
diff --git a/app/locations/migrations/0004_location_child.py b/app/locations/migrations/0004_location_child.py
new file mode 100644
index 0000000..94fd324
--- /dev/null
+++ b/app/locations/migrations/0004_location_child.py
@@ -0,0 +1,19 @@
+# Generated by Django 2.0.1 on 2018-06-29 17:11
+
+from django.db import migrations, models
+import django.db.models.deletion
+
+
+class Migration(migrations.Migration):
+
+ dependencies = [
+ ('locations', '0003_auto_20180307_1027'),
+ ]
+
+ operations = [
+ migrations.AddField(
+ model_name='location',
+ name='child',
+ field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, to='locations.Location'),
+ ),
+ ]
diff --git a/app/locations/migrations/0005_auto_20180629_1714.py b/app/locations/migrations/0005_auto_20180629_1714.py
new file mode 100644
index 0000000..04b6f49
--- /dev/null
+++ b/app/locations/migrations/0005_auto_20180629_1714.py
@@ -0,0 +1,18 @@
+# Generated by Django 2.0.1 on 2018-06-29 17:14
+
+from django.db import migrations
+
+
+class Migration(migrations.Migration):
+
+ dependencies = [
+ ('locations', '0004_location_child'),
+ ]
+
+ operations = [
+ migrations.RenameField(
+ model_name='location',
+ old_name='child',
+ new_name='childof',
+ ),
+ ]
diff --git a/app/locations/migrations/0006_auto_20180629_1739.py b/app/locations/migrations/0006_auto_20180629_1739.py
new file mode 100644
index 0000000..f47b6e9
--- /dev/null
+++ b/app/locations/migrations/0006_auto_20180629_1739.py
@@ -0,0 +1,18 @@
+# Generated by Django 2.0.1 on 2018-06-29 17:39
+
+from django.db import migrations
+
+
+class Migration(migrations.Migration):
+
+ dependencies = [
+ ('locations', '0005_auto_20180629_1714'),
+ ]
+
+ operations = [
+ migrations.RenameField(
+ model_name='location',
+ old_name='childof',
+ new_name='parent',
+ ),
+ ]
diff --git a/app/locations/models.py b/app/locations/models.py
index f9a3e5b..b4ee6f7 100644
--- a/app/locations/models.py
+++ b/app/locations/models.py
@@ -121,6 +121,7 @@ class Location(models.Model):
slug = models.SlugField()
pub_date = models.DateTimeField('Date published')
geometry = models.MultiPolygonField(srid=4326)
+ parent = models.ForeignKey('self', on_delete=models.CASCADE, blank=True, null=True)
class Meta:
ordering = ('-pub_date',)
diff --git a/app/locations/urls.py b/app/locations/urls.py
index abe9f0a..5faefc1 100644
--- a/app/locations/urls.py
+++ b/app/locations/urls.py
@@ -6,6 +6,11 @@ app_name = "locations"
urlpatterns = [
path(
+ r'<str:country>/<str:state>/<str:slug>/',
+ views.LocationDetail.as_view(),
+ name="location-detail"
+ ),
+ path(
r'mapdata/',
views.MapDataList.as_view(),
name="mapdata"
diff --git a/app/locations/views.py b/app/locations/views.py
index c463eac..3a93c0d 100644
--- a/app/locations/views.py
+++ b/app/locations/views.py
@@ -1,12 +1,15 @@
from django.shortcuts import render_to_response
from django.template import RequestContext
-from jrnl.models import Entry
-from locations.models import Country, Region, Route
-from projects.shortcuts import render_to_geojson
-
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 = {
@@ -79,3 +82,20 @@ def data_json(request, id):
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