Cleaning up Facebook og description.

This commit is contained in:
Samuel Clay 2012-11-26 17:26:01 -08:00
parent 258a52a87a
commit 8607fa69f9
5 changed files with 11 additions and 10 deletions

View file

@ -1,5 +1,6 @@
# -*- coding: utf-8 -*-
import datetime
import hashlib
from south.db import db
from south.v2 import DataMigration
from django.db import models
@ -8,14 +9,15 @@ from apps.social.models import MSharedStory
class Migration(DataMigration):
def forwards(self, orm):
shared_stories = MSharedStory.objects.filter(story_guid_hash__exists=False)
shared_stories = MSharedStory.objects.all()
count = shared_stories.count()
print "%s shared stories..." % count
for s, story in enumerate(shared_stories):
if s % 100 == 0:
print "%s/%s" % (s+1, count)
story.story_guid
story.story_guid_hash = hashlib.sha1(story.story_guid).hexdigest()[:6]
story.save()
def backwards(self, orm):
"Write your backwards methods here."

View file

@ -1144,7 +1144,7 @@ class MSharedStory(mongo.Document):
story_author_name = mongo.StringField()
story_permalink = mongo.StringField()
story_guid = mongo.StringField(unique_with=('user_id',))
story_guid_hash = mongo.StringField()
story_guid_hash = mongo.StringField(max_length=6)
story_tags = mongo.ListField(mongo.StringField(max_length=250))
posted_to_services = mongo.ListField(mongo.StringField(max_length=20))
mute_email_users = mongo.ListField(mongo.IntField())
@ -1177,7 +1177,7 @@ class MSharedStory(mongo.Document):
if self.story_guid_hash:
return self.story_guid_hash
self.story_guid_hash = hashlib.sha1(self.story_guid).hexdigest()
self.story_guid_hash = hashlib.sha1(self.story_guid).hexdigest()[:6]
self.save()
return self.story_guid_hash
@ -1202,7 +1202,7 @@ class MSharedStory(mongo.Document):
self.story_original_content_z = zlib.compress(self.story_original_content)
self.story_original_content = None
self.story_guid_hash = hashlib.sha1(self.story_guid).hexdigest()
self.story_guid_hash = hashlib.sha1(self.story_guid).hexdigest()[:6]
self.story_title = strip_tags(self.story_title)
self.comments = linkify(strip_tags(self.comments))

View file

@ -405,8 +405,8 @@ def load_social_page(request, user_id, username=None, **kwargs):
if '/story/' in path and format != 'html':
story_id = path.replace('/story/', '')
active_story_db = MSharedStory.objects.filter(user_id=social_user.pk,
story_guid_hash__startswith=story_id).limit(1)
if active_story_db:
story_guid_hash=story_id).limit(1)
if active_story_db:
active_story_db = active_story_db[0]
active_story = Feed.format_story(active_story_db)
if active_story_db.image_count:
@ -418,7 +418,6 @@ def load_social_page(request, user_id, username=None, **kwargs):
feed = Feed.get_by_id(active_story['story_feed_id'])
if feed:
active_story['feed'] = feed.canonical()
print active_story
params = {
'social_user' : social_user,

View file

@ -13,7 +13,7 @@ NEWSBLUR.Router = Backbone.Router.extend({
},
story: function(guid) {
this.story_guid = guid;
this.story_guid = guid.replace(/\?(.*)$/, '');
},
site: function(feed_id) {

View file

@ -19,7 +19,7 @@
{% endif %}
<meta property="og:image" content="{{ active_story.image_url }}">
<meta property="og:title" content="{{ active_story.story_title }}">
<meta property="og:description" content="{{ active_story.story_content|addslashes|safe }}">
<meta property="og:description" content="{{ active_story.story_content|striptags|addslashes|safe }}">
<meta property="article:published_time" content="{{ active_story.iso8601 }}">
<meta property="article:author" content="{{ active_story.story_authors }}">
<meta property="article:tag" content="{{ active_story.tags }}">