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


Python helpers.urlparams函数代码示例

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


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

示例1: test_post_absolute_url

    def test_post_absolute_url(self):
        p = Post.objects.get(pk=1)
        url_ = reverse("forums.posts", kwargs={"forum_slug": p.thread.forum.slug, "thread_id": p.thread.id})
        exp_ = urlparams(url_, hash="post-%s" % p.id)
        eq_(exp_, p.get_absolute_url())

        p = Post.objects.get(pk=24)
        url_ = reverse("forums.posts", kwargs={"forum_slug": p.thread.forum.slug, "thread_id": p.thread.id})
        exp_ = urlparams(url_, hash="post-%s" % p.id, page=2)
        eq_(exp_, p.get_absolute_url())
开发者ID:MechanisM,项目名称:kitsune,代码行数:10,代码来源:test_models.py

示例2: test_no_update_tagging

    def test_no_update_tagging(self):
        url = urlparams(reverse('questions.add_tag', args=[self.q.id]))
        self._request_and_no_update(url, req_type='POST', data={
                'tag-name': 'foo'
            })

        url = urlparams(reverse('questions.remove_tag', args=[self.q.id]))
        self._request_and_no_update(url, req_type='POST', data={
                'remove-tag-foo': 1
            })
开发者ID:bajubullet,项目名称:kitsune,代码行数:10,代码来源:test_views.py

示例3: test_post_absolute_url

    def test_post_absolute_url(self):
        p = Post.objects.get(pk=1)
        url_ = reverse('wiki.discuss.posts',
                       args=[p.thread.document.slug, p.thread.id])
        exp_ = urlparams(url_, hash='post-%s' % p.id)
        eq_(exp_, p.get_absolute_url())

        p = Post.objects.get(pk=24)
        url_ = reverse('wiki.discuss.posts',
                       args=[p.thread.document.slug, p.thread.id])
        exp_ = urlparams(url_, hash='post-%s' % p.id, page=2)
        eq_(exp_, p.get_absolute_url())
开发者ID:MechanisM,项目名称:kitsune,代码行数:12,代码来源:test_models.py

示例4: test_post_absolute_url

    def test_post_absolute_url(self):
        p = Post.objects.get(pk=1)
        url_ = reverse('forums.posts',
                       kwargs={'forum_slug': p.thread.forum.slug,
                               'thread_id': p.thread.id})
        exp_ = urlparams(url_, hash='post-%s' % p.id)
        eq_(exp_, p.get_absolute_url())

        p = Post.objects.get(pk=24)
        url_ = reverse('forums.posts',
                       kwargs={'forum_slug': p.thread.forum.slug,
                               'thread_id': p.thread.id})
        exp_ = urlparams(url_, hash='post-%s' % p.id, page=2)
        eq_(exp_, p.get_absolute_url())
开发者ID:AutomatedTester,项目名称:kitsune,代码行数:14,代码来源:test_models.py

示例5: test_login_next_parameter_in_forms

    def test_login_next_parameter_in_forms(self):
        """Test with a valid ?next=url parameter."""
        # header and footer forms
        next = "/en-US/demos/submit"
        response = self.client.get(urlparams(reverse("demos_submit")))
        eq_(200, response.status_code)
        doc = pq(response.content)
        eq_(next, doc('#main-header input[name="next"]')[0].attrib["value"])

        # user login page - someone logged-out clicks edit
        next = "/en-US/docs/Testing$edit"
        response = self.client.get(urlparams(reverse("users.login"), next=next))
        eq_(200, response.status_code)
        doc = pq(response.content)
        eq_(next, doc('input[name="next"]')[0].attrib["value"])
开发者ID:craigcook,项目名称:kuma,代码行数:15,代码来源:test_templates.py

