summaryrefslogtreecommitdiff
path: root/app/sightings
diff options
context:
space:
mode:
Diffstat (limited to 'app/sightings')
-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
9 files changed, 230 insertions, 51 deletions
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