summaryrefslogtreecommitdiffstats
path: root/askbot/views
diff options
context:
space:
mode:
authorEvgeny Fadeev <evgeny.fadeev@gmail.com>2013-04-15 05:25:59 -0400
committerEvgeny Fadeev <evgeny.fadeev@gmail.com>2013-04-15 05:25:59 -0400
commit0d5b61161be04616973495ba39822e1af60a6f0b (patch)
tree81c61d4e417ed59a842c5d890889f3cb719077ad /askbot/views
parent7ebc10362bf662489a0eba6105bd6d0d897d9541 (diff)
downloadaskbot-0d5b61161be04616973495ba39822e1af60a6f0b.tar.gz
askbot-0d5b61161be04616973495ba39822e1af60a6f0b.tar.bz2
askbot-0d5b61161be04616973495ba39822e1af60a6f0b.zip
added basic UI for auto-tweeting
Diffstat (limited to 'askbot/views')
-rw-r--r--askbot/views/__init__.py1
-rw-r--r--askbot/views/sharing.py53
2 files changed, 54 insertions, 0 deletions
diff --git a/askbot/views/__init__.py b/askbot/views/__init__.py
index a3c5e06d..167e231a 100644
--- a/askbot/views/__init__.py
+++ b/askbot/views/__init__.py
@@ -6,6 +6,7 @@ from askbot.views import writers
from askbot.views import commands
from askbot.views import users
from askbot.views import meta
+from askbot.views import sharing
from askbot.views import widgets
from django.conf import settings
if 'avatar' in settings.INSTALLED_APPS:
diff --git a/askbot/views/sharing.py b/askbot/views/sharing.py
new file mode 100644
index 00000000..0ba7686c
--- /dev/null
+++ b/askbot/views/sharing.py
@@ -0,0 +1,53 @@
+from askbot import const
+from askbot.deps.django_authopenid.util import OAuthConnection
+from askbot.utils import decorators
+from django.contrib.auth.decorators import login_required
+from django.core.urlresolvers import reverse
+from django.http import HttpResponseRedirect
+from django.views.decorators import csrf
+from django.utils import simplejson
+
+@login_required
+def start_sharing_twitter(request):
+ #start oauth process to authorize tweeting
+ #on behalf of user
+ callback_url = reverse('save_twitter_access_token')
+ connection = OAuthConnection('twitter', callback_url=callback_url)
+ connection.start()
+ request.session['oauth_token'] = connection.get_token()
+ oauth_url = connection.get_auth_url(login_only=False)
+ return HttpResponseRedirect(oauth_url)
+
+@login_required
+def save_twitter_access_token(request):
+ oauth_token = request.GET['oauth_token']
+ session_oauth_token = request.session['oauth_token']
+ assert(oauth_token == session_oauth_token['oauth_token'])
+ oauth = OAuthConnection('twitter')
+ access_token_data = oauth.get_access_token(
+ oauth_token = session_oauth_token,
+ oauth_verifier = request.GET['oauth_verifier']
+ )
+ #save the access token
+ request.user.twitter_access_token = simplejson.dumps(access_token_data)
+ request.user.twitter_handle = access_token_data['screen_name']
+ if request.user.social_sharing_mode == const.SHARE_NOTHING:
+ request.user.social_sharing_mode = const.SHARE_MY_POSTS
+ request.user.save()
+ #todo: set up user associaton for the login via twitter
+ #todo: save message that user can also login via twitter
+ return HttpResponseRedirect(request.user.get_profile_url())
+
+@csrf.csrf_exempt
+@decorators.ajax_only
+@decorators.post_only
+def change_social_sharing_mode(request):
+ mode = request.POST['mode']
+ if mode == 'share-nothing':
+ request.user.social_sharing_mode = const.SHARE_NOTHING
+ elif mode == 'share-my-posts':
+ request.user.social_sharing_mode = const.SHARE_MY_POSTS
+ else:
+ assert(mode == 'share-everything')
+ request.user.social_sharing_mode = const.SHARE_EVERYTHING
+ request.user.save()