本文整理汇总了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))
示例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))
示例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'))
示例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'))
示例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'))
示例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
示例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))
示例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