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


Python URL.query_param方法代码示例

本文整理汇总了Python中purl.URL.query_param方法的典型用法代码示例。如果您正苦于以下问题:Python URL.query_param方法的具体用法?Python URL.query_param怎么用?Python URL.query_param使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在purl.URL的用法示例。


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

示例1: get_links

# 需要导入模块: from purl import URL [as 别名]
# 或者: from purl.URL import query_param [as 别名]
    def get_links(self, request):

        edit_link = URL(request.link(self.submission))
        edit_link = edit_link.query_param("edit", "")
        edit_link = edit_link.query_param("return-to", request.url)

        return [Link(text=_("Edit submission"), url=edit_link.as_string(), classes=("edit-link",))]
开发者ID:i18nHub,项目名称:onegov.town,代码行数:9,代码来源:ticket.py

示例2: get_submission_link

# 需要导入模块: from purl import URL [as 别名]
# 或者: from purl.URL import query_param [as 别名]
def get_submission_link(request, submission, confirm_link):
    url = URL(request.link(submission))
    url = url.query_param('return-to', confirm_link)
    url = url.query_param('title', request.translate(
        _("Details about the reservation"))
    )
    url = url.query_param('edit', 1)
    url = url.query_param('quiet', 1)

    return url.as_string()
开发者ID:i18nHub,项目名称:onegov.town,代码行数:12,代码来源:reservation.py

示例3: UnicodeTests

# 需要导入模块: from purl import URL [as 别名]
# 或者: from purl.URL import query_param [as 别名]
class UnicodeTests(TestCase):

    def setUp(self):
        self.base = URL('http://127.0.0.1/')
        self.text = u'ć'
        self.bytes = self.text.encode('utf8')

    def test_set_unicode_query_param_value(self):
        url = self.base.query_param('q', self.text)
        self.assertEqual(self.text, url.query_param('q'))

    def test_set_bytestring_query_param_value(self):
        url = self.base.query_param('q', self.bytes)
        self.assertEqual(self.text, url.query_param('q'))

    def test_set_unicode_query_param_key(self):
        url = self.base.query_param(self.text, 'value')
        self.assertEqual('value', url.query_param(self.text))

    def test_set_bytestring_query_param_key(self):
        url = self.base.query_param(self.bytes, 'value')
        self.assertEqual('value', url.query_param(self.text))

    def test_append_unicode_query_param(self):
        url = self.base.append_query_param('q', self.text)
        self.assertEqual(self.text, url.query_param('q'))

    def test_append_bytestring_query_param(self):
        url = self.base.append_query_param('q', self.bytes)
        self.assertEqual(self.text, url.query_param('q'))

    def test_set_unicode_query_params(self):
        url = self.base.query_params({'q': self.text})
        self.assertEqual(self.text, url.query_param('q'))

    def test_set_bytestring_query_params(self):
        url = self.base.query_params({'q': self.bytes})
        self.assertEqual(self.text, url.query_param('q'))

    def test_add_unicode_path_segment(self):
        url = self.base.add_path_segment(self.text)
        self.assertEqual(self.text, url.path_segment(0))

    def test_add_bytestring_path_segment(self):
        url = self.base.add_path_segment(self.bytes)
        self.assertEqual(self.text, url.path_segment(0))

    def test_add_bytestring_path_segment(self):
        url = self.base.add_path_segment(self.bytes)
        self.assertEqual(self.text, url.path_segment(0))

    def test_add_unicode_fragment(self):
        url = self.base.fragment(self.text)
        self.assertEqual(self.text, url.fragment())
开发者ID:suquant,项目名称:purl,代码行数:56,代码来源:tests.py

示例4: get_links

# 需要导入模块: from purl import URL [as 别名]
# 或者: from purl.URL import query_param [as 别名]
    def get_links(self, request):

        edit_link = URL(request.link(self.submission))
        edit_link = edit_link.query_param('edit', '')
        edit_link = edit_link.query_param('return-to', request.url)

        return [
            Link(
                text=_('Edit submission'),
                url=edit_link.as_string(),
                classes=('edit-link', )
            )
        ]
开发者ID:Gitlab11,项目名称:onegov.town,代码行数:15,代码来源:ticket.py

示例5: set_param

