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


Python models.Question类代码示例

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


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

示例1: test_from_url

    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,代码行数:7,代码来源:test_models.py

示例2: test_from_url

    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,代码行数:7,代码来源:test_models.py

示例3: test_from_invalid_url

    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,代码行数:8,代码来源:test_models.py

示例4: test_from_invalid_url

    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,代码行数:8,代码来源:test_models.py

示例5: test_from_invalid_url

    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,代码行数:8,代码来源:test_models.py

示例6: test_no_inactive_users

    def test_no_inactive_users(self):
        """Ensure that inactive users' questions don't appear in the feed."""
        u = user(is_active=False, save=True)

        q = Question(title='Test Question', content='Lorem Ipsum Dolor',
                     creator_id=u.id)
        q.save()
        assert q.id not in [x.id for x in QuestionsFeed().items({})]
开发者ID:BReduardokramer,项目名称:kitsune,代码行数:8,代码来源:test_feeds.py

示例7: test_notification_created

    def test_notification_created(self):
        """Creating a new question auto-watches it for answers."""

        u = User.objects.get(pk=118533)
        q = Question(creator=u, title='foo', content='bar')
        q.save()

        assert QuestionReplyEvent.is_notifying(u, q)
开发者ID:GVRV,项目名称:kitsune,代码行数:8,代码来源:test_models.py

示例8: test_no_inactive_users

 def test_no_inactive_users(self):
     """Ensure that inactive users' questions don't appear in the feed."""
     u = User.objects.get(pk=118533)
     u.is_active = False
     u.save()
     q = Question(title='Test Question', content='Lorem Ipsum Dolor',
                  creator_id=118533)
     q.save()
     assert q.id not in [x.id for x in QuestionsFeed().items()]
开发者ID:GVRV,项目名称:kitsune,代码行数:9,代码来源:test_feeds.py

示例9: test_recent_counts

    def test_recent_counts(self):
        """Verify recent_asked_count and recent unanswered count."""
        # create a question for each of past 4 days
        now = datetime.now()
        question(created=now, save=True)
        question(created=now - timedelta(hours=12), save=True, is_locked=True)
        q = question(created=now - timedelta(hours=23), save=True)
        answer(question=q, save=True)
        # 25 hours instead of 24 to avoid random test fails.
        question(created=now - timedelta(hours=25), save=True)

        # Only 3 are recent from last 72 hours, 1 has an answer.
        eq_(3, Question.recent_asked_count())
        eq_(1, Question.recent_unanswered_count())
开发者ID:Cherpak,项目名称:kitsune,代码行数:14,代码来源:test_models.py

示例10: question

def question(save=False, **kwargs):
    defaults = dict(title=str(datetime.now()),
                    content='',
                    created=datetime.now(),
                    num_answers=0,
                    is_locked=0)
    defaults.update(kwargs)
    if 'creator' not in kwargs and 'creator_id' not in kwargs:
        defaults['creator'] = profile().user
    q = Question(**defaults)
    if save:
        q.save()
    if 'metadata' in defaults:
        if not save:
            raise ValueError('save must be True if metadata provided.')
        q.add_metadata(**defaults['metadata'])
    return q
开发者ID:MarkSchmidty,项目名称:kitsune,代码行数:17,代码来源:__init__.py

示例11: test_recent_counts_with_filter

    def test_recent_counts_with_filter(self):
        """Verify that recent_asked_count and recent_unanswered_count
        respect filters passed."""

        now = datetime.now()
        question(created=now, locale='en-US', save=True)
        q = question(created=now, locale='en-US', save=True)
        answer(question=q, save=True)

        question(created=now, locale='pt-BR', save=True)
        question(created=now, locale='pt-BR', save=True)
        q = question(created=now, locale='pt-BR', save=True)
        answer(question=q, save=True)

        # 5 asked recently, 3 are unanswered
        eq_(5, Question.recent_asked_count())
        eq_(3, Question.recent_unanswered_count())

        # check english (2 asked, 1 unanswered)
        locale_filter = Q(locale='en-US')
        eq_(2, Question.recent_asked_count(locale_filter))
        eq_(1, Question.recent_unanswered_count(locale_filter))

        # check pt-BR (3 asked, 2 unanswered)
        locale_filter = Q(locale='pt-BR')
        eq_(3, Question.recent_asked_count(locale_filter))
        eq_(2, Question.recent_unanswered_count(locale_filter))
