page_patch.py 文件源码

python
阅读 24 收藏 0 点赞 0 评论 0

项目:wagtail-translation 作者: skirsdeda 项目源码 文件源码
def save(self, *args, **kwargs):
    self.full_clean()

    update_descendant_url_paths = False
    is_new = self.id is None

    if is_new:
        self.set_url_path(self.get_parent())
    else:
        # update url paths if:
        # a) update_fields is specified and it includes any slug field
        # or
        # b) update_fields is not specified (check all slug fields in that case)
        slug_fields = get_translation_fields('slug')
        update_fields = kwargs.get('update_fields', slug_fields)
        updated_slug_fields = [f for f in slug_fields if f in update_fields]
        if updated_slug_fields:
            old_record = Page.objects.get(id=self.id)
            if any(getattr(old_record, f) != getattr(self, f) for f in updated_slug_fields):
                self.set_url_path(self.get_parent())
                update_descendant_url_paths = True

    result = super(Page, self).save(*args, **kwargs)

    if update_descendant_url_paths:
        self._update_descendant_lang_url_paths(old_record)

    if Site.objects.filter(root_page=self).exists():
        delete_root_path_cache()

    if is_new:
        cls = type(self)
        logger.info(
            "Page created: \"%s\" id=%d content_type=%s.%s path=%s",
            self.title,
            self.id,
            cls._meta.app_label,
            cls.__name__,
            self.url_path
        )

    return result
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号