changeset 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 7c69b1449d7a
children 77d878acea5e
files gpp/news/admin.py gpp/news/models.py gpp/news/static/js/news_admin.js static/js/tiny_mce_init_std.js
diffstat 4 files changed, 17 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- 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)
--- 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,
         }
--- /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');      
+});
--- 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",