comparison gpp/news/models.py @ 486:7854d75427af

For #233, add a meta description field for news stories. This field will get put in the open graph meta tag for better descriptions when shared on social media sites.
author Brian Neal <bgneal@gmail.com>
date Tue, 18 Oct 2011 23:23:42 +0000
parents bbbc357ac5f3
children
comparison
equal deleted inserted replaced
485:7c69b1449d7a 486:7854d75427af
36 allow_comments = models.BooleanField(default=True) 36 allow_comments = models.BooleanField(default=True)
37 tags = TagField() 37 tags = TagField()
38 front_page_expiration = models.DateField(null=True, blank=True) 38 front_page_expiration = models.DateField(null=True, blank=True)
39 update_date = models.DateTimeField(db_index=True, blank=True) 39 update_date = models.DateTimeField(db_index=True, blank=True)
40 priority = models.IntegerField(db_index=True, default=0, blank=True) 40 priority = models.IntegerField(db_index=True, default=0, blank=True)
41 meta_description = models.TextField(blank=True)
41 42
42 class Meta: 43 class Meta:
43 abstract = True 44 abstract = True
44 45
45 46
102 def ogp_tags(self): 103 def ogp_tags(self):
103 """ 104 """
104 Returns a dict of Open Graph Protocol meta tags. 105 Returns a dict of Open Graph Protocol meta tags.
105 106
106 """ 107 """
108 desc = self.meta_description.strip()
109 if not desc:
110 desc = 'News article submitted by %s on %s.' % (
111 self.submitter.username,
112 self.date_submitted.strftime('%B %d, %Y'))
113
107 return { 114 return {
108 'og:title': self.title, 115 'og:title': self.title,
109 'og:type': 'article', 116 'og:type': 'article',
110 'og:url': self.get_absolute_url(), 117 'og:url': self.get_absolute_url(),
111 'og:image': self.category.icon.url, 118 'og:image': self.category.icon.url,
112 'og:description': self.title, 119 'og:description': desc,
113 } 120 }