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


Python Site.save方法代码示例

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


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

示例1: test_duplicate_slug

# 需要导入模块: from wagtail.wagtailcore.models import Site [as 别名]
# 或者: from wagtail.wagtailcore.models.Site import save [as 别名]
    def test_duplicate_slug(self):
        from wagtail.wagtailcore.models import Site
        # Create a test Site with a root page
        root = models.TestRootPage(title='title', depth=1, path='0001', slug_en='slug_en', slug_de='slug_de')
        root.save()

        site = Site(root_page=root)
        site.save()

        # Add children to the root
        child = root.add_child(
            instance=models.TestSlugPage1(title='child1', slug_de='child', slug_en='child-en', depth=2, path='00010001')
        )

        child2 = root.add_child(
            instance=models.TestSlugPage2(title='child2', slug_de='child-2', slug_en='child2-en', depth=2,
                                          path='00010002')
        )

        # Clean should work fine as the two slugs are different
        child2.clean()

        # Make the slug equal to test if the duplicate is detected
        child2.slug_de = 'child'

        self.assertRaises(ValidationError, child2.clean)
开发者ID:sinnwerkstatt,项目名称:wagtail-modeltranslation,代码行数:28,代码来源:tests.py

示例2: _import_pages

# 需要导入模块: from wagtail.wagtailcore.models import Site [as 别名]
# 或者: from wagtail.wagtailcore.models.Site import save [as 别名]
 def _import_pages (self, exported_page_data):
     # Delete any existing pages.
     for page in Page.objects.all():
         page.delete()
     with open(exported_page_data, 'r') as fh:
         page_data = cPickle.load(fh)
     for page_name, info in page_data.items():
         self.logger.debug('Creating page {}'.format(page_name))
         page = info['class'](**info['kwargs'])
         page.save()
         self._pages[page_name] = page
     # Add a Wagtail Site, or nothing will appear anywhere.
     home_page = HomePage.objects.all()[0]
     site = Site(hostname='localhost', root_page=home_page,
                 is_default_site=True)
     site.save()
开发者ID:kcl-ddh,项目名称:chopin-online,代码行数:18,代码来源:import_all.py

示例3: run

# 需要导入模块: from wagtail.wagtailcore.models import Site [as 别名]
# 或者: from wagtail.wagtailcore.models.Site import save [as 别名]
def run():
    print 'Running script \'scripts.initial_test_data\' ...'

    admin_user = User.objects.filter(username='admin')
    if not admin_user:
        admin_user = User(username='admin',
                          password=make_password(os.environ.get('WAGTAIL_ADMIN_PW')),
                          is_superuser=True, is_active=True, is_staff=True)
        admin_user.save()
    else:
        admin_user = admin_user[0]


    # # Creates a new site root `CFGov`
    site_root = HomePage.objects.filter(title='CFGOV')
    if not site_root:
        root = Page.objects.first()
        site_root = HomePage(title='CFGOV', slug='home', depth=2, owner=admin_user)
        site_root.live = True
        root.add_child(instance=site_root)
        latest = site_root.save_revision(user=admin_user, submitted_for_moderation=False)
        latest.save()
    else:
        site_root = site_root[0]

    # Setting new site root
    site = Site.objects.first()
    if site.root_page_id != site_root.id:
        site.port = 8000
        site.root_page_id = site_root.id
        site.save()
        content_site = Site(hostname='content.localhost', port=8000, root_page_id=site_root.id)
        content_site.save()

    def publish_page(child=None, root=site_root):
        try:
            root.add_child(instance=child)
        except NodeAlreadySaved:
            pass
        revision = child.save_revision(
            user=admin_user,
            submitted_for_moderation=False,
        )
        revision.publish()

    # Create snippets
    contact = Contact.objects.filter(heading='Test User')
    if not contact:
        contact = Contact(heading='Test User')
    else:
        contact = contact[0]
    contact.contact_info = StreamValue(contact.contact_info.stream_block,
        [
            atomic.contact_email,
            atomic.contact_phone,
            atomic.contact_address
        ], True)
    contact.save()

    # Create each Page Type
    lap = LandingPage.objects.filter(title='Landing Page')
    if not lap:
        lap = LandingPage(title='Landing Page', slug='landing-page', owner=admin_user)
    else:
        lap = lap[0]
    lap.content = StreamValue(lap.content.stream_block,
        [
            atomic.image_text_25_75_group,
            atomic.image_text_50_50_group,
            atomic.half_width_link_blob_group,
            atomic.well
        ], True)
    lap.sidefoot = StreamValue(lap.sidefoot.stream_block,
        [
            atomic.related_links,
            atomic.sidebar_contact(contact.id)
        ], True)
    publish_page(lap)

    sp = SublandingPage.objects.filter(title='Sublanding Page')
    if not sp:
        sp = SublandingPage(title='Sublanding Page', slug='sublanding-page', owner=admin_user)
    else:
        sp = sp[0]
    sp.content = StreamValue(sp.content.stream_block,
        [
            atomic.main_contact_info(contact.id),
            atomic.reg_comment
        ], True)
    sp.sidefoot = StreamValue(sp.sidefoot.stream_block,
        [
            atomic.email_signup,
            atomic.rss_feed
        ], True)

    publish_page(sp)

    bp = BrowsePage.objects.filter(title='Browse Page')
    if not bp:
        bp = BrowsePage(title='Browse Page', slug='browse-page', owner=admin_user)
