summaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
Diffstat (limited to 'app')
-rw-r--r--app/books/migrations/0007_auto_20190131_2351.py24
-rw-r--r--app/income/migrations/0006_auto_20190131_2351.py17
-rw-r--r--app/jrnl/migrations/0025_auto_20190131_2335.py28
-rw-r--r--app/jrnl/migrations/0026_entry_country_name.py18
-rw-r--r--app/jrnl/models.py24
-rw-r--r--app/jrnl/views.py49
-rw-r--r--app/links/admin.py2
-rw-r--r--app/links/forms.py13
-rw-r--r--app/locations/admin.py6
-rw-r--r--app/locations/migrations/0015_luxcheckin.py33
-rw-r--r--app/locations/models.py38
-rw-r--r--app/photos/models.py30
-rw-r--r--app/photos/templatetags/get_size_by_name.py8
-rw-r--r--app/sightings/admin.py4
-rw-r--r--app/sightings/autocomplete_light_registry.py14
-rw-r--r--app/sightings/forms.py12
-rw-r--r--app/sightings/views.py12
-rw-r--r--app/utils/views.py21
18 files changed, 241 insertions, 112 deletions
diff --git a/app/books/migrations/0007_auto_20190131_2351.py b/app/books/migrations/0007_auto_20190131_2351.py
new file mode 100644
index 0000000..a8a6c8a
--- /dev/null
+++ b/app/books/migrations/0007_auto_20190131_2351.py
@@ -0,0 +1,24 @@
+# Generated by Django 2.1.1 on 2019-01-31 23:51
+
+from django.db import migrations
+
+
+class Migration(migrations.Migration):
+
+ dependencies = [
+ ('books', '0006_book_amazon_url'),
+ ]
+
+ operations = [
+ migrations.RemoveField(
+ model_name='booknote',
+ name='bookhighlight_ptr',
+ ),
+ migrations.RemoveField(
+ model_name='book',
+ name='amazon_url',
+ ),
+ migrations.DeleteModel(
+ name='BookNote',
+ ),
+ ]
diff --git a/app/income/migrations/0006_auto_20190131_2351.py b/app/income/migrations/0006_auto_20190131_2351.py
new file mode 100644
index 0000000..1c8f64c
--- /dev/null
+++ b/app/income/migrations/0006_auto_20190131_2351.py
@@ -0,0 +1,17 @@
+# Generated by Django 2.1.1 on 2019-01-31 23:51
+
+from django.db import migrations
+
+
+class Migration(migrations.Migration):
+
+ dependencies = [
+ ('income', '0005_invoice_slug'),
+ ]
+
+ operations = [
+ migrations.AlterModelOptions(
+ name='invoiceitem',
+ options={'ordering': ('time_start',)},
+ ),
+ ]
diff --git a/app/jrnl/migrations/0025_auto_20190131_2335.py b/app/jrnl/migrations/0025_auto_20190131_2335.py
new file mode 100644
index 0000000..60b9a8c
--- /dev/null
+++ b/app/jrnl/migrations/0025_auto_20190131_2335.py
@@ -0,0 +1,28 @@
+# Generated by Django 2.1.1 on 2019-01-31 23:35
+
+from django.db import migrations, models
+
+
+class Migration(migrations.Migration):
+
+ dependencies = [
+ ('jrnl', '0024_auto_20180902_1217'),
+ ]
+
+ operations = [
+ migrations.AddField(
+ model_name='entry',
+ name='location_name',
+ field=models.CharField(blank=True, max_length=200, null=True),
+ ),
+ migrations.AddField(
+ model_name='entry',
+ name='region_name',
+ field=models.CharField(blank=True, max_length=200, null=True),
+ ),
+ migrations.AddField(
+ model_name='entry',
+ name='state_name',
+ field=models.CharField(blank=True, max_length=200, null=True),
+ ),
+ ]
diff --git a/app/jrnl/migrations/0026_entry_country_name.py b/app/jrnl/migrations/0026_entry_country_name.py
new file mode 100644
index 0000000..22d07f9
--- /dev/null
+++ b/app/jrnl/migrations/0026_entry_country_name.py
@@ -0,0 +1,18 @@
+# Generated by Django 2.1.1 on 2019-01-31 23:35
+
+from django.db import migrations, models
+
+
+class Migration(migrations.Migration):
+
+ dependencies = [
+ ('jrnl', '0025_auto_20190131_2335'),
+ ]
+
+ operations = [
+ migrations.AddField(
+ model_name='entry',
+ name='country_name',
+ field=models.CharField(blank=True, max_length=200, null=True),
+ ),
+ ]
diff --git a/app/jrnl/models.py b/app/jrnl/models.py
index 809353c..5b7457a 100644
--- a/app/jrnl/models.py
+++ b/app/jrnl/models.py
@@ -4,6 +4,7 @@ import os
from django.dispatch import receiver
from django.contrib.gis.db import models
from django.urls import reverse
+from django.utils.functional import cached_property
from django.apps import apps
from django.conf import settings
from django.contrib.sitemaps import Sitemap
@@ -44,6 +45,10 @@ class Entry(models.Model):
enable_comments = models.BooleanField(default=False)
point = models.PointField(null=True, blank=True)
location = models.ForeignKey(Location, on_delete=models.CASCADE, null=True, blank=True)
+ location_name = models.CharField(max_length=200, blank=True, null=True)
+ state_name = models.CharField(max_length=200, blank=True, null=True)
+ country_name = models.CharField(max_length=200, blank=True, null=True)
+ region_name = models.CharField(max_length=200, blank=True, null=True)
PUB_STATUS = (
(0, 'Draft'),
(1, 'Published'),
@@ -122,20 +127,7 @@ class Entry(models.Model):
print(self.image.url)
image_dir, img = self.image.url.split('post-images/')[1].split('/')
print(image_dir, img)
- return '%spost-images/%s/%s' % (settings.IMAGES_URL, image_dir, img)
-
-
- @property
- def state(self):
- return self.location.state
-
- @property
- def country(self):
- return self.location.state.country
-
- @property
- def region(self):
- return self.location.state.country.lux_region
+ return '%spost-images/%s/%s' % (settings.IMAGES_URL, image_dir, img)
@property
def longitude(self):
@@ -184,6 +176,10 @@ class Entry(models.Model):
self.location = Location.objects.filter(geometry__contains=self.point).get()
except Location.DoesNotExist:
raise forms.ValidationError("There is no location associated with that point, add it: %sadmin/locations/location/add/" % (settings.BASE_URL))
+ self.location_name = self.location.name
+ self.state_name = self.location.state.name
+ self.country_name = self.location.state.country.name
+ self.region_name = self.location.state.country.lux_region.name
if created and not self.featured_image:
self.featured_image = LuxImage.objects.latest()
old = type(self).objects.get(pk=self.pk) if self.pk else None
diff --git a/app/jrnl/views.py b/app/jrnl/views.py
index cd63482..5dc627e 100644
--- a/app/jrnl/views.py
+++ b/app/jrnl/views.py
@@ -9,7 +9,7 @@ from django.db.models import Q
from utils.views import PaginatedListView
from .models import Entry, HomepageCurrator, Home
-from locations.models import CheckIn, Country, Region, Location
+from locations.models import LuxCheckIn, Country, Region, Location
from sightings.models import Sighting
@@ -17,8 +17,12 @@ class EntryList(PaginatedListView):
"""
Return a list of Entries in reverse chronological order
"""
- queryset = Entry.objects.filter(status__exact=1).order_by('-pub_date').select_related()
- template_name = "archives/jrnl.html"
+ model = Entry
+
+ def get_queryset(self):
+ queryset = super(EntryList, self).get_queryset()
+ print(queryset)
+ return queryset.filter(status__exact=1).order_by('-pub_date').select_related('location').prefetch_related('featured_image')
class EntryCountryList(PaginatedListView):
@@ -72,21 +76,21 @@ class EntryDetailView(DetailView):
template_name = "details/entry.html"
slug_field = "slug"
- def get_object(self):
- obj = get_object_or_404(
- self.model,
- slug=self.kwargs['slug'],
- pub_date__month=self.kwargs['month'],
- pub_date__year=self.kwargs['year']
- )
+ def get_queryset(self):
+ queryset = super(EntryDetailView, self).get_queryset()
+ return queryset.select_related('location').prefetch_related('field_notes').prefetch_related('books')
+
+ def get_object(self, queryset=None):
+ obj = super(EntryDetailView, self).get_object(queryset=queryset)
+ self.location = obj.location
return obj
def get_context_data(self, **kwargs):
context = super(EntryDetailView, self).get_context_data(**kwargs)
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")
+ Q(location=self.location) |
+ Q(location__in=Location.objects.filter(parent=self.location))
+ ).select_related().order_by('ap_id', 'ap__apclass__kind').distinct("ap")
return context
@@ -98,19 +102,24 @@ class HomepageList(ListView):
"""
Return a main entry and list of Entries in reverse chronological order
"""
- context_object_name = 'recent'
- exclude = Home.objects.get(pk=1)
- queryset = Entry.objects.filter(status__exact=1).exclude(pk=exclude.featured.pk)[:8]
+ model = Entry
+
+ def get_home(self):
+ return Home.objects.filter(pk=1).prefetch_related('featured_image').select_related('featured').select_related('featured__location').get()
+
+ def get_queryset(self):
+ queryset = super(HomepageList, self).get_queryset()
+ self.home = self.get_home()
+ return queryset.filter(status__exact=1).order_by('-pub_date').exclude().select_related('location').select_related('featured_image')[:8]
def get_template_names(self):
- obj = Home.objects.get(pk=1)
- return ['%s' % obj.template_name]
+ return ['%s' % self.home.template_name]
def get_context_data(self, **kwargs):
# Call the base implementation first to get a context
context = super(HomepageList, self).get_context_data(**kwargs)
- context['homepage'] = Home.objects.get(pk=1)
- context['location'] = CheckIn.objects.latest()
+ context['homepage'] = self.home
+ context['location'] = LuxCheckIn.objects.latest()
context['IMAGES_URL'] = settings.IMAGES_URL
return context
diff --git a/app/links/admin.py b/app/links/admin.py
index 3bec927..b1aabc0 100644
--- a/app/links/admin.py
+++ b/app/links/admin.py
@@ -7,12 +7,10 @@ from django.http import HttpResponseRedirect
from utils.widgets import TagListFilter
from .models import Link
-from .forms import LinkForm
@admin.register(Link)
class LinkAdmin(admin.ModelAdmin):
- form = LinkForm
list_display = ('title', 'admin_link', 'pub_date', 'status')
search_fields = ['title', 'description', 'url']
list_filter = ['status', TagListFilter]
diff --git a/app/links/forms.py b/app/links/forms.py
index 80a7c50..b7a2343 100644
--- a/app/links/forms.py
+++ b/app/links/forms.py
@@ -1,17 +1,4 @@
from django import forms
-import dal
-from dal_select2_taggit.widgets import TaggitSelect2
from .models import Link
from dal import autocomplete
-
-
-class LinkForm(autocomplete.FutureModelForm):
- class Meta:
- model = Link
- fields = ('tags',)
- widgets = {
- 'tags': autocomplete.TaggitSelect2(
- 'tag-autocomplete'
- )
- }
diff --git a/app/locations/admin.py b/app/locations/admin.py
index 26001a4..d644548 100644
--- a/app/locations/admin.py
+++ b/app/locations/admin.py
@@ -1,7 +1,7 @@
from django.contrib import admin
from django.contrib.gis.admin import OSMGeoAdmin
-from .models import Region, Country, Location, State, Route, CheckIn, Campsite
+from .models import Region, Country, Location, State, Route, LuxCheckIn, Campsite
from utils.widgets import OLAdminBase
from utils.util import get_latlon
@@ -236,8 +236,8 @@ class RouteAdmin(OSMGeoAdmin):
openlayers_url = '/static/admin/js/OpenLayers.js'
-@admin.register(CheckIn)
-class CheckInAdmin(OLAdminBase):
+@admin.register(LuxCheckIn)
+class LuxCheckInAdmin(OLAdminBase):
list_display = ('date', 'location')
# options for OSM map Using custom ESRI topo map
default_lat, default_lon = get_latlon()
diff --git a/app/locations/migrations/0015_luxcheckin.py b/app/locations/migrations/0015_luxcheckin.py
new file mode 100644
index 0000000..085bd9c
--- /dev/null
+++ b/app/locations/migrations/0015_luxcheckin.py
@@ -0,0 +1,33 @@
+# Generated by Django 2.1.1 on 2019-01-31 23:53
+
+import django.contrib.gis.db.models.fields
+from django.db import migrations, models
+import django.db.models.deletion
+import django.utils.timezone
+
+
+class Migration(migrations.Migration):
+
+ dependencies = [
+ ('locations', '0014_delete_mexstates'),
+ ]
+
+ operations = [
+ migrations.CreateModel(
+ name='LuxCheckIn',
+ fields=[
+ ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
+ ('point', django.contrib.gis.db.models.fields.PointField(blank=True, srid=4326)),
+ ('date', models.DateField(default=django.utils.timezone.now)),
+ ('location_name', models.CharField(blank=True, max_length=200, null=True)),
+ ('state_name', models.CharField(blank=True, max_length=200, null=True)),
+ ('country_name', models.CharField(blank=True, max_length=200, null=True)),
+ ('region_name', models.CharField(blank=True, max_length=200, null=True)),
+ ('location', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, to='locations.Location')),
+ ],
+ options={
+ 'ordering': ('-date',),
+ 'get_latest_by': 'date',
+ },
+ ),
+ ]
diff --git a/app/locations/models.py b/app/locations/models.py
index 3ec11b5..203e175 100644
--- a/app/locations/models.py
+++ b/app/locations/models.py
@@ -204,6 +204,44 @@ class CheckIn(models.Model):
super(CheckIn, self).save()
+class LuxCheckIn(models.Model):
+ point = models.PointField(blank=True)
+ location = models.ForeignKey(Location, on_delete=models.CASCADE, blank=True, null=True)
+ date = models.DateField(default=timezone.now)
+ location_name = models.CharField(max_length=200, blank=True, null=True)
+ state_name = models.CharField(max_length=200, blank=True, null=True)
+ country_name = models.CharField(max_length=200, blank=True, null=True)
+ region_name = models.CharField(max_length=200, blank=True, null=True)
+
+ class Meta:
+ ordering = ('-date',)
+ get_latest_by = 'date'
+
+ def __str__(self):
+ return str(self.date)
+
+ @property
+ def lon(self):
+ '''Get the site's longitude.'''
+ return self.point.x
+
+ @property
+ def lat(self):
+ '''Get the site's latitude.'''
+ return self.point.y
+
+ def save(self):
+ try:
+ self.location = Location.objects.filter(geometry__contains=self.point).get()
+ except Location.DoesNotExist:
+ raise forms.ValidationError("There is no location associated with that point, add it: %sadmin/locations/location/add/" % (settings.BASE_URL))
+ self.location_name = self.location.name
+ self.state_name = self.location.state.name
+ self.country_name = self.location.state.country.name
+ self.region_name = self.location.state.country.lux_region.name
+ super(LuxCheckIn, self).save()
+
+
class Campsite(models.Model):
name = models.CharField(max_length=200)
point = models.PointField(blank=True)
diff --git a/app/photos/models.py b/app/photos/models.py
index eb4b55e..2e022e2 100644
--- a/app/photos/models.py
+++ b/app/photos/models.py
@@ -7,6 +7,7 @@ from django.core.exceptions import ValidationError
from django.contrib.gis.db import models
from django.contrib.sitemaps import Sitemap
from django.utils.encoding import force_text
+from django.utils.functional import cached_property
from django.urls import reverse
from django.apps import apps
from django.utils.html import format_html
@@ -111,6 +112,32 @@ class LuxImage(models.Model):
def get_image_ext(self):
return self.image.url[-3:]
+ @cached_property
+ def get_featured_jrnl(self):
+ ''' cached version of getting the primary image for archive page'''
+ return "%s%s/%s_%s.%s" % (settings.IMAGES_URL, self.pub_date.strftime("%Y"), self.get_image_name(), 'featured_jrnl', self.get_image_ext())
+
+ @cached_property
+ def get_picwide_sm(self):
+ ''' cached version of getting the second image for archive page'''
+ return "%s%s/%s_%s.%s" % (settings.IMAGES_URL, self.pub_date.strftime("%Y"), self.get_image_name(), 'picwide-sm', self.get_image_ext())
+
+ @cached_property
+ def get_srcset(self):
+ srcset = ""
+ for size in self.sizes.all():
+ srcset += "%s%s/%s_%s.%s %sw, " % (settings.IMAGES_URL, self.pub_date.strftime("%Y"), self.get_image_name(), size.name, self.get_image_ext(), size.width)
+ return srcset
+
+ @cached_property
+ def get_src(self):
+ src = ""
+ if self.sizes.all().count() > 1:
+ src += "%s%s/%s_%s.%s" % (settings.IMAGES_URL, self.pub_date.strftime("%Y"), self.get_image_name(), 'picwide-med', self.get_image_ext())
+ else:
+ src += "%s%s/%s_%s.%s" % (settings.IMAGES_URL, self.pub_date.strftime("%Y"), self.get_image_name(), [size.name for size in self.sizes.all()], self.get_image_ext())
+ return src
+
def get_image_by_size(self, size="original"):
base = self.get_image_name()
if size == "admin_insert":
@@ -136,6 +163,9 @@ class LuxImage(models.Model):
return format_html('<a href="%s"><img src="%s"></a>' % (self.get_image_by_size(), self.get_image_by_size("tn")))
admin_thumbnail.short_description = 'Thumbnail'
+ def get_sizes(self):
+ return self.sizes.all()
+
@property
def latitude(self):
return self.point.y
diff --git a/app/photos/templatetags/get_size_by_name.py b/app/photos/templatetags/get_size_by_name.py
new file mode 100644
index 0000000..fc64a61
--- /dev/null
+++ b/app/photos/templatetags/get_size_by_name.py
@@ -0,0 +1,8 @@
+from django import template
+
+register = template.Library()
+
+@register.simple_tag
+def get_size_by_name(obj, *args):
+ method = getattr(obj, "get_size_by_name")
+ return method(*args)
diff --git a/app/sightings/admin.py b/app/sightings/admin.py
index 7108bba..d95dd72 100644
--- a/app/sightings/admin.py
+++ b/app/sightings/admin.py
@@ -1,4 +1,4 @@
-import copy
+import copy
from django.contrib import admin
from django.contrib.gis.admin import OSMGeoAdmin
from .models import APClass, AP, Sighting
@@ -6,7 +6,6 @@ from .models import APClass, AP, Sighting
from photos.forms import GalleryForm
from utils.util import get_latlon
from utils.widgets import CustomSelectMultiple, LGEntryForm
-from .forms import SightingsForm
from django.contrib.admin.options import FORMFIELD_FOR_DBFIELD_DEFAULTS
class GalleryFormPlus(GalleryForm):
@@ -80,7 +79,6 @@ class APAdmin(admin.ModelAdmin):
@admin.register(Sighting)
class SightingAdmin(OSMGeoAdmin):
- form = SightingsForm
list_filter = (('location', admin.RelatedOnlyFieldListFilter),)
list_display = ('ap', 'location')
# options for OSM map Using custom ESRI topo map
diff --git a/app/sightings/autocomplete_light_registry.py b/app/sightings/autocomplete_light_registry.py
deleted file mode 100644
index 9c113d0..0000000
--- a/app/sightings/autocomplete_light_registry.py
+++ /dev/null
@@ -1,14 +0,0 @@
-import autocomplete_light.shortcuts as al
-from .models import AP
-
-al.register(AP,
- search_fields=['common_name',],
- attrs={
- 'placeholder': 'Animal/Plant...',
- 'data-autocomplete-minimum-characters': 2,
- },
- widget_attrs={
- 'data-widget-maximum-values': 4,
- 'class': 'modern-style',
- },
-)
diff --git a/app/sightings/forms.py b/app/sightings/forms.py
deleted file mode 100644
index 77d61f9..0000000
--- a/app/sightings/forms.py
+++ /dev/null
@@ -1,12 +0,0 @@
-from dal import autocomplete
-
-from .models import Sighting
-
-
-class SightingsForm(autocomplete.FutureModelForm):
- class Meta:
- model = Sighting
- fields = ('pub_date','ap', 'point',)
- widgets = {
- 'ap': autocomplete.ModelSelect2(url='ap-autocomplete')
- }
diff --git a/app/sightings/views.py b/app/sightings/views.py
index f65011c..c90e5c1 100644
--- a/app/sightings/views.py
+++ b/app/sightings/views.py
@@ -3,7 +3,6 @@ from django.views.generic import ListView
from django.contrib.auth.models import User
from utils.views import PaginatedListView
from .models import AP, Sighting
-from dal import autocomplete
class SightingListView(PaginatedListView):
@@ -57,14 +56,3 @@ class SightingDetailView(DetailView):
except Sighting.DoesNotExist:
pass
return context
-
-
-class APAutocomplete(autocomplete.Select2QuerySetView):
- def get_queryset(self):
- if not self.request.user.is_authenticated:
- return AP.objects.none()
- qs = AP.objects.all()
- if self.q:
- qs = qs.filter(common_name__icontains=self.q)
- return qs
-
diff --git a/app/utils/views.py b/app/utils/views.py
index dcb16a8..cd72961 100644
--- a/app/utils/views.py
+++ b/app/utils/views.py
@@ -2,11 +2,13 @@ from itertools import chain
import json
from django.http import Http404, HttpResponse
from django.views.generic import ListView
+from django.apps import apps
from photos.models import LuxImage, LuxVideo
from django.shortcuts import render_to_response
from django.shortcuts import render
from django.template import RequestContext
+
class PaginatedListView(ListView):
"""
handles my own pagination system
@@ -38,26 +40,7 @@ def insert_image(request):
reverse=True
)
return render(request, 'admin/insert_images.html', {'object_list': object_list, 'textarea_id': request.GET['textarea']})
-
-
-from taggit.models import Tag
-
-from dal import autocomplete
-
-class TagAutocomplete(autocomplete.Select2QuerySetView):
- def get_queryset(self):
- # Don't forget to filter out results depending on the visitor !
- if not self.request.user.is_authenticated:
- return Tag.objects.none()
- qs = Tag.objects.all()
-
- if self.q:
- qs = qs.filter(name__istartswith=self.q)
-
- return qs
-
-from django.apps import apps
def nav_json(request, app, model, pk):
model = apps.get_model(app_label=app, model_name=model)