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


Python Page.from_path方法代码示例

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


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

示例1: handle

# 需要导入模块: from waliki.models import Page [as 别名]
# 或者: from waliki.models.Page import from_path [as 别名]
    def handle(self, *args, **options):
        extensions = [ext.strip() for ext in options["extensions"].split(",")]
        ignored_dirs = [d.strip() for d in options["ignored_dirs"].split(",")]
        for root, dirs, files in os.walk(WALIKI_DATA_DIR):
            [dirs.remove(d) for d in ignored_dirs if d in dirs]
            for filename in files:
                if os.path.splitext(filename)[1] not in extensions:
                    continue
                path = os.path.join(root.replace(WALIKI_DATA_DIR, ""), filename).strip("/")

                if not Page.objects.filter(path=path).exists():
                    page = Page.from_path(path)
                    self.stdout.write("Created page %s for %s" % (page.get_absolute_url(), path))

        # Deleted pages?
        for page in Page.objects.all():
            if not os.path.exists(page.abspath):
                self.stdout.write("Deleted page %s (missing %s)" % (page.get_absolute_url(), page.path))
                page.delete()

        if Attachment:

            class FakeAttachment(object):
                def __init__(self, page):
                    self.page = page

            for page in Page.objects.all():
                path = os.path.join(settings.MEDIA_ROOT, WALIKI_UPLOAD_TO(FakeAttachment(page), ""))
                if not os.path.exists(path):
                    continue
                for filename in os.listdir(path):
                    if not os.path.isfile(os.path.join(path, filename)):
                        continue
                    file = WALIKI_UPLOAD_TO(FakeAttachment(page), filename)
                    if page.attachments.filter(file=file):
                        continue
                    attachment = Attachment.objects.create(page=page, file=file, filename=filename)
                    self.stdout.write("Created attachment %s for %s" % (attachment, page.slug))

            for attachment in Attachment.objects.all():
                if not os.path.exists(os.path.join(settings.MEDIA_ROOT, attachment.file.name)):
                    self.stdout.write(
                        "Missing %s from %s. Deleted attachment object" % (attachment, attachment.page.slug)
                    )
                    attachment.delete()
开发者ID:BrunoMoreno,项目名称:waliki,代码行数:47,代码来源:sync_waliki.py

示例2: handle

# 需要导入模块: from waliki.models import Page [as 别名]
# 或者: from waliki.models.Page import from_path [as 别名]
    def handle(self, *args, **options):
        extensions = [ext.strip() for ext in options['extensions'].split(',')]
        ignored_dirs = [d.strip() for d in options['ignored_dirs'].split(',')]
        for root, dirs, files in os.walk(WALIKI_DATA_DIR):
            [dirs.remove(d) for d in ignored_dirs if d in dirs]
            for filename in files:
                if os.path.splitext(filename)[1] not in extensions:
                    continue
                path = os.path.join(root.replace(WALIKI_DATA_DIR, ''), filename).strip('/')

                if not Page.objects.filter(path=path).exists():
                    page = Page.from_path(path)
                    self.stdout.write('Created page %s for %s' % (page.get_absolute_url(), path))

        for page in Page.objects.all():
            if not os.path.exists(page.abspath):
                self.stdout.write('Deleted page %s (missing %s)' % (page.get_absolute_url(), page.path))
                page.delete()
开发者ID:JuloWaks,项目名称:waliki,代码行数:20,代码来源:sync_waliki.py


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