def other_services(request, template_name="account/other_services.html"): from microblogging.utils import twitter_verify_credentials from microblogging.pownce_utils import pownce_verify_credentials twitter_form = TwitterForm(request.user) pownce_form = PownceForm(request.user) twitter_authorized = False pownce_authorized = False if request.method == "POST": twitter_form = TwitterForm(request.user, request.POST) if request.POST['actionType'] == 'saveTwitter': if twitter_form.is_valid(): from microblogging.utils import twitter_account_raw twitter_account = twitter_account_raw(request.POST['username'], request.POST['password']) twitter_authorized = twitter_verify_credentials(twitter_account) if not twitter_authorized: request.user.message_set.create(message="Twitter authentication failed") else: twitter_form.save() if request.POST['actionType'] == 'savePownce': pownce_form = PownceForm(request.user, request.POST) if pownce_form.is_valid(): from microblogging.pownce_utils import pownce_account_raw pownce_account = pownce_account_raw(request.POST['usernamep'], request.POST['passwordp']) pownce_authorized = pownce_verify_credentials(pownce_account) if not pownce_authorized: request.user.message_set.create(message="Pownce authentication failed") else: pownce_form.save() else: from microblogging.utils import twitter_account_for_user from microblogging.pownce_utils import pownce_account_for_user twitter_account = twitter_account_for_user(request.user) pownce_account = pownce_account_for_user(request.user) twitter_authorized = twitter_verify_credentials(twitter_account) pownce_authorized = pownce_verify_credentials(pownce_account) twitter_form = TwitterForm(request.user) pownce_form = PownceForm(request.user) return render_to_response(template_name, { "twitter_form": twitter_form, "twitter_authorized": twitter_authorized, "pownce_form": pownce_form, "pownce_authorized":pownce_authorized, }, context_instance=RequestContext(request))
def personal(request, form_class=TweetForm, template_name="microblogging/personal.html", success_url=None): """ just the tweets the current user is following """ twitter_account = twitter_account_for_user(request.user) pownce_account = pownce_account_for_user(request.user) if request.method == "POST": form = form_class(request.user, request.POST) if form.is_valid(): text = form.cleaned_data["text"] form.save() if request.POST.get("pub2twitter", False): twitter_account.PostUpdate(text) if request.POST.get("pub2pownce", False): pownce_account.post_message("all", text) if success_url is None: success_url = reverse("microblogging.views.personal") return HttpResponseRedirect(success_url) reply = None else: reply = request.GET.get("reply", None) form = form_class() if reply: form.fields["text"].initial = u"@%s " % reply tweets = TweetInstance.objects.tweets_for(request.user).order_by("-sent") return render_to_response( template_name, { "form": form, "reply": reply, "tweets": tweets, "twitter_authorized": twitter_verify_credentials(twitter_account), "pownce_authorized": pownce_verify_credentials(pownce_account), }, context_instance=RequestContext(request), )