Exemplo n.º 1
0
    def get_share_page_url_with_tracking(self, sharer, channel, request=None, absolute=False):
        url = self.get_share_page_url(absolute=absolute)
        share = ShareTrackingUrl.create(sharer, url, channel)

        if request and channel != 'testing':
            fact.record('create_share_url', request, dict(url=url, channel=channel, share=share.id))

        return share.url_for_channel()
Exemplo n.º 2
0
def create_email_invite_url(request):
    url = 'http://example.com/download'

    if request.user.is_authenticated():
        sharer = request.user
        share = ShareTrackingUrl.create(sharer, url, 'email')
        url = share.url_for_channel()

    return {'invite_url': url}
Exemplo n.º 3
0
def create_email_invite_url(request):
    url = 'http://example.com/download'

    if request.user.is_authenticated():
        sharer = request.user
        share = ShareTrackingUrl.create(sharer, url, 'email')
        url = share.url_for_channel()

    return {'invite_url': url}
Exemplo n.º 4
0
    def get_share_page_url_with_tracking(self,
                                         sharer,
                                         channel,
                                         request=None,
                                         absolute=False):
        url = self.get_share_page_url(absolute=absolute)
        share = ShareTrackingUrl.create(sharer, url, channel)

        if request and channel != 'testing':
            fact.record('create_share_url', request,
                        dict(url=url, channel=channel, share=share.id))

        return share.url_for_channel()
Exemplo n.º 5
0
 def download_share():
     return ShareTrackingUrl.create(request.user,
                                    'http://example.com/download', channel)
