def save(self): """ :rtype: VoidEntity :return: VoidEntity """ Session.add(self) return self
def add_role(user_fk, role_fk): po = UserRoleHeader(user_fk=user_fk, role_fk=role_fk) Session.add(po) permits = Session.query(Permission.code).\ join(RolePermissionHeader).\ filter(RolePermissionHeader.role_fk == role_fk).all() if permits: redis.sadd('user_permits:%s' % user_fk, *[e[0] for e in permits])
def erase(self): old_parent = self.parent if old_parent: cnt = Session.query(func.count(ProductCategory.id)) \ .filter(ProductCategory.parent_fk == old_parent.id).one()[0] if cnt <= 1: old_parent.leaf = True Session.add(old_parent) super().erase()
def set_parent(self, parent=None): """ :param {str|ProductCategory|None} parent: parent_fk or parent; None to remove parent :return: """ if parent: if isinstance(parent, str): if parent == self.id: raise BusinessException('parent should not be oneself') parent = self.__class__.load(parent) if not parent: raise EntityNotFound('%s#%s' % (self.__class__.name, parent)) if parent.id == self.id: raise BusinessException('parent should not be oneself') old_parent = self.parent if parent == old_parent: return if old_parent: cnt = Session.query(func.count(ProductCategory.id))\ .filter(ProductCategory.parent_fk == old_parent.id).one()[0] if cnt <= 1: old_parent.leaf = True Session.add(old_parent) parent.leaf = False self.parent = parent self._update_fullname() else: old_parent = self.parent if old_parent: cnt = Session.query(func.count(ProductCategory.id)) \ .filter(ProductCategory.parent_fk == old_parent.id).one()[0] if cnt <= 1: old_parent.leaf = True Session.add(old_parent) self.parent = None self._update_fullname()