本文整理汇总了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())
示例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
})
示例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())
示例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())
示例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"])
示例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)
示例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)
示例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()
示例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)
示例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'])
示例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)
示例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)
示例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)
示例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()
示例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'])