# 需要导入模块: from purl import URL [as 别名]
# 或者: from purl.URL import query_param [as 别名]
def set_param(request=None, url=None, **kwargs):
    if not request and not url:
        return '/'
    url = URL(path=request.path, query=request.META['QUERY_STRING']) if request else URL(url)
    for k, v in kwargs.items():
        url = url.query_param(k, v)
    return url.as_string()
开发者ID:pinkevich,项目名称:django-project-template,代码行数:9,代码来源:utils.py

示例6: editbar_links

# 需要导入模块: from purl import URL [as 别名]
# 或者: from purl.URL import query_param [as 别名]
    def editbar_links(self):
        if self.request.is_logged_in:
            edit_url = URL(self.request.link(self.model.event, 'bearbeiten'))
            edit_url = edit_url.query_param(
                'return-to', self.request.link(self.model.event)
            )
            edit_link = Link(
                text=_("Edit"),
                url=edit_url.as_string(),
                classes=('edit-link', )
            )

            if self.event_deletable(self.model.event):
                delete_link = DeleteLink(
                    text=_("Delete"),
                    url=self.request.link(self.model.event),
                    confirm=_("Do you really want to delete this event?"),
                    yes_button_text=_("Delete event"),
                    redirect_after=self.events_url
                )
            else:
                delete_link = DeleteLink(
                    text=_("Delete"),
                    url=self.request.link(self.model.event),
                    confirm=_("This event can't be deleted."),
                    extra_information=_(
                        "To remove this event, go to the ticket and reject it."
                    )
                )

            return [edit_link, delete_link]
开发者ID:i18nHub,项目名称:onegov.town,代码行数:33,代码来源:layout.py

示例7: get_wikipedia

# 需要导入模块: from purl import URL [as 别名]
# 或者: from purl.URL import query_param [as 别名]
def get_wikipedia(args, name):
    url = URL(
        "http://en.wikipedia.org/w/api.php?format=json&action=query&prop=info&inprop=url")

    def get_result(res):
        """
{
    "query": {
        "pages": {
            "45724": {
                "contentmodel": "wikitext",
                "counter": "",
                "editurl":
                    "http://en.wikipedia.org/w/index.php?title=Panthera_leo&action=edit",
                "fullurl": "http://en.wikipedia.org/wiki/Panthera_leo",
                "lastrevid": 535861485,
                "length": 71,
                "ns": 0,
                "pageid": 45724,
                "pagelanguage": "en",
                "redirect": "",
                "title": "Panthera leo",
                "touched": "2014-02-27T02:04:39Z"
            }
        }
    }
}
        """
        res = res.json().get('query', {}).get('pages', {})
        return res.values()[0] if res else {}

    return get_data(args, name, 'wikipedia', url.query_param('titles', name), get_result)
开发者ID:kristinnts11,项目名称:tsammalex,代码行数:34,代码来源:wiki.py

示例8: url

# 需要导入模块: from purl import URL [as 别名]
# 或者: from purl.URL import query_param [as 别名]
 def url(self, path='/', **query):
     url = URL(path)
     if not url.host():
         url = url.host(self.host)
     if not url.scheme():
         url = url.scheme('http')
     for k, v in query.items():
         url = url.query_param(k, v)
     return url
开发者ID:LinguList,项目名称:clldclient,代码行数:11,代码来源:database.py

示例9: get_video_id_from_url

# 需要导入模块: from purl import URL [as 别名]
# 或者: from purl.URL import query_param [as 别名]
    def get_video_id_from_url(self, video_url):
        video_url = URL(video_url)

        if 'youtube' not in video_url.host():
            raise DownytError(
                'Provided URL is not from YouTube: {}'.format(video_url)
            )

        return video_url.query_param('v')
开发者ID:sesh,项目名称:downyt,代码行数:11,代码来源:cli.py

示例10: get_eol

# 需要导入模块: from purl import URL [as 别名]
# 或者: from purl.URL import query_param [as 别名]
def get_eol(args, name):
    """
    http://eol.org/api/search/1.0.json?q=Panthera+leo&page=1&exact=true&\
    filter_by_taxon_concept_id=&filter_by_hierarchy_entry_id=&filter_by_string=
    """
    url = URL('http://eol.org/api/search/1.0.json?page=1&exact=true')

    def get_result(res):
        res = res.json().get('results')
        return res[0] if res else {}

    return get_data(args, name, 'eol', url.query_param('q', name), get_result)
