本文整理汇总了Python中pages.models.Content类的典型用法代码示例。如果您正苦于以下问题:Python Content类的具体用法?Python Content怎么用?Python Content使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Content类的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: edit_page_content
def edit_page_content(request, page_id, lang):
lang_form = LanguageForm({'lang': lang})
if not lang_form.is_valid():
return HttpResponse(_(u'Language is not registered in system.') + _(u" Language code: ") + lang)
page = get_object_or_404(Page, id=page_id)
try:
content = Content.objects.get(page=page_id, lang=lang)
except Content.DoesNotExist:
content = Content(page=page, lang=lang)
ContentForm = get_content_form(('page', 'lang'))
if request.method == 'POST':
content_form = ContentForm(request.POST, prefix='content_form', instance=content)
if content_form.is_valid():
content = content_form.save(commit=False)
content.page = page
content.save()
save = request.POST.get('save', u'save_edit')
if save == u'save':
return redirect('pages:administration:edit_page', id=page_id)
else:
content_form = ContentForm(prefix='content_form', instance=content)
return render(request, 'pages/administration/edit_page_content.html', {
'content': content,
'content_form': content_form,
})
示例2: test_01_set_body_pagelink
def test_01_set_body_pagelink(self):
"""Test the get_body_pagelink_ids and set_body_pagelink functions."""
self.set_setting("PAGE_LINK_FILTER", True)
page1 = self.create_new_page()
page2 = self.create_new_page()
# page2 has a link on page1
content_string = 'test <a href="%s" class="page_%d">hello</a>'
content = Content(
page=page2,
language='en-us',
type='body',
body=content_string % ('#', page1.id)
)
content.save()
self.assertEqual(
Content.objects.get_content(page2, 'en-us', 'body'),
content_string % (page1.get_url_path(), page1.id)
)
self.assertFalse(page2.has_broken_link())
page1.delete()
self.assertEqual(
Content.objects.get_content(page2, 'en-us', 'body'),
'test <a href="#" class="pagelink_broken">hello</a>'
)
self.assertTrue(page2.has_broken_link())
示例3: test_str_method
def test_str_method(self):
"""Problem with encoding __str__ method"""
page = self.new_page({"title": u"АБВГДЕЖ"})
content = Content(page=page, type="title", language="fr-ch", body=u"АБВГДЕЖ")
content.save()
try:
str(content)
except:
self.fail("Cyrilic characters in content should not raise any error")
示例4: test_language_fallback_bug
def test_language_fallback_bug(self):
"""Language fallback doesn't work properly."""
page = self.create_new_page()
c = Content(page=page, type="new_type", body="toto", language="en-us")
c.save()
self.assertEqual(Content.objects.get_content(page, "en-us", "new_type"), "toto")
self.assertEqual(Content.objects.get_content(page, "fr-ch", "new_type"), "")
self.assertEqual(Content.objects.get_content(page, "fr-ch", "new_type", True), "toto")
示例5: test_get_page_from_id_context_variable
def test_get_page_from_id_context_variable(self):
"""Test get_page_from_string_or_id with an id context variable."""
page = self.new_page({"slug": "test"})
self.assertEqual(get_page_from_string_or_id(str(page.id)), page)
content = Content(page=page, language="en-us", type="test_id", body=page.id)
content.save()
context = Context({"current_page": page})
context = RequestContext(MockRequest(), context)
template = Template(
"{% load pages_tags %}" "{% placeholder test_id as str %}" "{% get_page str as p %}" "{{ p.slug }}"
)
self.assertEqual(template.render(context), "test")
示例6: test_get_page_from_id_context_variable
def test_get_page_from_id_context_variable(self):
"""Test get_page_from_string_or_id with an id context variable."""
page = self.new_page({'slug': 'test'})
self.assertEqual(get_page_from_string_or_id(str(page.id)), page)
content = Content(page=page, language='en-us', type='test_id',
body=page.id)
content.save()
context = {'current_page': page}
template = Template('{% load pages_tags %}'
'{% placeholder test_id as str %}'
'{% get_page str as p %}'
'{{ p.slug }}')
self.assertEqual(render(template, context), 'test')
示例7: test_automatic_slug_renaming
def test_automatic_slug_renaming(self):
"""Test a slug renaming."""
self.set_setting("PAGE_AUTOMATIC_SLUG_RENAMING", True)
c = self.get_admin_client()
page_data = self.get_new_page_data()
page_data['slug'] = "slug"
response = c.post('/admin/pages/page/add/', page_data)
self.assertRedirects(response, '/admin/pages/page/')
response = c.post('/admin/pages/page/add/', page_data)
self.assertRedirects(response, '/admin/pages/page/')
response = c.post('/admin/pages/page/add/', page_data)
self.assertRedirects(response, '/admin/pages/page/')
slug = page_data['slug']
page1 = Content.objects.get_content_slug_by_slug(slug).page
page2 = Content.objects.get_content_slug_by_slug(slug+'-2').page
page3 = Content.objects.get_content_slug_by_slug(slug+'-3').page
self.assertNotEqual(page1.id, page2.id)
self.assertNotEqual(page2.id, page3.id)
self.assertEqual(Content.objects.filter(type="slug").count(), 3)
# post again on page 3 doesn't change the slug
page_3_slug = page3.slug()
page_data['slug'] = page_3_slug
response = c.post('/admin/pages/page/%d/' % page3.id, page_data)
self.assertRedirects(response, '/admin/pages/page/')
self.assertEqual(Content.objects.filter(type="slug").count(), 3)
content = Content.objects.get_content_slug_by_slug(page_3_slug)
self.assertEqual(page3.id, content.page.id)
# change an old slug of another page and see that it doesn't
# influence the current slug of this page
old_slug = Content.objects.filter(page=page1).latest("creation_date")
new_slug = Content(page=page1, body=page_3_slug, type="slug")
new_slug.creation_date = old_slug.creation_date - datetime.timedelta(seconds=5)
new_slug.save()
self.assertEqual(Content.objects.filter(type="slug").count(), 4)
# check than the old slug doesn't trigger a new slug for page 3
response = c.post('/admin/pages/page/%d/' % page3.id, page_data)
content = Content.objects.get_content_slug_by_slug(page_3_slug)
self.assertEqual(page3.id, content.page.id)
self.assertEqual(Content.objects.filter(type="slug").count(), 4)
new_slug.creation_date = old_slug.creation_date + datetime.timedelta(seconds=5)
new_slug.save()
# check than the new slug does trigger a new slug for page 3
response = c.post('/admin/pages/page/%d/' % page3.id, page_data)
content = Content.objects.get_content_slug_by_slug(page_3_slug)
self.assertEqual(page1.id, content.page.id)
content = Content.objects.get_content_slug_by_slug(page_3_slug+'-2')
self.assertEqual(page3.id, content.page.id)
示例8: test_language_fallback_bug
def test_language_fallback_bug(self):
"""Language fallback doesn't work properly."""
page = self.create_new_page()
c = Content(page=page, type='new_type', body='toto', language='en-us')
c.save()
self.assertEqual(
Content.objects.get_content(page, 'en-us', 'new_type'),
'toto'
)
self.assertEqual(
Content.objects.get_content(page, 'fr-ch', 'new_type'),
''
)
self.assertEqual(
Content.objects.get_content(page, 'fr-ch', 'new_type', True),
'toto'
)