def update(self, article): ''' Implementation of @see: IArticleService.update ''' assert isinstance(article, Article) origArt = super().getById(article.Id) assert isinstance(origArt, Article) article.Item = origArt.Item article.PublishedOn = origArt.PublishedOn # update the article content super().update(article) # update the item content item = self.itemService.getById(article.Item) assert isinstance(item, Item) rawContent = json.loads(article.Content) item.HeadLine = rawContent['Title'] item.SlugLine = '-'.join(item.HeadLine.split()) item.Version += 1 self.itemService.update(item) q = QItemContent() q.item = article.Item contents = self.itemContentService.getAll(q=q) for c in contents: assert isinstance(c, ItemContent) if rawContent.get(c.ResidRef): c.Content = rawContent[c.ResidRef] self.itemContentService.update(c) # if article was published republish the changes if article.PublishedOn is not None: self.contentPublisherService.publish(article.Item) self.articleSearchProvider.update(article)
def publish(self, guid): ''' Implementation for @see: IContentPublisherService.publish ''' # Test add document myItem = self.itemService.getById(guid) assert isinstance(myItem, PackageItem) item = Item() item.guid = myItem.GUId item.version = myItem.Version item.itemClass = myItem.ItemClass item.urgency = myItem.Urgency item.headline = myItem.HeadLine item.slugline = myItem.SlugLine item.byline = myItem.Byline item.creditline = myItem.CreditLine item.firstCreated = myItem.FirstCreated item.versionCreated = myItem.VersionCreated q = QItemContent() q.item = myItem.GUId contents = self.itemContentService.getAll(q=q) for c in contents: assert isinstance(c, ItemContent) content = Content() content.contenttype = c.ContentType content.content = c.Content content.residRef = c.ResidRef content.href = c.HRef content.size = c.Size content.rendition = c.Rendition item.contents.append(content) self.unpublish(item.guid) item.save(safe=True) return True