Commits

vickyi  committed 21be4c8 Draft

补全更新

  • Participants
  • Parent commits a9cf94a

Comments (0)

Files changed (7)

File .settings/org.eclipse.core.resources.prefs

 eclipse.preferences.version=1
 encoding//ChineBlog/blog/models.py=utf-8
+encoding//ChineBlog/blog/social_sync.py=utf-8
 encoding//ChineBlog/blog/urls.py=utf-8
 encoding//ChineBlog/blog/views.py=utf-8
 encoding//ChineBlog/dashboard.py=utf-8

File ChineBlog/blog/models.py

 def send_email(sender, instance, **kwargs):
     comment = instance
     
-    if settings.ENABLE_EMAIL:
+    if settings.ENABLE_EMAIL and comment.visible == True:
         t = loader.get_template("blog/coolblue/email.html")
         type = 0 if comment.content_type.model == 'article' else 1
         

File ChineBlog/blog/social_sync.py

 Created on 2012-2-15
 
 @author: Chine
+
+@change: by dolphinzhang1987@gmail.com 2012-09-07
+
 '''
 
 from django.conf import settings
 
 MAX_WORDS = 140
 
-def get_sync_content(article, social_type):
+def get_sync_content(article, client, social_type):
+    # Title
     title = article.title
     title_count = sina_client.count_words(title)
     short_url = sina_client.get_short_url('%s%s' % (settings.SITE, article.get_absolute_url()))
+    
+#    short url
+    url = '%s%s' % (settings.SITE, article.get_absolute_url())
+    if hasattr(client, 'get_short_url'):
+        short_url = client.get_short_url(url)
+    else:
+        short_url = url
+
     short_url_count = sina_client.count_words(short_url)
+    
+    # Base content
     base = u"发表了文章《》 - ... "
     base_count = sina_client.count_words(base)
     
         and article.share \
         and article.shares.filter(type=social_type).count() == 0:
         
-        share_id = client.update_status(get_sync_content(article, social_type))
+        share_id = client.update_status(get_sync_content(article, client, social_type))
         
         content_type = ContentType.objects.get(model='article')
         share = SocialItem(share_id=share_id, content_type=content_type, type=social_type, object_id=article.id)

File ChineBlog/blog/templates/blog/coolblue/footer.html

       	        <li><a title="Renren" href="http://www.renren.com/profile.do?id=722143160" rel="nofollow">
 				<img alt="Renren" title="Renren" src="/static/blog/coolblue/images/renren.png" style="width: 48px; height: 48px;" /></a>
 			    </li>
-			    <li><a title="Weibo" href="http://t.sina.com.cn/chinekingseu" rel="nofollow">
+			    <li><a title="Weibo" href="http://weibo.com/myblueshow" rel="nofollow">
 				<img alt="Weibo" title="Weibo" src="/static/blog/coolblue/images/WeiBo.png" /></a>
 			    </li>
 			    <li><a title="通过邮件订阅" href="#" rel="nofollow">
 
             <p style="width: 200px;">保持更新,通过订阅
 		    <a href="{% url blog_rss %}">RSS</a>, <a href="http://www.renren.com/profile.do?id=722143160">人人</a>,
-			<a href="http://t.sina.com.cn/chinekingseu">新浪微博</a> or <a href="index">Email</a>
+			<a href="http://weibo.com/myblueshow">新浪微博</a> or <a href="index">Email</a>
 		    </p>
 
 	    </div>

File ChineBlog/settings.py

 # Google CustomSearch api
 GOOGLE_SEARCH_ENGINE_UNIQUE_ID = ''
 GOOGLE_CUSTOM_SEARCH_ENDPOINT = 'https://www.googleapis.com/customsearch/v1'
+
+# Google Url Shortener api
+GOOGLE_URL_SHORTENER_ENDPOINT = 'https://www.googleapis.com/urlshortener/v1/url'
                         
 # Weibo
 ENABLE_WEIBO_ACCOUNT = False

File ChineBlog/social/google/__init__.py

         blog_user['avatar'] = user_data['picture']
         
         return blog_user
+
+def get_short_url(url):
+    data = json.dumps({
+        'longUrl': url, 
+    })
+    headers = {"Content-Type": "application/json"}
+    req = urllib2.Request(settings.GOOGLE_URL_SHORTENER_ENDPOINT, data, headers)
+    resp = urllib2.urlopen(req)
+    
+    return json.loads(resp.read()).get('id', None)
     
 class GooglePlusClient(object):
     def __init__(self, **kwargs):

File ChineBlog/social/txweibo/__init__.py

 
 from qqweibo import OAuthHandler, API
 from ChineBlog.social.weibo import client as weibo_client
+from ChineBlog.social.google import get_short_url
 
 def get_oauth_handler():
     return OAuthHandler(settings.QQWEIBO_API['app_key'], 
         return r.id
     
     def get_short_url(self, url):
-        return weibo_client.get_short_url(url)
+#        return weibo_client.get_short_url(url)
+        return get_short_url(url)
     
     
 client = BlogQQWeiboClient()