diff options
Diffstat (limited to 'app')
-rw-r--r-- | app/notes/__init__.py | 0 | ||||
-rw-r--r-- | app/notes/admin.py | 48 | ||||
-rw-r--r-- | app/notes/models.py | 60 |
3 files changed, 108 insertions, 0 deletions
diff --git a/app/notes/__init__.py b/app/notes/__init__.py new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/app/notes/__init__.py diff --git a/app/notes/admin.py b/app/notes/admin.py new file mode 100644 index 0000000..8797a92 --- /dev/null +++ b/app/notes/admin.py @@ -0,0 +1,48 @@ +from django.contrib import admin +from django.contrib.gis.admin import OSMGeoAdmin +from notes.models import Note +from django import forms + + +class NoteModelForm(forms.ModelForm): + body_markdown = forms.CharField(widget=forms.Textarea(attrs={'maxlength': 400, 'rows': 5, 'cols': 65}), label='Note') + + class Meta: + model = Note + + +class NoteAdmin(OSMGeoAdmin): + form = NoteModelForm + list_display = ('slug', 'date_created', 'location') + list_filter = ('location',) + fieldsets = ( + ('Note', { + 'fields': ( + 'body_markdown', + 'slug', + 'point' + ), + 'classes': ( + 'show', + 'extrapretty', + 'wide' + ) + }), + ) + # options for OSM map Using custom ESRI topo map + default_lon = -9285175 + default_lat = 4025046 + default_zoom = 11 + units = True + scrollable = False + map_width = 700 + map_height = 425 + map_template = 'gis/admin/osm.html' + openlayers_url = '/static/admin/js/OpenLayers.js' + + class Media: + js = ( + '/static/jquery.simplyCountable.js', + '/static/count.js', + ) +admin.site.register(Note, NoteAdmin) diff --git a/app/notes/models.py b/app/notes/models.py new file mode 100644 index 0000000..bad7172 --- /dev/null +++ b/app/notes/models.py @@ -0,0 +1,60 @@ +import datetime +from django.contrib.gis.db import models +from django.template.defaultfilters import slugify +from django import forms +from django.conf import settings +from locations.models import Location + +# http://freewisdom.org/projects/python-markdown/ +import markdown + + +class Note(models.Model): + slug = models.SlugField(unique_for_date='date_created', blank=True) + date_created = models.DateTimeField('Date', blank=True) + date_last_updated = models.DateTimeField('Date', blank=True) + point = models.PointField() + location = models.ForeignKey(Location, null=True, blank=True) + body_html = models.TextField(blank=True) + body_markdown = models.CharField('Note', max_length=450) + + def __str__(self): + return self.slug + + def get_absolute_url(self): + return '/notes/%s/%s' % (self.date_created.strftime("%Y/%b").lower(), self.slug) + + @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 save(self): + self.body_html = markdown.markdown(self.body_markdown, extensions=['extra'], safe_mode=False) + self.date_last_updated = datetime.datetime.now() + if not self.date_created: + self.date_created = datetime.datetime.now() + if not self.slug: + self.slug = slugify(self.body_markdown)[:20] + 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)) + super(Note, self).save() |