• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python helpers.urlparams函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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


示例16: process_request

    def process_request(self, request):
        zones = (DocumentZone.objects.filter(url_root__isnull=False)
                                     .exclude(url_root=''))
        for zone in zones:
            root = '/%s' % zone.url_root
            orig_path = '/docs/%s' % zone.document.slug

            if request.path_info.startswith(orig_path):
                # Is this a request for the "original" wiki path? Redirect to
                # new URL root, if so.
                new_path = request.path_info.replace(orig_path, root, 1)
                new_path = '/%s%s' % (request.locale, new_path)
                
                query = request.GET.copy()
                if 'lang' in query:
                    query.pop('lang')
                new_path = urlparams(new_path, query_dict=query)

                return HttpResponseRedirect(new_path)

            elif request.path_info.startswith(root):
                # Is this a request for the relocated wiki path? If so, rewrite
                # the path as a request for the proper wiki view.
                request.path_info = request.path_info.replace(
                    root, '/docs/%s' % zone.document.slug, 1)
                break
开发者ID:Kapeli,项目名称:kuma,代码行数:26,代码来源:middleware.py


示例17: request

    def request(cls, url, start, end, realm='Webtrends Basic Authentication'):
        """Make an authed request to the webtrends API.

        Make one attempt to fetch and reload the data. If something fails, it's
        the caller's responsibility to retry.
        """

        # If start and/or end are date or datetime, convert to string.
        if isinstance(start, (date, datetime)):
            start = start.strftime('%Ym%md%d')
        if isinstance(end, (date, datetime)):
            end = end.strftime('%Ym%md%d')

        auth_handler = HTTPBasicAuthHandler()
        auth_handler.add_password(realm=realm,
                                  uri=url,
                                  user=settings.WEBTRENDS_USER,
                                  passwd=settings.WEBTRENDS_PASSWORD)
        opener = build_opener(auth_handler)
        url = urlparams(url, start_period=start, end_period=end)
        try:
            # TODO: A wrong username or password results in a recursion depth
            # error.
            return opener.open(url).read()
        except IOError, e:
            raise StatsIOError(*e.args)
开发者ID:Apokalyptica79,项目名称:kitsune,代码行数:26,代码来源:webtrends.py


示例18: get_absolute_url

    def get_absolute_url(self):
        query = {}
        if self.page > 1:
            query = {"page": self.page}

        url = reverse("questions.answers", kwargs={"question_id": self.question_id})
        return urlparams(url, hash="answer-%s" % self.id, **query)
开发者ID:trinaldi,项目名称:kitsune,代码行数:7,代码来源:models.py


示例19: get_absolute_url

    def get_absolute_url(self):
        query = {}
        if self.page > 1:
            query = {'page': self.page}

        url = self.question.get_absolute_url()
        return urlparams(url, hash='answer-%s' % self.id, **query)
开发者ID:sgarrity,项目名称:kitsune,代码行数:7,代码来源:models.py


示例20: test_document_listing

    def test_document_listing(self, flag_is_active):
        """Verify /products/<product slug>/<topic slug> renders articles."""
        flag_is_active.return_value = True

        # Create a topic and product.
        t1 = topic(save=True)
        t2 = topic(save=True)
        p = product(save=True)

        # Create 3 documents with the topic and product and one without.
        for i in range(3):
            doc = revision(is_approved=True, save=True).document
            doc.topics.add(t1)
            doc.products.add(p)
            if i == 1:  # Only one document with t2
                doc.topics.add(t2)

        doc = revision(is_approved=True, save=True).document

        self.refresh()

        # GET the page and verify the content.
        url = reverse('products.documents', args=[p.slug, t1.slug])
        r = self.client.get(url, follow=True)
        eq_(200, r.status_code)
        doc = pq(r.content)
        eq_(3, len(doc('#document-list > ul > li')))

        # GET the page with refine topic and verify the content.
        url = reverse('products.documents', args=[p.slug, t1.slug])
        url = urlparams(url, refine=t2.slug)
        r = self.client.get(url, follow=True)
        eq_(200, r.status_code)
        doc = pq(r.content)
        eq_(1, len(doc('#document-list > ul > li')))
开发者ID:Uwanja,项目名称:kitsune,代码行数:35,代码来源:test_templates.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python parser.get_object_fallback函数代码示例发布时间:2022-05-27
下一篇:
Python projects.Project类代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap