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


Python Content.save方法代码示例

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


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

示例1: edit_page_content

# 需要导入模块: from pages.models import Content [as 别名]
# 或者: from pages.models.Content import save [as 别名]
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,
    })
开发者ID:isergey,项目名称:talk.arbicon,代码行数:34,代码来源:views.py

示例2: test_01_set_body_pagelink

# 需要导入模块: from pages.models import Content [as 别名]
# 或者: from pages.models.Content import save [as 别名]
 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())
开发者ID:BBB,项目名称:django-page-cms,代码行数:27,代码来源:test_pages_link.py

示例3: test_automatic_slug_renaming

# 需要导入模块: from pages.models import Content [as 别名]
# 或者: from pages.models.Content import save [as 别名]
    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)
开发者ID:asd1355215911,项目名称:django-page-cms,代码行数:61,代码来源:test_functionnal.py

示例4: test_str_method

# 需要导入模块: from pages.models import Content [as 别名]
# 或者: from pages.models.Content import save [as 别名]
 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")
开发者ID:egorius,项目名称:django-page-cms,代码行数:11,代码来源:test_regression.py

示例5: test_language_fallback_bug

# 需要导入模块: from pages.models import Content [as 别名]
# 或者: from pages.models.Content import save [as 别名]
    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")
开发者ID:egorius,项目名称:django-page-cms,代码行数:12,代码来源:test_regression.py

示例6: test_get_page_from_id_context_variable

# 需要导入模块: from pages.models import Content [as 别名]
# 或者: from pages.models.Content import save [as 别名]
    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")
开发者ID:asd1355215911,项目名称:django-page-cms,代码行数:15,代码来源:test_unit.py

示例7: test_get_page_from_id_context_variable

# 需要导入模块: from pages.models import Content [as 别名]
# 或者: from pages.models.Content import save [as 别名]
    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')
开发者ID:DjangoBD,项目名称:django-page-cms,代码行数:16,代码来源:test_templates.py

示例8: test_language_fallback_bug

# 需要导入模块: from pages.models import Content [as 别名]
# 或者: from pages.models.Content import save [as 别名]
    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'
        )
开发者ID:DjangoBD,项目名称:django-page-cms,代码行数:21,代码来源:test_regression.py


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