开发者ID:Cherpak,项目名称:kitsune,代码行数:27,代码来源:test_models.py

示例12: related_questions

    def related_questions(self):
        """Return questions that are 'morelikethis' document."""
        # Only documents in default IA categories have related.
        if (
            self.redirect_url()
            or not self.current_revision
            or self.category not in settings.IA_DEFAULT_CATEGORIES
            or self.locale not in settings.AAQ_LANGUAGES
        ):
            return []

        # First try to get the results from the cache
        key = "wiki_document:related_questions:%s" % self.id
        questions = cache.get(key)
        if questions is not None:
            statsd.incr("wiki.related_questions.cache.hit")
            log.debug("Getting MLT questions for {doc} from cache.".format(doc=repr(self)))
            return questions

        try:
            statsd.incr("wiki.related_questions.cache.miss")
            max_age = settings.SEARCH_DEFAULT_MAX_QUESTION_AGE
            start_date = int(time.time()) - max_age

            s = Question.get_mapping_type().search()
            questions = (
                s.values_dict("id", "question_title", "url")
                .filter(
                    question_locale=self.locale,
                    product__in=[p.slug for p in self.get_products()],
                    question_has_helpful=True,
                    created__gte=start_date,
                )
                .query(
                    __mlt={
                        "fields": ["question_title", "question_content"],
                        "like_text": self.title,
                        "min_term_freq": 1,
                        "min_doc_freq": 1,
                    }
                )[:3]
            )
            questions = list(questions)
            cache.add(key, questions)
        except ES_EXCEPTIONS:
            statsd.incr("wiki.related_questions.esexception")
            log.exception("ES MLT related_questions")
            questions = []

        return questions
开发者ID:joshua-s,项目名称:kitsune,代码行数:50,代码来源:models.py

示例13: pageviews_by_question

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,代码行数:46,代码来源:googleanalytics.py

示例14: related_questions

    def related_questions(self):
        """Return questions that are 'morelikethis' document."""
        # Only documents in default IA categories have related.
        if (self.redirect_url() or not self.current_revision or
            self.category not in settings.IA_DEFAULT_CATEGORIES):
            return []

        # First try to get the results from the cache
        key = 'wiki_document:related_questions:%s' % self.id
        questions = cache.get(key)
        if questions is not None:
            statsd.incr('wiki.related_questions.cache.hit')
            log.debug('Getting MLT questions for {doc} from cache.'
                .format(doc=repr(self)))
            return questions

        try:
            statsd.incr('wiki.related_questions.cache.miss')
            max_age = settings.SEARCH_DEFAULT_MAX_QUESTION_AGE
            start_date = int(time.time()) - max_age

            s = Question.get_mapping_type().search()
            questions = s.values_dict('id', 'question_title', 'url').filter(
                    question_locale=self.locale,
                    product__in=[p.slug for p in self.get_products()],
                    question_has_helpful=True,
                    created__gte=start_date
                ).query(
                    __mlt={
                        'fields': ['question_title', 'question_content'],
                        'like_text': self.title,
                        'min_term_freq': 1,
                        'min_doc_freq': 1,
                    }
                )[:3]
            questions = list(questions)
            cache.add(key, questions)
        except ES_EXCEPTIONS as exc:
            statsd.incr('wiki.related_questions.esexception')
            log.error('ES MLT {err} related_questions for {doc}'.format(
                    doc=repr(self), err=str(exc)))
            questions = []

        return questions
开发者ID:smillaedler,项目名称:kitsune,代码行数:44,代码来源:models.py

示例15: test_from_url_id_only

 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,代码行数:6,代码来源:test_models.py


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