#.........这里部分代码省略.........
开发者ID:kurtrwall,项目名称:cfgov-refresh,代码行数:103,代码来源:initial_test_data.py

示例4: station_post_saved

# 需要导入模块: from wagtail.wagtailcore.models import Site [as 别名]
# 或者: from wagtail.wagtailcore.models.Site import save [as 别名]
def station_post_saved(sender, instance, created, *args, **kwargs):
    """
    Create the basis for the website: set up settings and pages
    that are common.
    """
    if not created:
        return

    # root pages
    root_page = Page.objects.get(id=1)

    homepage = models.Publication(
        title = instance.name,
        slug = instance.slug,
        body = _(
            'If you see this page, then Aircox is running for the station '
            '{station.name}. You might want to change it to a better one. '
        ).format(station = instance),
    )
    root_page.add_child(instance=homepage)

    # Site
    default_site = Site.objects.filter(is_default_site = True).first()
    is_default_site = False
    if default_site and default_site.pk == 1:
        # default website generated by wagtail: disable is_default_site so
        # we can use it for us
        default_site.is_default_site = False
        default_site.save()
        is_default_site = True

    site = Site(
        # /doc/ when a Station is created, a wagtail Site is generated with
        #       default options. User must set the correct localhost afterwards
        hostname = instance.slug + ".local",
        port = 80,
        site_name = instance.name.capitalize(),
        root_page = homepage,
        is_default_site = is_default_site,
    )
    site.save()

    # settings
    website_settings = models.WebsiteSettings(
        site = site,
        station = instance,
        description = _("The website of the {name} radio").format(
            name = instance.name
        ),
        # Translators: tags set by default in <meta> description of the website
        tags = _('radio,{station.name}').format(station = instance)
    )

    # timetable
    timetable = models.TimetablePage(
        title = _('Timetable'),
    )
    homepage.add_child(instance = timetable)

    # list page (search, terms)
    list_page = models.DynamicListPage(
        # title is dynamic: no need to specify
        title = _('Search'),
    )
    homepage.add_child(instance = list_page)
    website_settings.list_page = list_page

    # programs' page: list of programs in a section
    programs = models.Publication(
        title = _('Programs'),
    )
    homepage.add_child(instance = programs)

    section = sections.Region(
        name = _('programs'),
        position = 'post_content',
        page = programs,
    )
    section.save();
    section.add_item(sections.SectionList(
        count = 15,
        title = _('Programs'),
        url_text = _('All programs'),
        model = ContentType.objects.get_for_model(models.ProgramPage),
        related = programs,
    ))

    website_settings.default_programs_page = programs
    website_settings.sync = True

    # logs (because it is a cool feature)
    logs = models.LogsPage(
        title = _('Previously on air'),
        station = instance,
    )
    homepage.add_child(instance = logs)

    # save
    site.save()
    website_settings.save()
开发者ID:bkfox,项目名称:aircox,代码行数:102,代码来源:signals.py


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