base.py 文件源码

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

项目:Kameleon 作者: ThinkEE 项目源码 文件源码
def __setattr__(self, name, value):
        """
        Overide __setattr__ to update dict value and field value at once
        """
        object.__setattr__(self, name, value)

        if name in self.dictValues: # If updating a field value
            if self._meta.fields[name].salt: # field is salt
                # If field is already salt do nothing.
                # XXX Could create a security issue. What happend is value
                # starts with $2b$ but it's not encrypted. Not critical for now
                if not ("$2b$" in value and value[:4] == "$2b$"):
                    value = bcrypt.hashpw(value.encode('utf8'), bcrypt.gensalt())
                    object.__setattr__(self, name, value)

            # If value is an instance of model class and has a relation.
            # Append it to the corresponding field list
            if hasattr(value, "_meta") and self.isForeignKey(self._meta.fields[name]):
                self.dictValues[name] = getattr(value, self._meta.fields[name].reference.name)
                return

            self.dictValues[name] = value
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号