summaryrefslogtreecommitdiff
path: root/app/guides/models.py
diff options
context:
space:
mode:
Diffstat (limited to 'app/guides/models.py')
-rw-r--r--app/guides/models.py80
1 files changed, 64 insertions, 16 deletions
diff --git a/app/guides/models.py b/app/guides/models.py
index 1583bee..8704887 100644
--- a/app/guides/models.py
+++ b/app/guides/models.py
@@ -20,11 +20,13 @@ class Guide(models.Model):
title = models.CharField(max_length=200)
sub_title = models.CharField(max_length=200, blank=True)
dek = models.TextField(blank=True)
- preamble_markdown = models.TextField(blank=True)
- preamble_html = models.TextField(blank=True)
- slug = models.SlugField(unique_for_date='pub_date')
- body_html = models.TextField(blank=True)
+ prologue_markdown = models.TextField(blank=True)
+ prologue_html = models.TextField(blank=True)
body_markdown = models.TextField()
+ body_html = models.TextField(blank=True)
+ epilogue_markdown = models.TextField(blank=True)
+ epilogue_html = models.TextField(blank=True)
+ slug = models.SlugField(unique_for_date='pub_date')
pub_date = models.DateTimeField('Date published')
last_updated = models.DateTimeField(auto_now=True)
enable_comments = models.BooleanField(default=False)
@@ -33,19 +35,21 @@ class Guide(models.Model):
(1, 'Published'),
)
status = models.IntegerField(choices=PUB_STATUS, default=0)
+ POST_TYPE = (
+ (0, 'guide'),
+ (1, 'review'),
+ )
+ post_type = models.IntegerField(choices=POST_TYPE, default=0)
meta_description = models.CharField(max_length=256, null=True, blank=True)
tags = TaggableManager(through=TaggedItems, blank=True, help_text='Topics Covered')
- category = models.ForeignKey(Category, on_delete=models.CASCADE)
featured_image = models.ForeignKey(LuxImage, on_delete=models.CASCADE, null=True, blank=True)
+ point = models.PointField(null=True, blank=True)
+ location = models.ForeignKey(Location, on_delete=models.CASCADE, null=True, blank=True)
has_video = models.BooleanField(blank=True, default=False)
+ disclaimer = models.BooleanField(blank=True, default=False)
field_notes = models.ManyToManyField(FieldNote, blank=True)
books = models.ManyToManyField(Book, blank=True)
- essays = models.ManyToManyField(Essay, blank=True)
jrnl = models.ManyToManyField(Entry, blank=True)
- point = models.PointField(null=True, blank=True)
- location = models.ForeignKey(Location, on_delete=models.CASCADE, null=True, blank=True)
- afterword = models.TextField(blank=True)
- afterword_html = models.TextField(blank=True)
class Meta:
ordering = ('-pub_date',)
@@ -56,7 +60,10 @@ class Guide(models.Model):
return self.title
def get_absolute_url(self):
- return reverse('guides:detail', kwargs={"category": self.category, "slug": self.slug})
+ if self.post_type == 0:
+ return reverse('guide:guide-detail', kwargs={"slug": self.slug})
+ if self.post_type == 1:
+ return reverse('review:review-detail', kwargs={"slug": self.slug})
def comment_period_open(self):
return self.enable_comments and datetime.datetime.today() - datetime.timedelta(30) <= self.pub_date
@@ -66,14 +73,55 @@ class Guide(models.Model):
return self.get_previous_by_pub_date(status__exact=1)
@property
+ def get_previous_admin_url(self):
+ n = self.get_previous_by_pub_date()
+ return reverse('admin:%s_%s_change' %(self._meta.app_label, self._meta.model_name), args=[n.id] )
+
+ @property
def get_next_published(self):
return self.get_next_by_pub_date(status__exact=1)
- def save(self):
- md = render_images(self.body_markdown)
- self.body_html = markdown_to_html(md)
- self.afterword_html = markdown_to_html(self.afterword)
- super(Guide, self).save()
+ @property
+ def get_next_admin_url(self):
+ model = apps.get_model(app_label=self._meta.app_label, model_name=self._meta.model_name)
+ try:
+ return reverse('admin:%s_%s_change' %(self._meta.app_label, self._meta.model_name), args=[self.get_next_by_pub_date().pk] )
+ except model.DoesNotExist:
+ return ''
+
+ @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, *args, **kwargs):
+ created = self.pk is None
+ if not created:
+ md = render_images(self.body_markdown)
+ self.body_html = markdown_to_html(md)
+ self.prologue_html = markdown_to_html(self.prologue_markdown)
+ self.epilogue_html = markdown_to_html(self.epilogue_markdown)
+ self.has_video = parse_video(self.body_html)
+ if self.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 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
+ if old and old.featured_image != self.featured_image: # Field has changed
+ s = LuxImageSize.objects.get(name="featured_jrnl")
+ ss = LuxImageSize.objects.get(name="picwide-med")
+ self.featured_image.sizes.add(s)
+ self.featured_image.sizes.add(ss)
+ self.featured_image.save()
+ super(Guide, self).save(*args, **kwargs)
class GuideSitemap(Sitemap):