示例6: test_search_suggestion_question_age

    def test_search_suggestion_question_age(self):
        """Verifies the view doesn't return old questions."""
        topic(title='Fix problems', slug='fix-problems', save=True)
        p = product(slug=u'firefox', save=True)

        q1 = question(title='Fresh Cupcakes', save=True)
        q1.products.add(p)

        max_age = settings.SEARCH_DEFAULT_MAX_QUESTION_AGE
        too_old = datetime.now() - timedelta(seconds=max_age * 2)
        q2 = question(title='Stale Cupcakes', created=too_old, updated=too_old,
                      save=True)
        q2.products.add(p)

        self.refresh()

        url = urlparams(
            reverse('questions.aaq_step4', args=['desktop', 'fix-problems']),
                    search='cupcakes')

        response = self.client.get(url, follow=True)
        eq_(200, response.status_code)

        self.assertContains(response, q1.title)
        self.assertNotContains(response, q2.title)
开发者ID:bajubullet,项目名称:kitsune,代码行数:25,代码来源:test_views.py

示例7: process_request

    def process_request(self, request):
        prefixer = Prefixer(request)
        set_url_prefixer(prefixer)
        full_path = prefixer.fix(prefixer.shortened_path)

        if 'lang' in request.GET:
            # Blank out the locale so that we can set a new one. Remove lang
            # from the query params so we don't have an infinite loop.
            prefixer.locale = ''
            new_path = prefixer.fix(prefixer.shortened_path)
            query = dict((smart_str(k), v) for
                         k, v in request.GET.iteritems() if k != 'lang')
            return HttpResponsePermanentRedirect(urlparams(new_path, **query))

        if full_path != request.path:
            query_string = request.META.get('QUERY_STRING', '')
            full_path = urllib.quote(full_path.encode('utf-8'))

            if query_string:
                full_path = '%s?%s' % (full_path, query_string)

            response = HttpResponsePermanentRedirect(full_path)

            # Vary on Accept-Language if we changed the locale
            old_locale = prefixer.locale
            new_locale, _ = split_path(full_path)
            if old_locale != new_locale:
                response['Vary'] = 'Accept-Language'

            return response

        request.path_info = '/' + prefixer.shortened_path
        request.locale = prefixer.locale
        tower.activate(prefixer.locale)
开发者ID:Reinmar,项目名称:kuma,代码行数:34,代码来源:middleware.py

示例8: test_search_suggestions_archived_articles

    def test_search_suggestions_archived_articles(self):
        """Verifies that archived articles aren't shown."""
        topic(title='Fix problems', slug='fix-problems', save=True)
        p = product(slug=u'firefox', save=True)

        d1 = document(title=u'document donut', category=10, save=True)
        d1.products.add(p)
        revision(document=d1, is_approved=True, save=True)

        d2 = document(title=u'document cupcake', category=10, is_archived=True,
                      save=True)
        d2.products.add(p)
        revision(document=d1, is_approved=True, save=True)

        self.refresh()

        url = urlparams(
            reverse('questions.aaq_step4', args=['desktop', 'fix-problems']),
            search='document')

        response = self.client.get(url, follow=True)
        eq_(200, response.status_code)

        doc = pq(response.content)
        eq_(len(doc('.result.document')), 1)
        assert 'donut' in doc('.result.document h3 a').text()
        assert 'cupcake' not in doc('.result.document h3 a').text()
开发者ID:bajubullet,项目名称:kitsune,代码行数:27,代码来源:test_views.py

示例9: add_tag_async

def add_tag_async(request, question_id):
    """Add a (case-insensitive) tag to question asyncronously. Return empty.

    If the question already has the tag, do nothing.

    """
    try:
        question, canonical_name = _add_tag(request, question_id)
    except Tag.DoesNotExist:
        return HttpResponse(json.dumps({'error': unicode(UNAPPROVED_TAG)}),
                            mimetype='application/json',
                            status=400)

    if canonical_name:
        question.clear_cached_tags()
        tag = Tag.objects.get(name=canonical_name)
        tag_url = urlparams(reverse('questions.questions'), tagged=tag.slug)
        data = {'canonicalName': canonical_name,
                'tagUrl': tag_url}
        return HttpResponse(json.dumps(data),
                            mimetype='application/json')

    return HttpResponse(json.dumps({'error': unicode(NO_TAG)}),
                        mimetype='application/json',
                        status=400)
开发者ID:victorneo,项目名称:kitsune,代码行数:25,代码来源:views.py

示例10: test_login_next_parameter_in_forms

    def test_login_next_parameter_in_forms(self):
        '''Test with a valid ?next=url parameter.'''
        # header and footer forms
        next = '/en-US/demos/submit'
        response = self.client.get(urlparams(reverse('demos_submit')))
        eq_(200, response.status_code)
        doc = pq(response.content)
        eq_(next, doc('#masthead input[name="next"]')[0].attrib['value'])

        # user login page - someone logged-out clicks edit
        next = '/en-US/docs/Testing$edit'
        response = self.client.get(urlparams(reverse('users.login'),
                                             next=next))
        eq_(200, response.status_code)
        doc = pq(response.content)
        eq_(next, doc('input[name="next"]')[0].attrib['value'])
开发者ID:gerv,项目名称:kuma,代码行数:16,代码来源:test_templates.py

示例11: get_last_post_url

 def get_last_post_url(self):
     query = {'last': self.last_post_id}
     page = self.last_page
     if page > 1:
         query['page'] = page
     url = reverse('forums.posts', args=[self.forum.slug, self.id])
     return urlparams(url, hash='post-%s' % self.last_post_id, **query)
开发者ID:readevalprint,项目名称:kitsune,代码行数:7,代码来源:models.py

示例12: test_intermediate

    def test_intermediate(self):
        """
        Test that the intermediate DocumentAttachment gets created
        correctly when adding an Attachment with a document_id.

        """
        doc = document(locale='en', slug='attachment-test-intermediate')
        doc.save()
        rev = revision(document=doc, is_approved=True)
        rev.save()

        file_for_upload = make_test_file(
            content='A file for testing intermediate attachment model.')

        post_data = {
            'title': 'Intermediate test file',
            'description': 'Intermediate test file',
            'comment': 'Initial upload',
            'file': file_for_upload,
        }

        add_url = urlparams(reverse('attachments.new_attachment'),
                            document_id=doc.id)
        resp = self.client.post(add_url, data=post_data)
        eq_(302, resp.status_code)

        eq_(1, doc.files.count())

        intermediates = DocumentAttachment.objects.filter(document__pk=doc.id)
        eq_(1, intermediates.count())

        intermediate = intermediates[0]
        eq_('admin', intermediate.attached_by.username)
        eq_(file_for_upload.name.split('/')[-1], intermediate.name)
开发者ID:Faldrian,项目名称:kuma,代码行数:34,代码来源:test_views.py

示例13: _new_question

 def _new_question(self, post_it=False):
     """Post a new question and return the response."""
     topic(title="Fix problems", slug="fix-problems", save=True)
     url = urlparams(reverse("questions.aaq_step5", args=["desktop", "fix-problems"]), search="A test question")
     if post_it:
         return self.client.post(url, self.data, follow=True)
     return self.client.get(url, follow=True)
开发者ID:atopal,项目名称:kitsune,代码行数:7,代码来源:test_views.py

示例14: sub_test

 def sub_test(locale, *titles):
     url = urlparams(reverse("questions.questions", locale=locale))
     response = self.client.get(url, follow=True)
     doc = pq(response.content)
     eq_msg(len(doc("section[id^=question]")), len(titles), "Wrong number of results for {0}".format(locale))
     for substr in titles:
         assert substr in doc(".questions section .content h2 a").text()
开发者ID:atopal,项目名称:kitsune,代码行数:7,代码来源:test_views.py

示例15: test_send_message_to_prefilled

 def test_send_message_to_prefilled(self, flag_is_active):
     flag_is_active.return_value = True
     url = urlparams(reverse('messages.new'), to=self.user2.username)
     response = self.client.get(url, follow=True)
     eq_(200, response.status_code)
     eq_(self.user2.username,
         pq(response.content)('#id_to')[0].attrib['value'])
开发者ID:bowmasters,项目名称:kitsune,代码行数:7,代码来源:test_templates.py


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