summaryrefslogtreecommitdiff
path: root/app/notes/models.py
diff options
context:
space:
mode:
Diffstat (limited to 'app/notes/models.py')
-rw-r--r--app/notes/models.py58
1 files changed, 58 insertions, 0 deletions
diff --git a/app/notes/models.py b/app/notes/models.py
index 6d5e805..775c78c 100644
--- a/app/notes/models.py
+++ b/app/notes/models.py
@@ -3,6 +3,7 @@ import datetime
from django.contrib.gis.db import models
from django.template.defaultfilters import slugify
from django.utils.html import urlize
+from django.utils import timezone
from django.db.models.signals import post_save
from django.dispatch import receiver
from django.conf import settings
@@ -14,10 +15,67 @@ from twython import Twython
import markdown
#from twitter_text.autolink import Autolink
+from utils.widgets import markdown_to_html
+from daily.models import CheckIn
+
+
def twitter_truncate(txt):
return txt.split("|")[0]
+class LuxNote(models.Model):
+ title = models.CharField(max_length=250, null=True, blank=True)
+ slug = models.SlugField(unique_for_date='pub_date', blank=True)
+ pub_date = models.DateTimeField(default=timezone.now)
+ date_last_updated = models.DateTimeField('Date', blank=True)
+ body_html = models.TextField(blank=True)
+ body_markdown = models.TextField('Note')
+ point = models.PointField(blank=True, null=True)
+ location = models.ForeignKey(Location, blank=True, null=True)
+
+ def __str__(self):
+ return self.title
+
+ def get_absolute_url(self):
+ return reverse("notes:detail", kwargs={"year": self.pub_date.year, "month": self.pub_date.strftime("%m"), "slug": self.slug})
+
+ @property
+ def region(self):
+ return self.location.state.country.lux_region
+
+ @property
+ def longitude(self):
+ '''Get the site's longitude.'''
+ return round(self.point.x, 2)
+
+ @property
+ def latitude(self):
+ '''Get the site's latitude.'''
+ return round(self.point.y, 2)
+
+ @property
+ def get_previous_published(self):
+ return self.get_previous_by_pub_date()
+
+ @property
+ def get_next_published(self):
+ return self.get_next_by_pub_date()
+
+
+ def save(self, *args, **kwargs):
+ self.body_html = markdown_to_html(self.body_markdown)
+ if not self.point:
+ self.point = CheckIn.objects.latest().point
+ 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))
+ if not self.id:
+ self.pub_date= timezone.now()
+ self.date_last_updated = timezone.now()
+ super(LuxNote, self).save()
+
+
class Note(models.Model):
title = models.CharField(max_length=250, null=True, blank=True)
slug = models.SlugField(unique_for_date='date_created', blank=True)