当前位置: 首页>>代码示例>>Python>>正文


Python Question.from_url方法代码示例

本文整理汇总了Python中kitsune.questions.models.Question.from_url方法的典型用法代码示例。如果您正苦于以下问题:Python Question.from_url方法的具体用法?Python Question.from_url怎么用?Python Question.from_url使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在kitsune.questions.models.Question的用法示例。


在下文中一共展示了Question.from_url方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_from_url

# 需要导入模块: from kitsune.questions.models import Question [as 别名]
# 或者: from kitsune.questions.models.Question import from_url [as 别名]
    def test_from_url(self):
        """Verify question returned from valid URL."""
        q = question(save=True)

        eq_(q, Question.from_url('/en-US/questions/%s' % q.id))
        eq_(q, Question.from_url('/es/questions/%s' % q.id))
        eq_(q, Question.from_url('/questions/%s' % q.id))
开发者ID:Cherpak,项目名称:kitsune,代码行数:9,代码来源:test_models.py

示例2: test_from_url

# 需要导入模块: from kitsune.questions.models import Question [as 别名]
# 或者: from kitsune.questions.models.Question import from_url [as 别名]
    def test_from_url(self):
        """Verify question returned from valid URL."""
        q = QuestionFactory()

        eq_(q, Question.from_url('/en-US/questions/%s' % q.id))
        eq_(q, Question.from_url('/es/questions/%s' % q.id))
        eq_(q, Question.from_url('/questions/%s' % q.id))
开发者ID:1234-,项目名称:kitsune,代码行数:9,代码来源:test_models.py

示例3: test_from_invalid_url

# 需要导入模块: from kitsune.questions.models import Question [as 别名]
# 或者: from kitsune.questions.models.Question import from_url [as 别名]
    def test_from_invalid_url(self):
        """Verify question returned from valid URL."""
        q = question(save=True)

        eq_(None, Question.from_url('/en-US/questions/%s/edit' % q.id))
        eq_(None, Question.from_url('/en-US/kb/%s' % q.id))
        eq_(None, Question.from_url('/random/url'))
        eq_(None, Question.from_url('/en-US/questions/stats'))
开发者ID:Cherpak,项目名称:kitsune,代码行数:10,代码来源:test_models.py

示例4: test_from_invalid_url

# 需要导入模块: from kitsune.questions.models import Question [as 别名]
# 或者: from kitsune.questions.models.Question import from_url [as 别名]
    def test_from_invalid_url(self):
        """Verify question returned from valid URL."""
        q = QuestionFactory()

        eq_(None, Question.from_url('/en-US/questions/%s/edit' % q.id))
        eq_(None, Question.from_url('/en-US/kb/%s' % q.id))
        eq_(None, Question.from_url('/random/url'))
        eq_(None, Question.from_url('/en-US/questions/dashboard/metrics'))
开发者ID:1234-,项目名称:kitsune,代码行数:10,代码来源:test_models.py

示例5: test_from_invalid_url

# 需要导入模块: from kitsune.questions.models import Question [as 别名]
# 或者: from kitsune.questions.models.Question import from_url [as 别名]
    def test_from_invalid_url(self):
        """Verify question returned from valid URL."""
        q = question(save=True)

        eq_(None, Question.from_url('/en-US/questions/{0!s}/edit'.format(q.id)))
        eq_(None, Question.from_url('/en-US/kb/{0!s}'.format(q.id)))
        eq_(None, Question.from_url('/random/url'))
        eq_(None, Question.from_url('/en-US/questions/dashboard/metrics'))
开发者ID:runt18,项目名称:kitsune,代码行数:10,代码来源:test_models.py

示例6: pageviews_by_question