Exemplo n.º 6
0
def share_create_for_channel(request,
                             channel,
                             comment_id=None,
                             quest_id=None,
                             download_link=False,
                             is_invite=False):
    ret = {}

    def download_share():
        return ShareTrackingUrl.create(request.user,
                                       'http://example.com/download', channel)

    if not download_link and comment_id is not None and quest_id is not None:
        raise ValueError("Can't specify both a comment and quest to share.")

    if download_link:
        return {'share_url': download_share().url_for_channel()}

    if is_invite:
        if quest_id is None:
            share_url = download_share().url_for_channel()

            if channel == 'twitter':
                message = _(u"Come draw with me on @DrawQuest! %(url)s" %
                            {'url': share_url})
            elif channel == 'email':
                follow_me_message = _(
                    "You can follow me in the app as \"%(username)s\"" %
                    {'username': getattr(request.user, 'username')
                     }) if request.user.is_authenticated() else ''
                message = _(
                    u"""I'm using DrawQuest, a free creative drawing app for iPhone, iPod touch, and iPad. DrawQuest sends you daily drawing challenges and allows you to create your own to share with friends. %(follow_me_message)s

Download DrawQuest for free here: %(url)s""" % {
                        'follow_me_message': follow_me_message,
                        'url': share_url
                    })
            else:
                message = _(u"Come draw with me on DrawQuest! %(url)s" %
                            {'url': share_url})
        else:
            quest = get_object_or_404(Quest, id=quest_id)

            if channel in ['twitter', 'facebook']:
                share_url = get_share_page_url_with_tracking(quest,
                                                             request.user,
                                                             channel,
                                                             request=request)
            else:
                share_url = download_share().url_for_channel()

            if request.user.is_authenticated(
            ) and quest.author_id == request.user.id:
                if channel == 'twitter':
                    message = _(
                        u"I just created a Quest on @DrawQuest! \"%(quest_title)s\" Come draw it with me: %(url)s"
                        % {
                            'quest_title': quest.title,
                            'url': share_url
                        })
                else:
                    message = _(
                        u"I just created a Quest on DrawQuest! \"%(quest_title)s\" Come draw it with me: %(url)s"
                        % {
                            'quest_title': quest.title,
                            'url': share_url
                        })
            else:
                if channel == 'twitter':
                    message = _(
                        u"Come draw \"%(quest_title)s\" with me on @DrawQuest! %(url)s"
                        % {
                            'quest_title': quest.title,
                            'url': share_url
                        })
                else:
                    message = _(
                        u"Come draw \"%(quest_title)s\" with me on DrawQuest! %(url)s"
                        % {
                            'quest_title': quest.title,
                            'url': share_url
                        })

        return {
            'share_url': share_url,
            'message': message,
        }

    if comment_id is None and quest_id is None:
        share = ShareTrackingUrl.create(request.user, None, channel)
        ret['share_id'] = share.id
        url = share.url_for_channel()
    else:
        if quest_id is not None:
            shared_obj = get_object_or_404(Quest, id=quest_id)
            quest_title = shared_obj.title
        else:
            shared_obj = get_object_or_404(QuestComment, id=comment_id)
            quest_title = shared_obj.parent_comment.title

        author = User.objects.get(id=shared_obj.author_id)

        if channel in ['twitter', 'facebook']:
            url = get_share_page_url_with_tracking(shared_obj,
                                                   request.user,
                                                   channel,
                                                   request=request)
        else:
            url = download_share().url_for_channel()

        if channel == 'twitter':
            if quest_id is not None:
                ret['tweet'] = _(
                    u'Come draw "%(quest_title)s" with me on @DrawQuest! %(url)s'
                    % {
                        'quest_title': quest_title,
                        'url': url
                    })
            else:
                ret['tweet'] = _(u'"%(quest_title)s" %(url)s via @DrawQuest' %
                                 {
                                     'quest_title': quest_title,
                                     'url': url
                                 })

            if author.kv.twitter_privacy.get() == False:
                try:
                    author_screen_name = ret[
                        'twitter_screen_name'] = author.twitteruser.screen_name
                    if quest_id is not None:
                        ret['tweet'] = _(
                            u'Come draw "%(quest_title)s" by @%(screen_name)s with me on @DrawQuest! %(url)s'
                            % {
                                'quest_title': quest_title,
                                'url': url,
                                'screen_name': author_screen_name
                            })
                    else:
                        ret['tweet'] = _(
                            u'"%(quest_title)s" %(url)s by @%(screen_name)s via @DrawQuest'
                            % {
                                'quest_title': quest_title,
                                'url': url,
                                'screen_name': author_screen_name
                            })
                except (AttributeError, TwitterUser.DoesNotExist):
                    pass

            ret['message'] = ret['tweet']
        elif channel == 'email':
            if quest_id is not None:
                ret['message'] = _(
                    u"""I'm using DrawQuest, a free creative drawing app for iPhone, iPod touch, and iPad. DrawQuest sends you daily drawing challenges and allows you to create your own to share with friends. I thought you might enjoy this Quest: \"%(quest_title)s\"

Download DrawQuest for free here: %(url)s""" % {
                        'quest_title': quest_title,
                        'url': url
                    })
            else:
                ret['message'] = _(
                    u"""I thought you'd like this drawing made with DrawQuest, a free creative drawing app for iPhone, iPod touch, and iPad.

\"%(quest_title)s\" %(url)s

Download DrawQuest for free here: %(download_url)s""" % {
                        'quest_title':
                        quest_title,
                        'url':
                        get_share_page_url_with_tracking(
                            shared_obj, request.user, channel,
                            request=request),
                        'download_url':
                        url
                    })
        else:
            if quest_id is not None:
                ret['message'] = _(
                    u"Come draw \"%(quest_title)s\" with me on DrawQuest! %(url)s"
                    % {
                        'quest_title': quest_title,
                        'url': url
                    })
            else:
                if channel == 'text_message':
                    ret['message'] = _(
                        u"""Check out this drawing on DrawQuest: \"%(quest_title)s\" %(url)s

Download DrawQuest for free here: %(download_url)s""" % {
                            'quest_title':
                            quest_title,
                            'url':
                            get_share_page_url_with_tracking(shared_obj,
                                                             request.user,
                                                             channel,
                                                             request=request),
                            'download_url':
                            url
                        })
                else:
                    ret['message'] = _(
                        u"Check out this drawing on DrawQuest: \"%(quest_title)s\" %(url)s"
                        % {
                            'quest_title': quest_title,
                            'url': url
                        })

    if channel == 'facebook':
        url = 'http://example.com' + url

    if not ret.get('message'):
        if channel == 'twitter':
            ret['message'] = _(u"Come draw with me on @DrawQuest! %(url)s" %
                               {'url': url})
        else:
            ret['message'] = _(u"Come draw with me on DrawQuest! %(url)s" %
                               {'url': url})

    ret['share_url'] = url

    return ret
Exemplo n.º 7
0
 def download_share():
     return ShareTrackingUrl.create(request.user, 'http://example.com/download', channel)
