コード例 #1
0
ファイル: tasks.py プロジェクト: Dinodog/kitsune
def _add_short_links_chunked(data):
    """Create short_url's for a chunked list of docs."""
    base_url = 'https://{0}%s'.format(Site.objects.get_current().domain)
    for doc in data:
        endpoint = reverse('wiki.document',
                           locale=doc.locale,
                           args=[doc.slug])
        doc.share_link = generate_short_url(base_url % endpoint)
        doc.save()
コード例 #2
0
 def test_generate_short_url_200(self, mock_requests):
     """Tests a valid 200 response for generate_short_url method."""
     mock_json = mock.Mock()
     mock_json.json.return_value = {
         'status_code': 200,
         'data': {
             'url': 'http://mzl.la/LFolSf'
         }
     }
     mock_requests.post.return_value = mock_json
     eq_('http://mzl.la/LFolSf', generate_short_url(self.test_url))
コード例 #3
0
def add_short_links(doc_ids):
    """Create short_url's for a list of docs."""
    base_url = "https://{0}%s".format(Site.objects.get_current().domain)
    docs = Document.objects.filter(id__in=doc_ids)
    try:
        for doc in docs:
            # Use django's reverse so the locale isn't included.
            endpoint = django_reverse("wiki.document", args=[doc.slug])
            doc.update(share_link=generate_short_url(base_url % endpoint))
    except BitlyRateLimitException:
        # The next run of the `generate_missing_share_links` cron job will
        # catch all documents that were unable to be processed.
        pass
コード例 #4
0
ファイル: tasks.py プロジェクト: dbbhattacharya/kitsune
def add_short_links(doc_ids):
    """Create short_url's for a list of docs."""
    base_url = 'https://{0}%s'.format(Site.objects.get_current().domain)
    docs = Document.objects.filter(id__in=doc_ids)
    try:
        for doc in docs:
            endpoint = reverse('wiki.document',
                               locale=doc.locale,
                               args=[doc.slug])
            doc.share_link = generate_short_url(base_url % endpoint)
            doc.save()
    except BitlyRateLimitException:
        # The next run of the `generate_missing_share_links` cron job will
        # catch all documents that were unable to be processed.
        pass
コード例 #5
0
ファイル: tasks.py プロジェクト: zctyhj/kitsune
def add_short_links(doc_ids):
    """Create short_url's for a list of docs."""
    base_url = 'https://{0}%s'.format(Site.objects.get_current().domain)
    docs = Document.objects.filter(id__in=doc_ids)
    try:
        pin_this_thread()  # Stick to master.
        for doc in docs:
            # Use django's reverse so the locale isn't included.
            endpoint = django_reverse('wiki.document', args=[doc.slug])
            doc.update(share_link=generate_short_url(base_url % endpoint))
            statsd.incr('wiki.add_short_links.success')
    except BitlyRateLimitException:
        # The next run of the `generate_missing_share_links` cron job will
        # catch all documents that were unable to be processed.
        statsd.incr('wiki.add_short_links.rate_limited')
        pass
    finally:
        unpin_this_thread()
コード例 #6
0
ファイル: tasks.py プロジェクト: 1234-/kitsune
def add_short_links(doc_ids):
    """Create short_url's for a list of docs."""
    base_url = 'https://{0}%s'.format(Site.objects.get_current().domain)
    docs = Document.objects.filter(id__in=doc_ids)
    try:
        pin_this_thread()  # Stick to master.
        for doc in docs:
            # Use django's reverse so the locale isn't included.
            endpoint = django_reverse('wiki.document', args=[doc.slug])
            doc.update(share_link=generate_short_url(base_url % endpoint))
            statsd.incr('wiki.add_short_links.success')
    except BitlyRateLimitException:
        # The next run of the `generate_missing_share_links` cron job will
        # catch all documents that were unable to be processed.
        statsd.incr('wiki.add_short_links.rate_limited')
        pass
    finally:
        unpin_this_thread()
コード例 #7
0
ファイル: tasks.py プロジェクト: iankronquist/kitsune
def add_short_links(doc_ids):
    """Create short_url's for a list of docs."""
    base_url = 'https://{0}%s'.format(Site.objects.get_current().domain)
    docs = Document.objects.filter(id__in=doc_ids)
    try:
        pin_this_thread()  # Stick to master.
        for doc in docs:
            endpoint = reverse('wiki.document',
                               locale=doc.locale,
                               args=[doc.slug])
            doc.share_link = generate_short_url(base_url % endpoint)
            doc.save()
    except BitlyRateLimitException:
        # The next run of the `generate_missing_share_links` cron job will
        # catch all documents that were unable to be processed.
        pass
    finally:
        unpin_this_thread()
コード例 #8
0
ファイル: test_utils.py プロジェクト: zu83/kitsune
 def test_generate_short_url_200(self, mock_requests):
     """Tests a valid 200 response for generate_short_url method."""
     mock_json = mock.Mock()
     mock_json.json.return_value = {"status_code": 200, "data": {"url": "http://mzl.la/LFolSf"}}
     mock_requests.post.return_value = mock_json
     eq_("http://mzl.la/LFolSf", generate_short_url(self.test_url))