# 需要导入模块: from kitsune.questions.models import Question [as 别名]
# 或者: from kitsune.questions.models.Question import from_url [as 别名]
def pageviews_by_question(start_date, end_date):
    """Return the number of pageviews by question in a given date range.

    Returns a dict with pageviews for each document:
        {question_id>: <pageviews>,
         1: 42,
         7: 1337,...}
    """
    counts = {}
    request = _build_request()
    start_index = 1
    max_results = 10000

    while True:  # To deal with pagination

        @retry_503
        def _make_request():
            return request.get(
                ids='ga:' + profile_id,
                start_date=str(start_date),
                end_date=str(end_date),
                metrics='ga:pageviews',
                dimensions='ga:pagePath',
                filters='ga:pagePathLevel2==/questions/',
                max_results=max_results,
                start_index=start_index).execute()

        results = _make_request()

        for result in results['rows']:
            path = result[0]
            pageviews = int(result[1])
            question_id = Question.from_url(path, id_only=True)
            if not question_id:
                continue

            # The same question can appear multiple times due to url params
            # and locale.
            counts[question_id] = counts.get(question_id, 0) + pageviews

        # Move to next page of results.
        start_index += max_results
        if start_index > results['totalResults']:
            break

    return counts
开发者ID:AndryulE,项目名称:kitsune,代码行数:48,代码来源:googleanalytics.py

示例7: test_from_url_id_only

# 需要导入模块: from kitsune.questions.models import Question [as 别名]
# 或者: from kitsune.questions.models.Question import from_url [as 别名]
 def test_from_url_id_only(self):
     """Verify question returned from valid URL."""
     # When requesting the id, the existence of the question isn't checked.
     eq_(123, Question.from_url('/en-US/questions/123', id_only=True))
     eq_(234, Question.from_url('/es/questions/234', id_only=True))
     eq_(345, Question.from_url('/questions/345', id_only=True))
开发者ID:Cherpak,项目名称:kitsune,代码行数:8,代码来源:test_models.py

示例8: pageviews_by_question

# 需要导入模块: from kitsune.questions.models import Question [as 别名]
# 或者: from kitsune.questions.models.Question import from_url [as 别名]
def pageviews_by_question(start_date, end_date, verbose=False):
    """Return the number of pageviews by question in a given date range.

    Returns a dict with pageviews for each document:
        {question_id>: <pageviews>,
         1: 42,
         7: 1337,...}
    """
    counts = {}
    request = _build_request()
    max_results = 10000

    end_date_step = end_date

    while True:  # To reduce the size of result set request 3 months at a time
        start_date_step = end_date_step - timedelta(90)

        if start_date_step < start_date:
            start_date_step = start_date

        if verbose:
            print 'Fetching data for {0!s} to {1!s}:'.format(start_date_step,
                                                   end_date_step)

        start_index = 1

        while True:  # To deal with pagination

            @retry_503
            def _make_request():
                return request.get(
                    ids='ga:' + profile_id,
                    start_date=str(start_date_step),
                    end_date=str(end_date_step),
                    metrics='ga:pageviews',
                    dimensions='ga:pagePath',
                    filters='ga:pagePathLevel2==/questions/',
                    max_results=max_results,
                    start_index=start_index).execute()

            results = _make_request()

            if verbose:
                d = (max_results - 1
                     if start_index + max_results - 1 < results['totalResults']
                     else results['totalResults'] - start_index)
                print '- Got {0!s} of {1!s} results.'.format(start_index + d,
                                                   results['totalResults'])

            for result in results['rows']:
                path = result[0]
                pageviews = int(result[1])
                question_id = Question.from_url(path, id_only=True)
                if not question_id:
                    continue

                # The same question can appear multiple times due to url params
                # and locale.
                counts[question_id] = counts.get(question_id, 0) + pageviews

            # Move to next page of results.
            start_index += max_results
            if start_index > results['totalResults']:
                break

        end_date_step = start_date_step - timedelta(1)

        if start_date_step == start_date or end_date_step < start_date:
            break

    return counts
开发者ID:runt18,项目名称:kitsune,代码行数:73,代码来源:googleanalytics.py


注:本文中的kitsune.questions.models.Question.from_url方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。