summaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
Diffstat (limited to 'app')
-rw-r--r--app/birds/admin.py8
-rw-r--r--app/birds/models.py62
-rw-r--r--app/birds/urls.py8
-rw-r--r--app/birds/views.py27
4 files changed, 102 insertions, 3 deletions
diff --git a/app/birds/admin.py b/app/birds/admin.py
index 01a6f4c..8c09b7b 100644
--- a/app/birds/admin.py
+++ b/app/birds/admin.py
@@ -1,14 +1,17 @@
from django.contrib import admin
from django.contrib.gis.admin import OSMGeoAdmin
-from birds.models import BirdSighting, BirdClass, Bird
+from birds.models import BirdSighting, BirdAudio, BirdClass, Bird
class BirdClassAdmin(admin.ModelAdmin):
list_display = ('common_name', 'scientific_name',)
+class BirdAudioAdmin(admin.ModelAdmin):
+ list_display = ('bird', 'recorder',)
class BirdAdmin(admin.ModelAdmin):
list_display = ('pk', 'common_name', 'scientific_name', 'code', 'bird_class')
+ list_filter = ('bird_class',)
class BirdSightingAdmin(OSMGeoAdmin):
@@ -17,7 +20,7 @@ class BirdSightingAdmin(OSMGeoAdmin):
# options for OSM map Using custom ESRI topo map
default_lon = -9285175
default_lat = 4025046
- default_zoom = 6
+ default_zoom = 10
units = True
scrollable = False
map_width = 700
@@ -27,4 +30,5 @@ class BirdSightingAdmin(OSMGeoAdmin):
admin.site.register(BirdSighting, BirdSightingAdmin)
admin.site.register(BirdClass, BirdClassAdmin)
+admin.site.register(BirdAudio, BirdAudioAdmin)
admin.site.register(Bird, BirdAdmin)
diff --git a/app/birds/models.py b/app/birds/models.py
index 3fb0c0f..2ba9451 100644
--- a/app/birds/models.py
+++ b/app/birds/models.py
@@ -1,11 +1,15 @@
import datetime
+from django.template.defaultfilters import slugify
from django.contrib.gis.db import models
+from django.contrib.auth.models import User
+from django.utils import timezone
from locations.models import Location
def get_upload_path(self, filename):
return "images/bird-images/%s/%s" % (datetime.datetime.today().strftime("%Y"), filename)
+
# from http://aba.org/checklist/codes.html
ABA_CODES = (
(1, 'regular occurring - common'),
@@ -23,6 +27,7 @@ class BirdClass(models.Model):
class Meta:
verbose_name_plural = 'Bird Class'
+ ordering = ["common_name",]
def __str__(self):
return self.common_name
@@ -30,17 +35,72 @@ class BirdClass(models.Model):
class Bird(models.Model):
common_name = models.CharField(max_length=200)
+ slug = models.SlugField()
scientific_name = models.CharField(max_length=200)
code = models.IntegerField(choices=ABA_CODES, default=0)
bird_class = models.ForeignKey(BirdClass)
+ image = models.FileField(upload_to=get_upload_path, null=True, blank=True)
def __str__(self):
return self.common_name
+ def get_absolute_url(self):
+ return "/birds/%s" %(self.slug)
+
+ class Meta:
+ ordering = ["common_name",]
+
+ def save(self):
+ self.slug = slugify(self.common_name[:50])
+ super(Bird, self).save()
+
+class BirdAudio(models.Model):
+ bird = models.ForeignKey(Bird, related_name='recordings')
+ audio = models.FileField(upload_to='audio/birds/')
+ recorder = models.CharField(max_length=200, null=True, blank=True)
+ pub_date = models.DateTimeField()
+ location = models.CharField(max_length=200, null=True, blank=True)
+ link = models.CharField(max_length=450, null=True, blank=True)
+ copyright = models.CharField(max_length=250, null=True, blank=True)
+
+ class Meta:
+ verbose_name_plural = 'Bird Audio'
+ ordering = ["bird",]
+
+ def __str__(self):
+ return self.bird.common_name
class BirdSighting(models.Model):
bird = models.ForeignKey(Bird)
point = models.PointField()
location = models.ForeignKey(Location)
- date = models.DateTimeField('Date')
+ date = models.DateTimeField('Date', default=timezone.now)
image = models.FileField(upload_to=get_upload_path, null=True, blank=True)
+ seen_by = models.ManyToManyField(User)
+
+ class Meta:
+ verbose_name_plural = 'Bird Sighting'
+
+ @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
+
+ @property
+ def longitude(self):
+ '''Get the site's longitude.'''
+ return self.point.x
+
+ @property
+ def latitude(self):
+ '''Get the site's latitude.'''
+ return self.point.y
+ def __str__(self):
+ return self.bird.common_name
diff --git a/app/birds/urls.py b/app/birds/urls.py
new file mode 100644
index 0000000..6a219f1
--- /dev/null
+++ b/app/birds/urls.py
@@ -0,0 +1,8 @@
+from django.conf.urls import *
+from django.views.generic.base import RedirectView
+from django.views.generic.detail import DetailView
+
+urlpatterns = patterns('',
+ url(r'^list/(?P<user>[\w]+)', 'birds.views.bird_list'),
+ url(r'^(?P<slug>[-_\w]+)$', 'birds.views.bird_detail'),
+)
diff --git a/app/birds/views.py b/app/birds/views.py
new file mode 100644
index 0000000..bd2f79e
--- /dev/null
+++ b/app/birds/views.py
@@ -0,0 +1,27 @@
+from django.shortcuts import render_to_response, get_object_or_404
+from django.template import RequestContext
+from django.http import Http404
+from django.conf import settings
+# from django.views.generic import ListView
+
+from birds.models import Bird, BirdAudio, BirdSighting
+from locations.models import Region, Country
+
+
+def bird_list(request, user):
+ #request.page_url = '/birds/seen/%d/'
+ #request.page = int(page)
+ context = {
+ 'object_list': BirdSighting.objects.filter(seen_by__username=user),
+ 'user': user,
+ }
+ return render_to_response("archives/birds.html", context, context_instance=RequestContext(request))
+
+
+def bird_detail(request, slug):
+ context = {
+ 'object': Bird.objects.get(slug=slug),
+ 'recording': BirdAudio.objects.get(bird__slug=slug)
+ }
+ return render_to_response("details/bird.html", context, context_instance=RequestContext(request))
+