Exemplo n.º 8
0
def share_create_for_channel(request, channel, comment_id=None, quest_id=None, download_link=False, is_invite=False):
    ret = {}

    def download_share():
        return ShareTrackingUrl.create(request.user, 'http://example.com/download', channel)

    if not download_link and comment_id is not None and quest_id is not None:
        raise ValueError("Can't specify both a comment and quest to share.")

    if download_link:
        return {'share_url': download_share().url_for_channel()}

    if is_invite:
        if quest_id is None:
            share_url = download_share().url_for_channel()

            if channel == 'twitter':
                message = _(u"Come draw with me on @DrawQuest! %(url)s" % {'url': share_url})
            elif channel == 'email':
                follow_me_message = _("You can follow me in the app as \"%(username)s\"" % {'username': getattr(request.user, 'username')}) if request.user.is_authenticated() else ''
                message = _(u"""I'm using DrawQuest, a free creative drawing app for iPhone, iPod touch, and iPad. DrawQuest sends you daily drawing challenges and allows you to create your own to share with friends. %(follow_me_message)s

Download DrawQuest for free here: %(url)s""" % {'follow_me_message': follow_me_message, 'url': share_url})
            else:
                message = _(u"Come draw with me on DrawQuest! %(url)s" % {'url': share_url})
        else:
            quest = get_object_or_404(Quest, id=quest_id)

            if channel in ['twitter', 'facebook']:
                share_url = get_share_page_url_with_tracking(quest, request.user, channel, request=request)
            else:
                share_url = download_share().url_for_channel()

            if request.user.is_authenticated() and quest.author_id == request.user.id:
                if channel == 'twitter':
                    message = _(u"I just created a Quest on @DrawQuest! \"%(quest_title)s\" Come draw it with me: %(url)s" % {'quest_title': quest.title, 'url': share_url})
                else:
                    message = _(u"I just created a Quest on DrawQuest! \"%(quest_title)s\" Come draw it with me: %(url)s" % {'quest_title': quest.title, 'url': share_url})
            else:
                if channel == 'twitter':
                    message = _(u"Come draw \"%(quest_title)s\" with me on @DrawQuest! %(url)s" % {'quest_title': quest.title, 'url': share_url})
                else:
                    message = _(u"Come draw \"%(quest_title)s\" with me on DrawQuest! %(url)s" % {'quest_title': quest.title, 'url': share_url})

        return {
            'share_url': share_url,
            'message': message,
        }

    if comment_id is None and quest_id is None:
        share = ShareTrackingUrl.create(request.user, None, channel)
        ret['share_id'] = share.id
        url = share.url_for_channel()
    else:
        if quest_id is not None:
            shared_obj = get_object_or_404(Quest, id=quest_id)
            quest_title = shared_obj.title
        else:
            shared_obj = get_object_or_404(QuestComment, id=comment_id)
            quest_title = shared_obj.parent_comment.title

        author = User.objects.get(id=shared_obj.author_id)

        if channel in ['twitter', 'facebook']:
            url = get_share_page_url_with_tracking(shared_obj, request.user, channel, request=request)
        else:
            url = download_share().url_for_channel()

        if channel == 'twitter':
            if quest_id is not None:
                ret['tweet'] = _(u'Come draw "%(quest_title)s" with me on @DrawQuest! %(url)s' % {'quest_title': quest_title, 'url': url})
            else:
                ret['tweet'] = _(u'"%(quest_title)s" %(url)s via @DrawQuest' % {'quest_title': quest_title, 'url': url})

            if author.kv.twitter_privacy.get() == False:
                try:
                    author_screen_name = ret['twitter_screen_name'] = author.twitteruser.screen_name
                    if quest_id is not None:
                        ret['tweet'] = _(u'Come draw "%(quest_title)s" by @%(screen_name)s with me on @DrawQuest! %(url)s' % {'quest_title': quest_title, 'url': url, 'screen_name': author_screen_name})
                    else:
                        ret['tweet'] = _(u'"%(quest_title)s" %(url)s by @%(screen_name)s via @DrawQuest' % {'quest_title': quest_title, 'url': url, 'screen_name': author_screen_name})
                except (AttributeError, TwitterUser.DoesNotExist):
                    pass

            ret['message'] = ret['tweet']
        elif channel == 'email':
            if quest_id is not None:
                ret['message'] = _(u"""I'm using DrawQuest, a free creative drawing app for iPhone, iPod touch, and iPad. DrawQuest sends you daily drawing challenges and allows you to create your own to share with friends. I thought you might enjoy this Quest: \"%(quest_title)s\"

Download DrawQuest for free here: %(url)s""" % {'quest_title': quest_title, 'url': url})
            else:
                ret['message'] = _(u"""I thought you'd like this drawing made with DrawQuest, a free creative drawing app for iPhone, iPod touch, and iPad.

\"%(quest_title)s\" %(url)s

Download DrawQuest for free here: %(download_url)s""" % {'quest_title': quest_title, 'url': get_share_page_url_with_tracking(shared_obj, request.user, channel, request=request), 'download_url': url})
        else:
            if quest_id is not None:
                ret['message'] = _(u"Come draw \"%(quest_title)s\" with me on DrawQuest! %(url)s" % {'quest_title': quest_title, 'url': url})
            else:
                if channel == 'text_message':
                    ret['message'] = _(u"""Check out this drawing on DrawQuest: \"%(quest_title)s\" %(url)s

Download DrawQuest for free here: %(download_url)s""" % {'quest_title': quest_title, 'url': get_share_page_url_with_tracking(shared_obj, request.user, channel, request=request), 'download_url': url})
                else:
                    ret['message'] = _(u"Check out this drawing on DrawQuest: \"%(quest_title)s\" %(url)s" % {'quest_title': quest_title, 'url': url})

    if channel == 'facebook':
        url = 'http://example.com' + url

    if not ret.get('message'):
        if channel == 'twitter':
            ret['message'] = _(u"Come draw with me on @DrawQuest! %(url)s" % {'url': url})
        else:
            ret['message'] = _(u"Come draw with me on DrawQuest! %(url)s" % {'url': url})

    ret['share_url'] = url

    return ret