开发者ID:kristinnts11,项目名称:tsammalex,代码行数:14,代码来源:wiki.py

示例11: handle_forbidden

# 需要导入模块: from purl import URL [as 别名]
# 或者: from purl.URL import query_param [as 别名]
def handle_forbidden(self, request):
    """ If a view is forbidden, the request is redirected to the login
    view. There, the user may login to the site and be redirected back
    to the originally forbidden view.

    """

    @request.after
    def set_status_code(response):
        response.status_code = self.code  # pass along 403

    url = URL(request.link(request.app.town, name='login'))
    url = url.query_param('to', request.url)

    return {
        'layout': DefaultLayout(self, request),
        'title': _(u"Access Denied"),
        'login_url': url
    }
开发者ID:Gitlab11,项目名称:onegov.town,代码行数:21,代码来源:exceptionviews.py

示例12: handle_pending_submission

# 需要导入模块: from purl import URL [as 别名]
# 或者: from purl.URL import query_param [as 别名]
def handle_pending_submission(self, request):
    """ Renders a pending submission, takes it's input and allows the
    user to turn the submission into a complete submission, once all data
    is valid.

    """
    collection = FormCollection(request.app.session())

    form = request.get_form(self.form_class, data=self.data)
    form.action = request.link(self)
    form.validate()

    if not request.POST:
        form.ignore_csrf_error()
    else:
        collection.submissions.update(self, form)

    if 'return-to' in request.GET:
        action = URL(form.action)
        action = action.query_param('return-to', request.GET['return-to'])

        form.action = action.as_string()

    completable = not form.errors and 'edit' not in request.GET

    if completable and 'return-to' in request.GET:
        request.success(_(u"Your changes were saved"))
        return morepath.redirect(request.GET['return-to'])

    return {
        'layout': FormSubmissionLayout(self, request),
        'title': self.form.title,
        'form': form,
        'completable': completable,
        'edit_link': request.link(self) + '?edit',
        'complete_link': request.link(self, 'complete'),
        'is_pending': self.state == 'pending',
        'readonly': 'readonly' in request.GET
    }
开发者ID:Gitlab11,项目名称:onegov.town,代码行数:41,代码来源:form_submission.py

示例13: handle_edit_event

# 需要导入模块: from purl import URL [as 别名]
# 或者: from purl.URL import query_param [as 别名]
def handle_edit_event(self, request, form):
    """ Edit an event.

    An anonymous user might edit an initiated event, a logged in user can also
    edit all events.

    """

    assert_anonymous_access_only_temporary(request, self)

    if form.submitted(request):
        form.update_model(self)

        request.success(_("Your changes were saved"))

        if 'return-to' in request.GET:
            return morepath.redirect(request.GET['return-to'])

        return morepath.redirect(request.link(self))

    form.apply_model(self)

    if 'return-to' in request.GET:
        action = URL(form.action)
        action = action.query_param('return-to', request.GET['return-to'])
        form.action = action.as_string()

    layout = EventLayout(self, request)
    layout.breadcrumbs.append(Link(_("Edit"), '#'))
    layout.editbar_links = []

    return {
        'layout': layout,
        'title': self.title,
        'form': form,
        'form_width': 'large'
    }
开发者ID:i18nHub,项目名称:onegov.town,代码行数:39,代码来源:event.py

示例14: test_setting_single_item_list_as_query_param

# 需要导入模块: from purl import URL [as 别名]
# 或者: from purl.URL import query_param [as 别名]
 def test_setting_single_item_list_as_query_param(self):
     url = URL().query_param("q", ["testing"])
     self.assertEqual("testing", url.query_param("q"))
开发者ID:Mondego,项目名称:pyreco,代码行数:5,代码来源:allPythonContent.py

示例15: test_setting_list_as_query_param

# 需要导入模块: from purl import URL [as 别名]
# 或者: from purl.URL import query_param [as 别名]
 def test_setting_list_as_query_param(self):
     url = URL().query_param("q", ["testing", "eggs"])
     self.assertEqual(["testing", "eggs"], url.query_param("q", as_list=True))
开发者ID:Mondego,项目名称:pyreco,代码行数:5,代码来源:allPythonContent.py


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