models.py 文件源码

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

项目:open-ledger 作者: creativecommons 项目源码 文件源码
def sync(self, attempt_perceptual_hash=False):
        """Attempt to sync the image with the remote location. Optionally does a number of
        other actions:
        * If the image exists and we have not constructed a fingerprint for it,
          do so at this time and populate the image model's perceptual_hash field
          (if attempt_perceptual_hash is True; defaults to False because it's slow)
        * If the image does not exist, mark it as removed_from_source
        * If the image is removed_from_source, delete it from the search engine
        * In all cases, update the last_synced_with_source timestamp on the image"""
        req = requests.head(self.url)
        if req.status_code == 200:
            if not self.perceptual_hash and attempt_perceptual_hash:
                self.perceptual_hash = self.generate_hash()
        else:
            self.removed_from_source = True

        self.last_synced_with_source = timezone.now()

        self.save()
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号