summaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
Diffstat (limited to 'app')
-rw-r--r--app/jrnl/migrations/0028_auto_20190218_1614.py33
-rw-r--r--app/jrnl/models.py10
-rw-r--r--app/jrnl/views.py4
-rw-r--r--app/locations/migrations/0016_auto_20190217_1847.py33
-rw-r--r--app/locations/migrations/0017_auto_20190217_1849.py23
-rw-r--r--app/locations/models.py22
-rw-r--r--app/sightings/admin.py34
-rw-r--r--app/sightings/migrations/0008_auto_20190217_1441.py38
-rw-r--r--app/sightings/migrations/0009_fieldnote.py26
-rw-r--r--app/sightings/migrations/0010_auto_20190217_1647.py25
-rw-r--r--app/sightings/migrations/0011_auto_20190217_1702.py29
-rw-r--r--app/sightings/migrations/0012_sighting_ap_common_name.py18
-rw-r--r--app/sightings/migrations/0013_fieldnote_sighting_location.py18
-rw-r--r--app/sightings/models.py74
-rw-r--r--app/sightings/views.py19
15 files changed, 339 insertions, 67 deletions
diff --git a/app/jrnl/migrations/0028_auto_20190218_1614.py b/app/jrnl/migrations/0028_auto_20190218_1614.py
new file mode 100644
index 0000000..aff2331
--- /dev/null
+++ b/app/jrnl/migrations/0028_auto_20190218_1614.py
@@ -0,0 +1,33 @@
+# Generated by Django 2.1.5 on 2019-02-18 16:14
+
+from django.db import migrations
+
+
+class Migration(migrations.Migration):
+
+ dependencies = [
+ ('jrnl', '0027_entry_country_slug'),
+ ]
+
+ operations = [
+ migrations.RemoveField(
+ model_name='entry',
+ name='country_name',
+ ),
+ migrations.RemoveField(
+ model_name='entry',
+ name='country_slug',
+ ),
+ migrations.RemoveField(
+ model_name='entry',
+ name='location_name',
+ ),
+ migrations.RemoveField(
+ model_name='entry',
+ name='region_name',
+ ),
+ migrations.RemoveField(
+ model_name='entry',
+ name='state_name',
+ ),
+ ]
diff --git a/app/jrnl/models.py b/app/jrnl/models.py
index dca4cd4..6c334ae 100644
--- a/app/jrnl/models.py
+++ b/app/jrnl/models.py
@@ -45,11 +45,6 @@ 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)
- country_slug = 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'),
@@ -177,11 +172,6 @@ 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.country_slug = self.location.state.country.slug
- 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 d1c4159..95b5c64 100644
--- a/app/jrnl/views.py
+++ b/app/jrnl/views.py
@@ -23,7 +23,7 @@ class EntryList(PaginatedListView):
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')
+ return queryset.filter(status__exact=1).order_by('-pub_date').prefetch_related('location').prefetch_related('featured_image')
class EntryCountryList(PaginatedListView):
@@ -115,7 +115,7 @@ class HomepageList(ListView):
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')[1:9]
+ return queryset.filter(status__exact=1).order_by('-pub_date').exclude().select_related('location').select_related('featured_image')[2:10]
def get_template_names(self):
return ['%s' % self.home.template_name]
diff --git a/app/locations/migrations/0016_auto_20190217_1847.py b/app/locations/migrations/0016_auto_20190217_1847.py
new file mode 100644
index 0000000..162b489
--- /dev/null
+++ b/app/locations/migrations/0016_auto_20190217_1847.py
@@ -0,0 +1,33 @@
+# Generated by Django 2.1.5 on 2019-02-17 18:47
+
+from django.db import migrations, models
+
+
+class Migration(migrations.Migration):
+
+ dependencies = [
+ ('locations', '0015_luxcheckin'),
+ ]
+
+ operations = [
+ migrations.AddField(
+ model_name='location',
+ name='country_name',
+ field=models.CharField(blank=True, max_length=50),
+ ),
+ migrations.AddField(
+ model_name='location',
+ name='country_slug',
+ field=models.CharField(blank=True, max_length=50),
+ ),
+ migrations.AddField(
+ model_name='location',
+ name='region_name',
+ field=models.CharField(blank=True, max_length=50),
+ ),
+ migrations.AddField(
+ model_name='location',
+ name='state_name',
+ field=models.CharField(blank=True, max_length=50),
+ ),
+ ]
diff --git a/app/locations/migrations/0017_auto_20190217_1849.py b/app/locations/migrations/0017_auto_20190217_1849.py
new file mode 100644
index 0000000..39f3e6f
--- /dev/null
+++ b/app/locations/migrations/0017_auto_20190217_1849.py
@@ -0,0 +1,23 @@
+# Generated by Django 2.1.5 on 2019-02-17 18:49
+
+from django.db import migrations, models
+
+
+class Migration(migrations.Migration):
+
+ dependencies = [
+ ('locations', '0016_auto_20190217_1847'),
+ ]
+
+ operations = [
+ migrations.AddField(
+ model_name='location',
+ name='region_slug',
+ field=models.CharField(blank=True, max_length=50),
+ ),
+ migrations.AddField(
+ model_name='location',
+ name='state_slug',
+ field=models.CharField(blank=True, max_length=50),
+ ),
+ ]
diff --git a/app/locations/models.py b/app/locations/models.py
index 203e175..6e8db7c 100644
--- a/app/locations/models.py
+++ b/app/locations/models.py
@@ -128,6 +128,12 @@ class Location(models.Model):
pub_date = models.DateTimeField('Date published')
geometry = models.MultiPolygonField(srid=4326)
parent = models.ForeignKey('self', on_delete=models.CASCADE, blank=True, null=True)
+ state_name = models.CharField(max_length=50, blank=True)
+ state_slug = models.CharField(max_length=50, blank=True)
+ country_name = models.CharField(max_length=50, blank=True)
+ country_slug = models.CharField(max_length=50, blank=True)
+ region_name = models.CharField(max_length=50, blank=True)
+ region_slug = models.CharField(max_length=50, blank=True)
class Meta:
ordering = ('-pub_date',)
@@ -137,10 +143,10 @@ class Location(models.Model):
return self.name
def comma_name(self):
- if self.state.country.name == "United States":
- return self.state
+ if self.country_name == "United States":
+ return self.state_name
else:
- return self.state.country
+ return self.country_name
@property
def get_previous_admin_url(self):
@@ -155,8 +161,16 @@ class Location(models.Model):
return ''
def get_absolute_url(self):
- return "/locations/%s/%s/%s/" % (self.state.country.slug, self.state.slug, self.slug)
+ return "/locations/%s/%s/%s/" % (self.country_slug, self.state_slug, self.slug)
+ def save(self, *args, **kwargs):
+ self.state_name = self.state.name
+ self.state_slug = self.state.slug
+ self.country_name = self.state.country.name
+ self.country_slug = self.state.country.slug
+ self.region_name = self.state.country.lux_region.name
+ self.region_slug = self.state.country.lux_region.slug
+ super(Location, self).save()
class Route(models.Model):
"""Model to hold routes for longer trips"""
diff --git a/app/sightings/admin.py b/app/sightings/admin.py
index d95dd72..fcbc2ca 100644
--- a/app/sightings/admin.py
+++ b/app/sightings/admin.py
@@ -1,7 +1,7 @@
import copy
from django.contrib import admin
from django.contrib.gis.admin import OSMGeoAdmin
-from .models import APClass, AP, Sighting
+from .models import APClass, AP, Sighting, FieldNote
from photos.forms import GalleryForm
from utils.util import get_latlon
@@ -96,3 +96,35 @@ class SightingAdmin(OSMGeoAdmin):
class Media:
js = ('next-prev-links.js',)
+
+@admin.register(FieldNote)
+class FieldNoteAdmin(admin.ModelAdmin):
+ form = LGEntryForm
+
+ def get_form(self, request, obj=None, **kwargs):
+ form = super(FieldNoteAdmin, self).get_form(request, obj, **kwargs)
+ form.base_fields['sighting'].label_from_instance = lambda obj: "{} - {} - {}".format(obj.ap_common_name, obj.pub_date.strftime("%Y-%b-%d"), obj.location_name)
+ return form
+
+ list_display = ('pk', 'ap_common_name', 'sighting_pub_date', 'sighting_location')
+ fieldsets = (
+ ('', {
+ 'fields': (
+ 'sighting',
+ 'body_markdown',
+ ),
+ 'classes': (
+ 'show',
+ 'extrapretty',
+ 'wide'
+ )
+ }
+ ),
+ )
+
+ class Media:
+ js = ('image-loader.js', 'next-prev-links.js')
+ css = {
+ "all": ("my_styles.css",)
+ }
+
diff --git a/app/sightings/migrations/0008_auto_20190217_1441.py b/app/sightings/migrations/0008_auto_20190217_1441.py
new file mode 100644
index 0000000..8b9389e
--- /dev/null
+++ b/app/sightings/migrations/0008_auto_20190217_1441.py
@@ -0,0 +1,38 @@
+# Generated by Django 2.1.5 on 2019-02-17 14:41
+
+from django.db import migrations, models
+
+
+class Migration(migrations.Migration):
+
+ dependencies = [
+ ('sightings', '0007_merge_20180708_1047'),
+ ]
+
+ operations = [
+ migrations.AddField(
+ model_name='sighting',
+ name='country_name',
+ field=models.CharField(blank=True, max_length=200),
+ ),
+ migrations.AddField(
+ model_name='sighting',
+ name='country_slug',
+ field=models.CharField(blank=True, max_length=200),
+ ),
+ migrations.AddField(
+ model_name='sighting',
+ name='location_name',
+ field=models.CharField(blank=True, max_length=200),
+ ),
+ migrations.AddField(
+ model_name='sighting',
+ name='region_name',
+ field=models.CharField(blank=True, max_length=200),
+ ),
+ migrations.AddField(
+ model_name='sighting',
+ name='state_name',
+ field=models.CharField(blank=True, max_length=200),
+ ),
+ ]
diff --git a/app/sightings/migrations/0009_fieldnote.py b/app/sightings/migrations/0009_fieldnote.py
new file mode 100644
index 0000000..2365936
--- /dev/null
+++ b/app/sightings/migrations/0009_fieldnote.py
@@ -0,0 +1,26 @@
+# Generated by Django 2.1.5 on 2019-02-17 16:15
+
+from django.db import migrations, models
+import django.db.models.deletion
+
+
+class Migration(migrations.Migration):
+
+ dependencies = [
+ ('sightings', '0008_auto_20190217_1441'),
+ ]
+
+ operations = [
+ migrations.CreateModel(
+ name='FieldNote',
+ fields=[
+ ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
+ ('body_html', models.TextField(blank=True, null=True)),
+ ('body_markdown', models.TextField(blank=True, null=True)),
+ ('sighting', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='sightings.Sighting')),
+ ],
+ options={
+ 'ordering': ['sighting__pub_date'],
+ },
+ ),
+ ]
diff --git a/app/sightings/migrations/0010_auto_20190217_1647.py b/app/sightings/migrations/0010_auto_20190217_1647.py
new file mode 100644
index 0000000..7427918
--- /dev/null
+++ b/app/sightings/migrations/0010_auto_20190217_1647.py
@@ -0,0 +1,25 @@
+# Generated by Django 2.1.5 on 2019-02-17 16:47
+
+from django.db import migrations, models
+
+
+class Migration(migrations.Migration):
+
+ dependencies = [
+ ('sightings', '0009_fieldnote'),
+ ]
+
+ operations = [
+ migrations.AlterField(
+ model_name='fieldnote',
+ name='body_html',
+ field=models.TextField(blank=True, default=''),
+ preserve_default=False,
+ ),
+ migrations.AlterField(
+ model_name='fieldnote',
+ name='body_markdown',
+ field=models.TextField(blank=True, default=''),
+ preserve_default=False,
+ ),
+ ]
diff --git a/app/sightings/migrations/0011_auto_20190217_1702.py b/app/sightings/migrations/0011_auto_20190217_1702.py
new file mode 100644
index 0000000..efe7cce
--- /dev/null
+++ b/app/sightings/migrations/0011_auto_20190217_1702.py
@@ -0,0 +1,29 @@
+# Generated by Django 2.1.5 on 2019-02-17 17:02
+
+import datetime
+from django.db import migrations, models
+
+
+class Migration(migrations.Migration):
+
+ dependencies = [
+ ('sightings', '0010_auto_20190217_1647'),
+ ]
+
+ operations = [
+ migrations.AlterModelOptions(
+ name='fieldnote',
+ options={'ordering': ['sighting_pub_date']},
+ ),
+ migrations.AddField(
+ model_name='fieldnote',
+ name='ap_common_name',
+ field=models.CharField(blank=True, max_length=200),
+ ),
+ migrations.AddField(
+ model_name='fieldnote',
+ name='sighting_pub_date',
+ field=models.DateTimeField(blank=True, default=datetime.datetime(2019, 2, 17, 17, 2, 51, 82998), verbose_name='Date'),
+ preserve_default=False,
+ ),
+ ]
diff --git a/app/sightings/migrations/0012_sighting_ap_common_name.py b/app/sightings/migrations/0012_sighting_ap_common_name.py
new file mode 100644
index 0000000..a931b30
--- /dev/null
+++ b/app/sightings/migrations/0012_sighting_ap_common_name.py
@@ -0,0 +1,18 @@
+# Generated by Django 2.1.5 on 2019-02-17 17:12
+
+from django.db import migrations, models
+
+
+class Migration(migrations.Migration):
+
+ dependencies = [
+ ('sightings', '0011_auto_20190217_1702'),
+ ]
+
+ operations = [
+ migrations.AddField(
+ model_name='sighting',
+ name='ap_common_name',
+ field=models.CharField(blank=True, max_length=200),
+ ),
+ ]
diff --git a/app/sightings/migrations/0013_fieldnote_sighting_location.py b/app/sightings/migrations/0013_fieldnote_sighting_location.py
new file mode 100644
index 0000000..ef8990d
--- /dev/null
+++ b/app/sightings/migrations/0013_fieldnote_sighting_location.py
@@ -0,0 +1,18 @@
+# Generated by Django 2.1.5 on 2019-02-17 18:31
+
+from django.db import migrations, models
+
+
+class Migration(migrations.Migration):
+
+ dependencies = [
+ ('sightings', '0012_sighting_ap_common_name'),
+ ]
+
+ operations = [
+ migrations.AddField(
+ model_name='fieldnote',
+ name='sighting_location',
+ field=models.CharField(blank=True, max_length=200),
+ ),
+ ]
diff --git a/app/sightings/models.py b/app/sightings/models.py
index fe09f39..5723776 100644
--- a/app/sightings/models.py
+++ b/app/sightings/models.py
@@ -130,6 +130,12 @@ class Sighting(models.Model):
point = models.PointField(blank=True)
location = models.ForeignKey(Location, on_delete=models.CASCADE, blank=True)
pub_date = models.DateTimeField('Date', default=timezone.now)
+ location_name = models.CharField(max_length=200, blank=True)
+ state_name = models.CharField(max_length=200, blank=True)
+ country_name = models.CharField(max_length=200, blank=True)
+ country_slug = models.CharField(max_length=200, blank=True)
+ region_name = models.CharField(max_length=200, blank=True)
+ ap_common_name = models.CharField(max_length=200, blank=True)
# seen_by = models.ManyToManyField(User)
# images = models.ManyToManyField(LuxImage, blank=True)
# audio = models.ManyToManyField(BirdAudio, blank=True)
@@ -183,7 +189,7 @@ class Sighting(models.Model):
return reverse("sightings:detail", kwargs={"slug": self.ap.slug})
def __str__(self):
- return self.ap.common_name
+ return self.ap_common_name
def save(self, *args, **kwargs):
if not self.point:
@@ -194,44 +200,34 @@ class Sighting(models.Model):
).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.ap_common_name = self.ap.common_name
+ self.location_name = self.location.name
+ self.state_name = self.location.state.name
+ self.country_name = self.location.state.country.name
+ self.country_slug = self.location.state.country.slug
+ self.region_name = self.location.state.country.lux_region.name
super(Sighting, self).save()
-"""
-Migration from Birds to abstract:
-apclass = OLDAPClass.objects.all()
-for b in apclass:
- NewAPClass.objects.create(
- common_name = b.common_name,
- scientific_name = b.scientific_name,
- kind = 1
- )
-
-ap = OLDAP.objects.all()
-for b in ap:
- apnew = NewAPClass.objects.get(scientific_name=b.apclass.scientific_name)
- print(ap)
- NewAP.objects.create(
- common_name = b.common_name,
- scientific_name = b.scientific_name,
- code = b.code,
- apclass = apnew,
- image = b.image,
- image_credit = b.image_credit,
- )
- print(t)
-
-oldsighting = OLDSighting.objects.all()
-for bird in oldsighting:
- ap = NEWAP.objects.get(scientific_name=bird.ap.scientific_name)
- s = NEWSighting.objects.create(
- ap = ap,
- point = bird.point,
- location = bird.location,
- date = bird.date,
- )
- for t in bird.images.all():
- s.images.add(t)
- for t in bird.seen_by.all():
- s.seen_by.add(t)
-"""
+class FieldNote(models.Model):
+ sighting = models.ForeignKey(Sighting, on_delete=models.CASCADE)
+ body_html = models.TextField(blank=True)
+ body_markdown = models.TextField(blank=True)
+ # these are only used to speed up admin
+ sighting_pub_date = models.DateTimeField('Date', blank=True)
+ sighting_location = models.CharField(max_length=200, blank=True)
+ ap_common_name = models.CharField(max_length=200, blank=True)
+
+ class Meta:
+ ordering = ["sighting_pub_date", ]
+
+ def __str__(self):
+ return '%s %s' % (self.ap_common_name, self.pk)
+
+ def save(self, *args, **kwargs):
+ self.sighting_pub_date = self.sighting.pub_date
+ self.ap_common_name = self.sighting.ap.common_name
+ self.sighting_location = self.sighting.location_name
+ md = render_images(self.body_markdown)
+ self.body_html = markdown_to_html(md)
+ super(FieldNote, self).save()
diff --git a/app/sightings/views.py b/app/sightings/views.py
index c90e5c1..3170b77 100644
--- a/app/sightings/views.py
+++ b/app/sightings/views.py
@@ -2,15 +2,14 @@ from django.views.generic.detail import DetailView
from django.views.generic import ListView
from django.contrib.auth.models import User
from utils.views import PaginatedListView
-from .models import AP, Sighting
+from .models import AP, Sighting, FieldNote
class SightingListView(PaginatedListView):
- template_name = 'archives/sightings.html'
def get_queryset(self):
qs_ids = Sighting.objects.order_by('ap__id', '-pub_date').distinct('ap').values_list('id', flat=True)
- return Sighting.objects.filter(id__in=qs_ids).order_by('-pub_date')
+ return Sighting.objects.filter(id__in=qs_ids).order_by('-pub_date').prefetch_related('ap')
class LifeListView(ListView):
@@ -37,22 +36,20 @@ class SightingListUserView(PaginatedListView):
class SightingDetailView(DetailView):
model = AP
- template_name = "details/sighting.html"
- slug_field = "slug"
def get_context_data(self, **kwargs):
# Call the base implementation first to get a context
context = super(SightingDetailView, self).get_context_data(**kwargs)
+ context['field_notes'] = FieldNote.objects.filter(
+ sighting__ap__slug=self.kwargs['slug']
+ )
+ context['sighting'] = Sighting.objects.filter(
+ ap__slug=self.kwargs['slug']
+ ).prefetch_related('location')
#try:
# context['recording'] = SightingAudio.objects.get(
# ap__slug=self.kwargs['slug']
# )
#except SightingAudio.DoesNotExist:
# pass
- try:
- context['sighting'] = Sighting.objects.filter(
- ap__slug=self.kwargs['slug']
- )
- except Sighting.DoesNotExist:
- pass
return context