def set_slug_in_elem(elem, newvalue, oldvalue, initiator): elem.slug = slugify(newvalue)
name = Column(String(20), nullable=False, unique=True) class User(Base): __tablename__ = 'users' name = Column(String(32), unique=True, nullable=False) vname = Column(String(64)) email = Column(String(64), nullable=False) ha1 = Column(String(32), nullable=False) active = Column(Boolean, server_default='True') @validates('ha1') def validates_ha1(self, key, passwd): if self.name is None: raise Exception('Set the name first') pack = ':'.join([self.name, maki.constants.REALM, passwd]) return hashlib.md5(pack.encode()).hexdigest() def set_slug_in_elem(elem, newvalue, oldvalue, initiator): elem.slug = slugify(newvalue) event.listen(Tag.name, 'set', set_slug_in_elem) event.listen(Category.name, 'set', set_slug_in_elem) event.listen(Post.revisions, 'append', lambda post, revision, init: setattr(post, 'slug', slugify(revision.title)))