コード例 #1
0
    def test_valid_text_length_of(self):
        request = construct_dummy_request()
        inner = discussion.valid_text_length_of('statement')
        response = inner(request)
        self.assertFalse(response)
        self.assertIsInstance(response, bool)

        request = construct_dummy_request(json_body={'statement': 'shrt'})
        inner = discussion.valid_text_length_of('statement')
        response = inner(request)
        self.assertFalse(response)
        self.assertIsInstance(response, bool)

        request = construct_dummy_request(
            json_body={'statement': 'loooooooong'})
        inner = discussion.valid_text_length_of('statement')
        response = inner(request)
        self.assertTrue(response)
        self.assertIsInstance(response, bool)
        assert_in('statement', request.validated)

        request = construct_dummy_request(
            json_body={'blorgh': 'more loooooooong'})
        inner = discussion.valid_text_length_of('blorgh')
        response = inner(request)
        self.assertTrue(response)
        self.assertIsInstance(response, bool)
        assert_in('blorgh', request.validated)
コード例 #2
0
@view_config(route_name='get_suggestion_with_similarity_to', renderer='json')
def get_suggestion_with_similarity_to(request):
    """
    Get statements an all regarding information to a given search value.
    The results statements which have a similarity to the search value.

    :param request: current request of the server
    :return: List of statements with a similarity to the search value
    """
    value = request.params.get('q')
    return get_statements_with_similarity_to(value)


# ajax - for sending news
@view_config(route_name='send_news', renderer='json')
@validate(valid_user_as_author, valid_text_length_of('title'), valid_text_length_of('text'))
def send_news(request):
    """
    ajax interface for settings news

    :param request: current request of the server
    :return: json-set with new news
    """
    LOG.debug("Set news via AJAX: %s", request.json_body)
    title = escape_string(request.validated['title'])
    text = escape_string(request.validated['text'])
    db_user = request.validated['user']
    return news_handler.set_news(title, text, db_user, request.registry.settings['pyramid.default_locale_name'],
                                 request.application_url)