# HG changeset patch # User Brian Neal # Date 1318980222 0 # Node ID 7854d75427af4c49675bd5aa27b0efe000e6cf2d # Parent 7c69b1449d7aef290d41fcef3bf81e89e2dcacd7 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. diff -r 7c69b1449d7a -r 7854d75427af gpp/news/admin.py --- a/gpp/news/admin.py Tue Oct 18 00:14:34 2011 +0000 +++ b/gpp/news/admin.py Tue Oct 18 23:23:42 2011 +0000 @@ -37,7 +37,8 @@ allow_comments=pending_story.allow_comments, tags=pending_story.tags, front_page_expiration=pending_story.front_page_expiration, - priority=pending_story.priority) + priority=pending_story.priority, + meta_description=pending_story.meta_description) story.save() pending_story.delete() @@ -48,7 +49,7 @@ approve_story.short_description = "Approve selected pending stories" class Media: - js = settings.GPP_THIRD_PARTY_JS['tiny_mce'] + js = ['js/news_admin.js'] + settings.GPP_THIRD_PARTY_JS['tiny_mce'] class StoryAdmin(admin.ModelAdmin): @@ -60,7 +61,7 @@ raw_id_fields = ('submitter', ) class Media: - js = settings.GPP_THIRD_PARTY_JS['tiny_mce'] + js = ['js/news_admin.js'] + settings.GPP_THIRD_PARTY_JS['tiny_mce'] admin.site.register(Category, CategoryAdmin) diff -r 7c69b1449d7a -r 7854d75427af gpp/news/models.py --- a/gpp/news/models.py Tue Oct 18 00:14:34 2011 +0000 +++ b/gpp/news/models.py Tue Oct 18 23:23:42 2011 +0000 @@ -38,6 +38,7 @@ front_page_expiration = models.DateField(null=True, blank=True) update_date = models.DateTimeField(db_index=True, blank=True) priority = models.IntegerField(db_index=True, default=0, blank=True) + meta_description = models.TextField(blank=True) class Meta: abstract = True @@ -104,10 +105,16 @@ Returns a dict of Open Graph Protocol meta tags. """ + desc = self.meta_description.strip() + if not desc: + desc = 'News article submitted by %s on %s.' % ( + self.submitter.username, + self.date_submitted.strftime('%B %d, %Y')) + return { 'og:title': self.title, 'og:type': 'article', 'og:url': self.get_absolute_url(), 'og:image': self.category.icon.url, - 'og:description': self.title, + 'og:description': desc, } diff -r 7c69b1449d7a -r 7854d75427af gpp/news/static/js/news_admin.js --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/gpp/news/static/js/news_admin.js Tue Oct 18 23:23:42 2011 +0000 @@ -0,0 +1,3 @@ +django.jQuery(document).ready(function() { + django.jQuery('#id_meta_description').addClass('mceNoEditor'); +}); diff -r 7c69b1449d7a -r 7854d75427af static/js/tiny_mce_init_std.js --- a/static/js/tiny_mce_init_std.js Tue Oct 18 00:14:34 2011 +0000 +++ b/static/js/tiny_mce_init_std.js Tue Oct 18 23:23:42 2011 +0000 @@ -1,5 +1,6 @@ tinyMCE.init({ - mode : "textareas", + mode : "specific_textareas", + editor_deselector: "mceNoEditor", theme : "advanced", convert_urls: false, theme_advanced_toolbar_location : "top",