models.py 文件源码

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

项目:balafon 作者: ljean 项目源码 文件源码
def save(self, *args, **kwargs):
        """save"""

        if self.status and self.status.is_final:
            self.done = True
        elif self.type and self.type.allowed_status.filter(is_final=True).exists():
            self.done = False

        if not self.done_date and self.done:
            self.done_date = now_rounded()
        elif self.done_date and not self.done:
            self.done_date = None

        #generate number automatically based on action type
        if self.number == 0 and self.type and self.type.number_auto_generated:
            self.number = self.type.last_number = self.type.last_number + 1
            self.type.save()

        ret = super(Action, self).save(*args, **kwargs)

        if self.type:
            if self.type.generate_uuid and not self.uuid:
                name = u'{0}-action-{1}-{2}'.format(
                    project_settings.SECRET_KEY, self.id, self.type.id if self.type else 0
                )
                name = unicodedata.normalize('NFKD', unicode(name)).encode("ascii", 'ignore')
                self.uuid = unicode(uuid.uuid5(uuid.NAMESPACE_URL, name))
                super(Action, self).save()

            if not self.type.generate_uuid and self.uuid:
                self.uuid = ''
                super(Action, self).save()

        return ret
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号