def insert(self, post): ''' @see: IPostService.insert ''' assert isinstance(post, Post), 'Invalid post %s' % post postDb = PostMapped() copy(post, postDb, exclude=COPY_EXCLUDE) postDb.typeId = self._typeId(post.Type) postDb = self._adjustTexts(postDb) if post.CreatedOn is None: postDb.CreatedOn = current_timestamp() if not postDb.Author: colls = self.session().query(CollaboratorMapped).filter( CollaboratorMapped.User == postDb.Creator).all() if not colls: coll = CollaboratorMapped() coll.User = postDb.Creator src = self.session().query(SourceMapped).filter( SourceMapped.Name == PostServiceAlchemy.default_source_name).one() coll.Source = src.Id self.session().add(coll) self.session().flush((coll, )) colls = (coll, ) postDb.Author = colls[0].Id self.session().add(postDb) self.session().flush((postDb, )) post.Id = postDb.Id return post.Id
def insert(self, post): ''' @see: IPostService.insert ''' assert isinstance(post, Post), 'Invalid post %s' % post postDb = PostMapped() copy(post, postDb, exclude=COPY_EXCLUDE) postDb.typeId = self._typeId(post.Type) # TODO: implement the proper fix using SQLAlchemy compilation rules nohigh = {i: None for i in range(0x10000, 0x110000)} if postDb.Meta: postDb.Meta = postDb.Meta.translate(nohigh) if postDb.Content: postDb.Content = postDb.Content.translate(nohigh) if postDb.ContentPlain: postDb.ContentPlain = postDb.ContentPlain.translate(nohigh) if post.CreatedOn is None: postDb.CreatedOn = current_timestamp() if not postDb.Author: colls = self.session().query(CollaboratorMapped).filter( CollaboratorMapped.User == postDb.Creator).all() if not colls: coll = CollaboratorMapped() coll.User = postDb.Creator src = self.session().query(SourceMapped).filter( SourceMapped.Name == PostServiceAlchemy.default_source_name).one() coll.Source = src.Id self.session().add(coll) self.session().flush((coll, )) colls = (coll, ) postDb.Author = colls[0].Id self.session().add(postDb) self.session().flush((postDb, )) post.Id = postDb.Id return post.Id