mirror of
https://github.com/viq/NewsBlur.git
synced 2025-09-18 21:43:31 +00:00
Merge branch 'facebook_share'
* facebook_share: Fixing Facebook share to use fancy actions. New share by facebook.
This commit is contained in:
commit
9f71c23573
5 changed files with 100 additions and 13 deletions
28
apps/social/migrations/0006_guid_hash.py
Normal file
28
apps/social/migrations/0006_guid_hash.py
Normal file
|
@ -0,0 +1,28 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
import datetime
|
||||
from south.db import db
|
||||
from south.v2 import DataMigration
|
||||
from django.db import models
|
||||
from apps.social.models import MSharedStory
|
||||
|
||||
class Migration(DataMigration):
|
||||
|
||||
def forwards(self, orm):
|
||||
shared_stories = MSharedStory.objects.filter(story_guid_hash__exists=False)
|
||||
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
|
||||
|
||||
def backwards(self, orm):
|
||||
"Write your backwards methods here."
|
||||
|
||||
models = {
|
||||
|
||||
}
|
||||
|
||||
complete_apps = ['social']
|
||||
symmetrical = True
|
|
@ -1144,6 +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_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())
|
||||
|
@ -1173,7 +1174,13 @@ class MSharedStory(mongo.Document):
|
|||
|
||||
@property
|
||||
def guid_hash(self):
|
||||
return hashlib.sha1(self.story_guid).hexdigest()
|
||||
if self.story_guid_hash:
|
||||
return self.story_guid_hash
|
||||
|
||||
self.story_guid_hash = hashlib.sha1(self.story_guid).hexdigest()
|
||||
self.save()
|
||||
|
||||
return self.story_guid_hash
|
||||
|
||||
def to_json(self):
|
||||
return {
|
||||
|
@ -1194,7 +1201,8 @@ class MSharedStory(mongo.Document):
|
|||
if self.story_original_content:
|
||||
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_title = strip_tags(self.story_title)
|
||||
|
||||
self.comments = linkify(strip_tags(self.comments))
|
||||
|
@ -1626,13 +1634,14 @@ class MSharedStory(mongo.Document):
|
|||
self.guid_hash[:6]
|
||||
)
|
||||
|
||||
def generate_post_to_service_message(self):
|
||||
def generate_post_to_service_message(self, include_url=True):
|
||||
message = self.comments
|
||||
if not message or len(message) < 1:
|
||||
message = self.story_title
|
||||
|
||||
message = truncate_chars(message, 116)
|
||||
message += " " + self.blurblog_permalink()
|
||||
if include_url:
|
||||
message = truncate_chars(message, 116)
|
||||
message += " " + self.blurblog_permalink()
|
||||
|
||||
return message
|
||||
|
||||
|
@ -1641,16 +1650,16 @@ class MSharedStory(mongo.Document):
|
|||
return
|
||||
|
||||
posted = False
|
||||
message = self.generate_post_to_service_message()
|
||||
social_service = MSocialServices.objects.get(user_id=self.user_id)
|
||||
user = User.objects.get(pk=self.user_id)
|
||||
|
||||
message = self.generate_post_to_service_message()
|
||||
logging.user(user, "~BM~FGPosting to %s: ~SB%s" % (service, message))
|
||||
|
||||
if service == 'twitter':
|
||||
posted = social_service.post_to_twitter(message)
|
||||
posted = social_service.post_to_twitter(self)
|
||||
elif service == 'facebook':
|
||||
posted = social_service.post_to_facebook(message)
|
||||
posted = social_service.post_to_facebook(self)
|
||||
|
||||
if posted:
|
||||
self.posted_to_services.append(service)
|
||||
|
@ -2113,7 +2122,9 @@ class MSocialServices(mongo.Document):
|
|||
profile.save()
|
||||
return profile
|
||||
|
||||
def post_to_twitter(self, message):
|
||||
def post_to_twitter(self, shared_story):
|
||||
message = shared_story.generate_post_to_service_message()
|
||||
|
||||
try:
|
||||
api = self.twitter_api()
|
||||
api.update_status(status=message)
|
||||
|
@ -2123,10 +2134,22 @@ class MSocialServices(mongo.Document):
|
|||
|
||||
return True
|
||||
|
||||
def post_to_facebook(self, message):
|
||||
def post_to_facebook(self, shared_story):
|
||||
message = shared_story.generate_post_to_service_message(include_url=False)
|
||||
shared_story.calculate_image_sizes()
|
||||
content = zlib.decompress(shared_story.story_content_z)[:1024]
|
||||
|
||||
try:
|
||||
api = self.facebook_api()
|
||||
api.put_wall_post(message=message)
|
||||
# api.put_wall_post(message=message)
|
||||
api.put_object('me', '%s:share' % settings.FACEBOOK_NAMESPACE,
|
||||
link=shared_story.blurblog_permalink(),
|
||||
type="link",
|
||||
name=shared_story.story_title,
|
||||
description=content,
|
||||
article=shared_story.story_permalink,
|
||||
message=message,
|
||||
)
|
||||
except facebook.GraphAPIError, e:
|
||||
print e
|
||||
return
|
||||
|
|
|
@ -399,7 +399,25 @@ def load_social_page(request, user_id, username=None, **kwargs):
|
|||
story['user_comments'] = shared_story.comments
|
||||
|
||||
stories = MSharedStory.attach_users_to_stories(stories, profiles)
|
||||
|
||||
|
||||
active_story = None
|
||||
path = request.META['PATH_INFO']
|
||||
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:
|
||||
active_story_db = active_story_db[0]
|
||||
active_story = Feed.format_story(active_story_db)
|
||||
if active_story_db.image_count:
|
||||
active_story['image_url'] = active_story_db.image_sizes[0]['url']
|
||||
active_story['tags'] = ', '.join(active_story_db.story_tags)
|
||||
if active_story['story_feed_id']:
|
||||
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,
|
||||
'stories' : stories,
|
||||
|
@ -412,7 +430,9 @@ def load_social_page(request, user_id, username=None, **kwargs):
|
|||
'feeds' : feeds,
|
||||
'user_profile' : hasattr(user, 'profile') and user.profile,
|
||||
'has_next_page' : has_next_page,
|
||||
'holzer_truism' : random.choice(jennyholzer.TRUISMS) #if not has_next_page else None
|
||||
'holzer_truism' : random.choice(jennyholzer.TRUISMS), #if not has_next_page else None
|
||||
'facebook_app_id': settings.FACEBOOK_APP_ID,
|
||||
'active_story' : active_story,
|
||||
}
|
||||
|
||||
diff1 = checkpoint1-start
|
||||
|
|
|
@ -415,6 +415,7 @@ REDIS = {
|
|||
|
||||
FACEBOOK_APP_ID = '111111111111111'
|
||||
FACEBOOK_SECRET = '99999999999999999999999999999999'
|
||||
FACEBOOK_NAMESPACE = 'newsblur'
|
||||
TWITTER_CONSUMER_KEY = 'ooooooooooooooooooooo'
|
||||
TWITTER_CONSUMER_SECRET = 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'
|
||||
|
||||
|
|
|
@ -10,6 +10,21 @@
|
|||
<link rel="icon" href="{{ social_profile.photo_url }}">
|
||||
<meta name="viewport" content="initial-scale=1, maximum-scale=1.5">
|
||||
|
||||
{% if active_story %}
|
||||
<meta property="fb:app_id" content="{{ facebook_app_id }}">
|
||||
<meta property="og:type" content="article">
|
||||
<meta property="og:url" content="{{ active_story.story_permalink }}">
|
||||
{% if active_story.feed %}
|
||||
<meta property="og:site_name" content="{{ active_story.feed.feed_title }}">
|
||||
{% 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 }}">
|
||||
<meta property="article:published_time" content="{{ active_story.story_date }}">
|
||||
<meta property="article:author" content="{{ active_story.story_authors }}">
|
||||
<meta property="article:tag" content="{{ active_story.tags }}">
|
||||
{% endif %}
|
||||
|
||||
{% include_stylesheets "blurblog" %}
|
||||
|
||||
{% if social_profile.custom_css %}
|
||||
|
|
Loading…
Add table
Reference in a new issue