def publish_to_social_networks(sender, request, record, **kwargs): from django.contrib.sites.models import Site from django.utils.html import strip_tags from facebook_app.models import publish_message profile = request.user.get_profile() if profile.facebook_share or profile.twitter_share: message = record.render_for_social(request) message = message.encode("utf-8") link = "http://%s%s" % (Site.objects.get_current().domain, record.get_absolute_url()) if profile.facebook_share: publish_message(request.user, message, link) if profile.twitter_share: pass elif profile.ask_to_share: request.session[ASK_TO_SHARE_TOKEN] = True
def save(self, request, *args, **kwargs): network = self.cleaned_data["social_network"] profile = request.user.get_profile() if network == "f": if not profile.facebook_access_token: return False profile.facebook_share = True profile.save() # now post their last record last_record = Record.objects.user_records(user=request.user, quantity=1)[0] message = last_record.render_for_social(request) message = message.encode("utf-8") link = "http://%s%s?source=sm-fb-post&subsource=%s" % ( Site.objects.get_current().domain, last_record.get_absolute_url(), last_record.get_absolute_url()) publish_message(request.user, message, link) if network == "t": profile = request.user.get_profile() profile.twitter_share = True profile.save() return True
def publish_to_social_networks(sender, request, record, **kwargs): from django.contrib.sites.models import Site from django.utils.html import strip_tags from facebook_app.models import publish_message from twitter_app.utils import update_status from twitter_app.oauth import OAuthToken profile = request.user.get_profile() if profile.facebook_share or profile.twitter_share: message = record.render_for_social(request) message = message.encode("utf-8") link = "http://%s%s" % (Site.objects.get_current().domain, record.get_absolute_url()) try: if profile.facebook_share: publish_message(request.user, message, link) except: pass try: if profile.twitter_share: update_status(OAuthToken.from_string(profile.twitter_access_token), "%s (%s)" % (message, link)) except: pass
def save(self, request, *args, **kwargs): network = self.cleaned_data["social_network"] profile = request.user.get_profile() if network == "f": if not profile.facebook_access_token: return False profile.facebook_share = True profile.save() # now post their last record last_record = Record.objects.user_records(user=request.user, quantity=1)[0] message = last_record.render_for_social(request) message = message.encode("utf-8") link = "http://%s%s?source=sm-fb-post&subsource=%s" % ( Site.objects.get_current().domain, last_record.get_absolute_url(), last_record.get_absolute_url(), ) publish_message(request.user, message, link) if network == "t": profile = request.user.get_profile() profile.twitter_share = True profile.save() return True