def buildQuery(self, session, offset=None, limit=1000, q=None): ''' @see: IArticleSearchProvider.buildQuery() ''' sql = session.query(ArticleMapped) if q: sql = buildQuery(sql, q, ArticleMapped) sql = sql.join(PersonMapped, ArticleMapped.Author == PersonMapped.Id) sql = sql.join(UserMapped, ArticleMapped.Creator == UserMapped.Id) if QArticle.search in q: all = processLike( q.search.ilike ) if q.search.ilike is not None else processLike(q.search.like) sql = sql.filter( or_(PersonMapped.FullName.like(all), UserMapped.FullName.like(all), ArticleMapped.Content.like(all))) count = sql.count() sql = buildLimits(sql, offset, limit) return (sql, count)
def getAll(self, articleId, offset=None, limit=None): ''' @see: IArticleCtxService.getAll ''' sql = self._buildQuery(articleId) sql = buildLimits(sql, offset, limit) return sql.all()
def _getAll(self, filter=None, query=None, offset=None, limit=None, sql=None): ''' Provides all the entities for the provided filter, with offset and limit. Also if query is known to the service then also a query can be provided. @param filter: SQL alchemy filtering|None The sql alchemy conditions to filter by. @param query: query The REST query object to provide filtering on. @param offset: integer|None The offset to fetch elements from. @param limit: integer|None The limit of elements to get. @param sql: SQL alchemy|None The sql alchemy query to use. @return: list The list of all filtered and limited elements. ''' if limit == 0: return [] sql = sql or self.session().query(ItemMapped) if filter is not None: sql = sql.filter(filter) if query: assert self.queryType.isValid(query), 'Invalid query %s, expected %s' % (query, QItem) sql = buildQuery(sql, query, ItemMapped) sql = buildLimits(sql, offset, limit) return sql.all()
def getAll(self, adminId, offset=None, limit=None, detailed=False, q=None): """ @see: IUserService.getAll """ if limit == 0: entities = () else: entities = None if detailed or entities is None: sql = self.session().query(UserMapped) sql = sql.filter(UserMapped.DeletedOn == None) if q: assert isinstance(q, QUser), "Invalid query %s" % q sql = buildQuery(sql, q, UserMapped) if QUser.all in q: filter = None if AsLike.like in q.all: for col in ALL_NAMES: filter = col.like(q.all.like) if filter is None else filter | col.like(q.all.like) elif AsLike.ilike in q.all: for col in ALL_NAMES: filter = col.ilike(q.all.ilike) if filter is None else filter | col.ilike(q.all.ilike) sql = sql.filter(filter) if entities is None: entities = buildLimits(sql, offset, limit).all() if detailed: return IterPart(entities, sql.count(), offset, limit) return entities
def getOwned(self, blogId, creatorId, typeId=None, thumbSize=None, offset=None, limit=None, q=None): ''' @see: IBlogPostService.getOwned ''' assert q is None or isinstance(q, QBlogPost), 'Invalid query %s' % q sql = self._buildQuery(blogId, typeId, creatorId, None, q) sql = sql.join(CollaboratorMapped, CollaboratorMapped.Id == BlogPostMapped.Author) sql = sql.join(SourceMapped, SourceMapped.Id == CollaboratorMapped.Source) sql = sql.filter(SourceMapped.Name == self.internal_source_type) if q and QBlogPost.isPublished in q: if q.isPublished.value: sql = sql.filter(BlogPostMapped.PublishedOn != None) else: sql = sql.filter(BlogPostMapped.PublishedOn == None) sql = sql.order_by(desc_op(BlogPostMapped.Order)) sql = buildLimits(sql, offset, limit) return self._addImages(sql.all(), thumbSize)
def getGroupUnpublished(self, blogId, groupId, typeId=None, authorId=None, thumbSize=None, offset=None, limit=None, q=None): ''' @see: IBlogPostService.getUnpublished ''' assert q is None or isinstance( q, QBlogPostUnpublished), 'Invalid query %s' % q updateLastAccessOn(self.session(), groupId) sql = self._buildQuery(blogId, typeId, None, authorId, q) sql = sql.filter(BlogPostMapped.PublishedOn == None) # blog collaborator group sql = sql.join( BlogCollaboratorGroupMemberMapped, BlogCollaboratorGroupMemberMapped.BlogCollaborator == BlogPostMapped.Creator) sql = sql.filter(BlogCollaboratorGroupMemberMapped.Group == groupId) sql = sql.order_by(desc_op(BlogPostMapped.Creator)) sql = sql.order_by(desc_op(BlogPostMapped.Order)) sql = buildLimits(sql, offset, limit) return self._addImages(sql.distinct())
def getAll(self, userId=None, sourceId=None, offset=None, limit=None, detailed=False, qu=None, qs=None): ''' @see: ICollaboratorService.getAll ''' sql = self.session().query(CollaboratorMapped) sql = sql.outerjoin(UserMapped).filter(UserMapped.DeletedOn == None) if userId is not None: sql = sql.filter(CollaboratorMapped.User == userId) if sourceId is not None: sql = sql.filter(CollaboratorMapped.Source == sourceId) if qu is not None: sql = buildQuery(sql.join(UserMapped), qu, UserMapped) if qs is not None: sql = buildQuery(sql.join(SourceMapped), qs, SourceMapped) sqlLimit = buildLimits(sql, offset, limit) if detailed: return IterPart(sqlLimit.all(), sql.count(), offset, limit) return sqlLimit.all()
def getMetaDatas(self, scheme, typeId=None, offset=None, limit=None, q=None, thumbSize=None): ''' @see: IMetaDataService.getMetaDatas ''' sql = self.buildSql(typeId, q) sql = buildLimits(sql, offset, limit) return (self.referencer.populate(metaData, scheme, thumbSize) for metaData in sql.all())
def getByBlog(self, blogId, offset=None, limit=None, detailed=False, q=None): ''' @see IBlogSyncService.getByBlog ''' sql = self.session().query(BlogSyncMapped) if q: assert isinstance(q, QBlogSync), 'Invalid blog sync query %s' % q sql = buildQuery(sql, q, BlogSyncMapped) sql = sql.join(SourceMapped, SourceMapped.Id == BlogSyncMapped.Source) sql = sql.join(BlogSourceDB, SourceMapped.Id == BlogSourceDB.source) sql = sql.filter(BlogSourceDB.blog == blogId) sql_prov = self.session().query(SourceMapped.URI) sql_prov = sql_prov.join(SourceTypeMapped, SourceTypeMapped.id == SourceMapped.typeId) sql_prov = sql_prov.filter( SourceTypeMapped.Key == self.blog_provider_type) sql = sql.filter(SourceMapped.OriginURI.in_(sql_prov)) sqlLimit = buildLimits(sql, offset, limit) if detailed: return IterPart(sqlLimit.all(), sql.count(), offset, limit) return sqlLimit.all()
def _getAllWithCount(self, filter=None, query=None, offset=None, limit=None, sql=None): ''' Provides all the entities for the provided filter, with offset and limit and the total count. Also if query is known to the service then also a query can be provided. @param filter: SQL alchemy filtering|None The sql alchemy conditions to filter by. @param query: query The REST query object to provide filtering on. @param offset: integer|None The offset to fetch elements from. @param limit: integer|None The limit of elements to get. @param sql: SQL alchemy|None The sql alchemy query to use. @return: tuple(list, integer) The list of all filtered and limited elements and the count of the total elements. ''' sql = sql or self.session().query(ItemMapped) if filter is not None: sql = sql.filter(filter) if query: assert self.queryType.isValid( query), 'Invalid query %s, expected %s' % (query, QItem) sql = buildQuery(sql, query, ItemMapped) sqlLimit = buildLimits(sql, offset, limit) if limit == 0: return (), sql.count() return sqlLimit.all(), sql.count()
def getMetaInfos(self, dataId=None, languageId=None, offset=None, limit=10, qi=None, qd=None): ''' @see: IMetaInfoService.getMetaInfos ''' sql = self.buildSql(dataId, languageId, qi, qd) sql = buildLimits(sql, offset, limit) return sql.all()
def getPublished(self, blogId, typeId=None, creatorId=None, authorId=None, thumbSize=None, offset=None, limit=None, detailed=False, q=None): ''' @see: IBlogPostService.getPublished ''' assert q is None or isinstance(q, QBlogPostPublished), 'Invalid query %s' % q sql = self._filterQuery(blogId, typeId, creatorId, authorId) sqlMore = None if q: if QWithCId.cId in q and q.cId: sql = sql.filter(BlogPostMapped.CId != None) # sql = sql.filter((BlogPostMapped.PublishedOn != None) | ((BlogPostMapped.CId != None) & (BlogPostMapped.DeletedOn == None))) sqlMore = buildQuery(sql, q, BlogPostMapped, exclude=QWithCId.cId) sql = buildQuery(sql, q, BlogPostMapped) if not sqlMore: sql = sql.filter((BlogPostMapped.PublishedOn != None) & (BlogPostMapped.DeletedOn == None)) sql = sql.order_by(desc_op(BlogPostMapped.Order)) sqlLimit = buildLimits(sql, offset, limit) posts = self._addImages(self._trimPosts(sqlLimit.all()), thumbSize) if detailed: posts = IterPost(posts, sql.count(), offset, limit) posts.lastCId = self.session().query(func.MAX(BlogPostMapped.CId)).filter(BlogPostMapped.Blog == blogId).scalar() if sqlMore: posts.offsetMore = sqlMore.count() else: posts.offsetMore = posts.total return posts
def getAll(self, offset=None, limit=None, detailed=False, q=None): ''' @see: IUserService.getAll ''' if limit == 0: entities = () else: entities = None if detailed or entities is None: sql = self.session().query(UserMapped) activeUsers = True if q: assert isinstance(q, QUser), 'Invalid query %s' % q sql = buildQuery(sql, q, UserMapped) if QUser.all in q: filter = None if AsLike.like in q.all: for col in ALL_NAMES: filter = col.like(q.all.like) if filter is None else filter | col.like(q.all.like) elif AsLike.ilike in q.all: for col in ALL_NAMES: filter = col.ilike(q.all.ilike) if filter is None else filter | col.ilike(q.all.ilike) sql = sql.filter(filter) if (QUser.inactive in q) and (AsBoolean.value in q.inactive): activeUsers = not q.inactive.value sql = sql.filter(UserMapped.Active == activeUsers) sql = sql.filter(UserMapped.Type == self.default_user_type_key) if entities is None: entities = buildLimits(sql, offset, limit).all() if detailed: return IterPart(entities, sql.count(), offset, limit) return entities
def getPotential(self, blogId, excludeSources=True, offset=None, limit=None, detailed=True, qu=None, qs=None): ''' @see: IBlogCollaboratorService.getPotential ''' sqlBlog = self.session().query(BlogCollaboratorMapped.Id).filter( BlogCollaboratorMapped.Blog == blogId) sql = self.session().query(CollaboratorMapped) sql = sql.join(UserMapped, CollaboratorMapped.User == UserMapped.Id) sql = sql.join(SourceMapped, SourceMapped.Id == CollaboratorMapped.Source) sql = sql.filter(not_(CollaboratorMapped.Id.in_(sqlBlog))) sql = sql.filter(UserMapped.Active == True) sql = sql.filter(UserMapped.Type == self.default_user_type_key) sql = sql.filter(SourceMapped.Name == self.internal_source_name) sql = sql.order_by(CollaboratorMapped.Name) if excludeSources: sql = sql.filter(CollaboratorMapped.User != None) if qu: sql = buildQuery(sql, qu, UserMapped) if qs: sql = buildQuery(sql, qs, SourceMapped) sqlLimit = buildLimits(sql, offset, limit) if detailed: return IterPart(sqlLimit.distinct(), sql.distinct().count(), offset, limit) return sqlLimit.distinct()
def getAll(self, offset=None, limit=None, detailed=False, q=None): ''' @see: IUserService.getAll ''' if limit == 0: entities = () else: entities = None if detailed or entities is None: sql = self.session().query(UserMapped) sql = sql.filter(UserMapped.DeletedOn == None) if q: assert isinstance(q, QUser), 'Invalid query %s' % q sql = buildQuery(sql, q, UserMapped) if QUser.all in q: filter = None if AsLike.like in q.all: for col in ALL_NAMES: filter = col.like( q.all.like ) if filter is None else filter | col.like( q.all.like) elif AsLike.ilike in q.all: for col in ALL_NAMES: filter = col.ilike( q.all.ilike ) if filter is None else filter | col.ilike( q.all.ilike) sql = sql.filter(filter) if entities is None: entities = buildLimits(sql, offset, limit).all() if detailed: return IterPart(entities, sql.count(), offset, limit) return entities
def getAll(self, typeKey=None, offset=None, limit=None, detailed=False, q=None): ''' @see: ISourceService.getAll ''' sql = self.session().query(SourceMapped) if typeKey: sql = sql.join(SourceTypeMapped).filter( SourceTypeMapped.Key == typeKey) if q: assert isinstance(q, QSource), 'Invalid source query %s' % q sql = buildQuery(sql, q, SourceMapped) if QSource.all in q: filter = None if AsLike.like in q.all: for col in ALL_NAMES: filter = col.like( q.all.like ) if filter is None else filter | col.like(q.all.like) elif AsLike.ilike in q.all: for col in ALL_NAMES: filter = col.ilike( q.all.ilike ) if filter is None else filter | col.ilike( q.all.ilike) sql = sql.filter(filter) sqlLimit = buildLimits(sql, offset, limit) if detailed: return IterPart(sqlLimit.all(), sql.count(), offset, limit) return sqlLimit.all()
def _getAll(self, filter=None, query=None, offset=None, limit=None, sqlQuery=None): """ Provides all the entities for the provided filter, with offset and limit. Also if query is known to the service then also a query can be provided. @param filter: SQL alchemy filtering|None The sql alchemy conditions to filter by. @param query: query The REST query object to provide filtering on. @param offset: integer|None The offset to fetch elements from. @param limit: integer|None The limit of elements to get. @param sqlQuery: SQL alchemy|None The sql alchemy query to use. @return: list The list of all filtered and limited elements. """ if limit == 0: return [] sqlQuery = sqlQuery or self.session().query(self.Entity) if filter is not None: sqlQuery = sqlQuery.filter(filter) if query: assert self.QEntity, "No query provided for the entity service" assert self.queryType.isValid(query), "Invalid query %s, expected %s" % (query, self.QEntity) sqlQuery = buildQuery(sqlQuery, query, self.Entity) sqlQuery = buildLimits(sqlQuery, offset, limit) return (entity for entity in sqlQuery.all())
def getPotential(self, blogId, excludeSources=True, offset=None, limit=None, detailed=True, qu=None, qs=None): ''' @see: IBlogCollaboratorService.getPotential ''' sqlBlog = self.session().query(BlogCollaboratorMapped.Id).filter( BlogCollaboratorMapped.Blog == blogId) sql = self.session().query(CollaboratorMapped).join(UserMapped).join( SourceMapped) sql = sql.filter(not_(CollaboratorMapped.Id.in_(sqlBlog))) sql = sql.filter(UserMapped.DeletedOn == None) sql = sql.order_by(CollaboratorMapped.Name) if excludeSources: sql = sql.filter(CollaboratorMapped.User != None) if qu: sql = buildQuery(sql, qu, UserMapped) if qs: sql = buildQuery(sql, qs, SourceMapped) sqlLimit = buildLimits(sql, offset, limit) if detailed: return IterPart(sqlLimit.all(), sql.count(), offset, limit) return sql.all()
def getAll(self, typeKey=None, offset=None, limit=None, detailed=False, q=None): """ @see: ISourceService.getAll """ sql = self.session().query(SourceMapped) if typeKey: sql = sql.join(SourceTypeMapped).filter(SourceTypeMapped.Key == typeKey) if q: assert isinstance(q, QSource), "Invalid source query %s" % q sql = buildQuery(sql, q, SourceMapped) if QSource.all in q: filter = None if AsLike.like in q.all: for col in ALL_NAMES: filter = col.like(q.all.like) if filter is None else filter | col.like(q.all.like) elif AsLike.ilike in q.all: for col in ALL_NAMES: filter = col.ilike(q.all.ilike) if filter is None else filter | col.ilike(q.all.ilike) sql = sql.filter(filter) # TODO: Hack to be able to get the list of the chained blog sources for a blog; # It should be removed when the new version of ally-py is used if QSource.blogId in q: sqlIn = self.session().query(BlogSourceDB.source).filter(BlogSourceDB.blog == q.blogId.equal) sql = sql.filter(SourceMapped.Id.in_(sqlIn)) sqlLimit = buildLimits(sql, offset, limit) if detailed: return IterPart(sqlLimit.all(), sql.count(), offset, limit) return sqlLimit.all()
def _getAll(self, filter=None, query=None, offset=None, limit=None, sql=None): ''' Provides all the entities for the provided filter, with offset and limit. Also if query is known to the service then also a query can be provided. @param filter: SQL alchemy filtering|None The sql alchemy conditions to filter by. @param query: query The REST query object to provide filtering on. @param offset: integer|None The offset to fetch elements from. @param limit: integer|None The limit of elements to get. @param sql: SQL alchemy|None The sql alchemy query to use. @return: list The list of all filtered and limited elements. ''' if limit == 0: return [] sql = sql or self.session().query(self.Entity) if filter is not None: sql = sql.filter(filter) if query: assert self.QEntity, 'No query provided for the entity service' assert self.queryType.isValid( query), 'Invalid query %s, expected %s' % (query, self.QEntity) sql = buildQuery(sql, query, self.Entity) sql = buildLimits(sql, offset, limit) return sql.all()
def getChainedPosts(self, blogId, sourceTypeKey, offset=None, limit=None, detailed=False, q=None): ''' @see: IBlogSourceService.getChainedPosts ''' sql = self.session().query(PostMapped) sql = sql.join(CollaboratorMapped).join(SourceMapped).join( SourceTypeMapped) sql = sql.filter(SourceTypeMapped.Key == sourceTypeKey) sql = sql.join(BlogSourceDB, SourceMapped.Id == BlogSourceDB.source).filter( BlogMapped.Id == blogId) if q: assert isinstance(q, QPostWithPublished), 'Invalid query %s' % q sql = buildQuery(sql, q, PostMapped) if q and QPostWithPublished.isPublished in q: if q.isPublished.value: sql = sql.filter(PostMapped.PublishedOn != None) else: sql = sql.filter(PostMapped.PublishedOn == None) sqlLimit = buildLimits(sql, offset, limit) if detailed: return IterPart(sqlLimit.all(), sql.count(), offset, limit) return sqlLimit.all()
def _getAllWithCount(self, filter=None, query=None, offset=None, limit=None, sql=None): ''' Provides all the entities for the provided filter, with offset and limit and the total count. Also if query is known to the service then also a query can be provided. @param filter: SQL alchemy filtering|None The sql alchemy conditions to filter by. @param query: query The REST query object to provide filtering on. @param offset: integer|None The offset to fetch elements from. @param limit: integer|None The limit of elements to get. @param sql: SQL alchemy|None The sql alchemy query to use. @return: tuple(list, integer) The list of all filtered and limited elements and the count of the total elements. ''' sql = sql or self.session().query(self.Entity) if filter is not None: sql = sql.filter(filter) if query: assert self.QEntity, 'No query provided for the entity service' assert self.queryType.isValid(query), 'Invalid query %s, expected %s' % (query, self.QEntity) sql = buildQuery(sql, query, self.Entity) sqlLimit = buildLimits(sql, offset, limit) if limit == 0: return (), sql.count() return sqlLimit.all(), sql.count()
def getRights(self, userId, typeId=None, offset=None, limit=None, detailed=False, q=None): ''' @see: IUserRbacService.getRights ''' if limit == 0: entities = () else: entities = None if detailed or entities is None: rbacId = self.rbacIdFor(userId) if not rbacId: return IterPart((), 0, offset, limit) if detailed else () sql = self.rbacService.rightsForRbacSQL(rbacId) if typeId: sql = sql.filter(RightMapped.Type == typeId) if q: assert isinstance(q, QRight), 'Invalid query %s' % q sql = buildQuery(sql, q, RightMapped) if entities is None: entities = buildLimits(sql, offset, limit).all() if detailed: return IterPart(entities, sql.count(), offset, limit) return entities
def getAll(self, languageId=None, userId=None, offset=None, limit=None, detailed=False, q=None): ''' @see: IBlogService.getAll ''' sql = self._buildQuery(languageId, userId, q) sqlLimit = buildLimits(sql, offset, limit) if detailed: return IterPart(sqlLimit.all(), sql.count(), offset, limit) return sqlLimit.all()
def getAll(self, creatorId=None, authorId=None, offset=None, limit=None, detailed=False, q=None): ''' @see: IPostService.getPublished ''' assert q is None or isinstance(q, QPost), 'Invalid query %s' % q sql = self._buildQuery(creatorId, authorId, q) sqlLimit = buildLimits(sql, offset, limit) if detailed: return IterPart(sqlLimit.all(), sql.count(), offset, limit) return sqlLimit.all()
def getUnpublishedBySource(self, sourceId, thumbSize=None, offset=None, limit=None, detailed=False, q=None): ''' @see: IBlogPostService.getUnpublished ''' assert q is None or isinstance(q, QBlogPostUnpublished), 'Invalid query %s' % q postVerification = aliased(PostVerificationMapped, name='post_verification_filter') sql = self.session().query(BlogPostMapped) sql = sql.filter(BlogPostMapped.Feed == sourceId) deleted = False if q: if QBlogPostUnpublished.isDeleted in q: deleted = q.isDeleted.value sql = buildQuery(sql, q, BlogPostMapped) if q: if QWithCId.search in q: all = self._processLike(q.search.ilike) if q.search.ilike is not None else self._processLike(q.search.like) sql = sql.filter(or_(BlogPostMapped.Meta.ilike(all), BlogPostMapped.CreatedOn.ilike(all), \ BlogPostMapped.Content.ilike(all), BlogPostMapped.ContentPlain.ilike(all), \ )) if QWithCId.status in q or QWithCId.checker in q: sql = sql.join(postVerification, postVerification.Id == BlogPostMapped.Id) sql = sql.join(VerificationStatusMapped, VerificationStatusMapped.id == postVerification.statusId) if QWithCId.status in q: sql = sql.filter(VerificationStatusMapped.Key == q.status.equal) if QWithCId.checker in q: sql = sql.filter(postVerification.Checker == q.checker.equal) if (QWithCId.cId not in q) or (QWithCId.cId in q and QWithCId.cId.start not in q \ and QWithCId.cId.end not in q and QWithCId.cId.since not in q and QWithCId.cId.until not in q): sql = sql.filter(BlogPostMapped.PublishedOn == None) if deleted: sql = sql.filter(BlogPostMapped.DeletedOn != None) else: sql = sql.filter(BlogPostMapped.DeletedOn == None) else: sql = sql.filter((BlogPostMapped.PublishedOn == None) & (BlogPostMapped.DeletedOn == None)) sql = sql.order_by(desc_op(BlogPostMapped.Order)) sqlLimit = buildLimits(sql, offset, limit) posts = self._addImages(self._trimPosts(sqlLimit.distinct(), deleted= not deleted, unpublished=False, published=True), thumbSize) if detailed: posts = IterPost(posts, sql.distinct().count(), offset, limit) lastCidSql = self.session().query(func.MAX(BlogPostMapped.CId)) lastCidSql = lastCidSql.join(CollaboratorMapped, BlogPostMapped.Creator == CollaboratorMapped.User) lastCidSql = lastCidSql.filter(CollaboratorMapped.Source == sourceId) posts.lastCId = lastCidSql.scalar() return posts
def getAll(self, blogId, typeId=None, creatorId=None, authorId=None, offset=None, limit=None, q=None): ''' @see: IBlogPostService.getAll ''' assert q is None or isinstance(q, QBlogPost), 'Invalid query %s' % q sql = self._buildQuery(blogId, typeId, creatorId, authorId, q) sql = sql.order_by(desc_op(BlogPostMapped.Order)) sql = buildLimits(sql, offset, limit) return self._trimmDeleted(sql.all())
def getAll(self, blogTypeId, typeId=None, offset=None, limit=None, q=None): ''' @see: IBlogPostService.getAll ''' assert q is None or isinstance(q, QBlogTypePost), 'Invalid query %s' % q sql = self._buildQuery(blogTypeId, typeId, q) sql = sql.order_by(desc_op(BlogTypePostMapped.Order)) sql = buildLimits(sql, offset, limit) return self._trimmDeleted(sql.all())
def getPluginMessages(self, plugin, offset=None, limit=None, detailed=False, qm=None, qs=None): ''' @see: IMessageService.getPluginMessages ''' sql = self.session().query(Message).join(Source).filter(Source.Plugin == plugin) if qm: sql = buildQuery(sql, qm, Message) if qs: sql = buildQuery(sql, qs, Source) sqlLimit = buildLimits(sql, offset, limit) if detailed: return IterPart(sqlLimit.all(), sql.count(), offset, limit) return sqlLimit.all()
def getAll(self, blogId, typeId=None, creatorId=None, authorId=None, thumbSize=None, offset=None, limit=None, q=None): ''' @see: IBlogPostService.getAll ''' assert q is None or isinstance(q, QBlogPost), 'Invalid query %s' % q sql = self._buildQuery(blogId, typeId, creatorId, authorId, q) sql = sql.order_by(desc_op(BlogPostMapped.Order)) sql = buildLimits(sql, offset, limit) return self._addImages(sql.all(), thumbSize)
def getAll(self, blogId, offset=None, limit=None, detailed=True): ''' @see: IBlogCollaboratorService.getAll ''' sql = self.session().query(BlogCollaboratorMapped).filter(BlogCollaboratorMapped.Blog == blogId) sql = sql.join(UserMapped).join(SourceMapped).order_by(BlogCollaboratorMapped.Name) sql = sql.filter(UserMapped.Active == True) sqlLimit = buildLimits(sql, offset, limit) if detailed: return IterPart(sqlLimit.all(), sql.count(), offset, limit) return sqlLimit.all()
def getAll(self, typeKey=None, offset=None, limit=None, detailed=False, q=None): ''' @see: ISourceService.getAll ''' sql = self.session().query(SourceMapped) if typeKey: sql = sql.join(SourceTypeMapped).filter(SourceTypeMapped.Key == typeKey) if q: sql = buildQuery(sql, q, SourceMapped) sqlLimit = buildLimits(sql, offset, limit) if detailed: return IterPart(sqlLimit.all(), sql.count(), offset, limit) return sqlLimit.all()
def getMetaInfos(self, scheme, offset=None, limit=None, qi=None, qd=None, thumbSize=None): ''' Provides the meta data based on unified multi-plugin criteria. ''' sql = self.session().query(MetaInfoMapped) if qi is not None: assert isinstance(qi, self.QMetaInfo), 'Invalid query %s' % qi metaInfos = self.queryIndexer.metaInfos.copy() assert isinstance(metaInfos, set) for name in namesForQuery(qi): if getattr(self.QMetaInfo, name) not in qi: continue criteriaMetaInfos = self.queryIndexer.metaInfoByCriteria.get( name) assert criteriaMetaInfos, 'No model class available for %s' % name metaInfos.intersection(criteriaMetaInfos) sql = buildQuery(sql, qi, MetaInfoMapped) for metaInfo in metaInfos: sql = sql.join(metaInfo) try: sql = buildQuery(sql, qi, metaInfo) except: raise Exception('Cannot build query for meta info %s' % metaInfo) if qd is not None: assert isinstance(qd, self.QMetaData), 'Invalid query %s' % qd metaDatas = self.queryIndexer.metaDatas.copy() assert isinstance(metaDatas, set) for name in namesForQuery(qd): if getattr(self.QMetaData, name) not in qd: continue criteriaMetaDatas = self.queryIndexer.metaDataByCriteria.get( name) assert criteriaMetaDatas, 'No model class available for %s' % name metaDatas.intersection(criteriaMetaDatas) sql = sql.join(MetaDataMapped) sql = buildQuery(sql, qd, MetaDataMapped) for metaData in metaDatas: sql = sql.join(metaData) sql = buildQuery(sql, qd, metaData) sql = buildLimits(sql, offset, limit) return sql.all()
def getMessages(self, sourceId=None, offset=None, limit=None, detailed=False, qm=None, qs=None): ''' @see: IMessageService.getMessages ''' sql = self.session().query(Message) if sourceId: sql = sql.filter(Message.Source == sourceId) if qm: sql = buildQuery(sql, qm, Message) if qs: sql = buildQuery(sql.join(Source), qs, Source) sqlLimit = buildLimits(sql, offset, limit) if detailed: return IterPart(sqlLimit.all(), sql.count(), offset, limit) return sqlLimit.all()
def getUnpublished(self, blogId, typeId=None, creatorId=None, authorId=None, offset=None, limit=None, q=None): ''' @see: IBlogPostService.getUnpublished ''' assert q is None or isinstance(q, QBlogPostUnpublished), 'Invalid query %s' % q sql = self._buildQuery(blogId, typeId, creatorId, authorId, q) sql = sql.filter(BlogPostMapped.PublishedOn == None) sql = sql.order_by(desc_op(BlogPostMapped.Order)) sql = buildLimits(sql, offset, limit) return self._trimmDeleted(sql.all())
def getAll(self, personId=None, sourceId=None, offset=None, limit=None, detailed=False, qp=None, qs=None): ''' @see: ICollaboratorService.getAll ''' sql = self.session().query(CollaboratorMapped) if personId: sql = sql.filter(CollaboratorMapped.Person == personId) if sourceId: sql = sql.filter(CollaboratorMapped.Source == sourceId) if qp: sql = buildQuery(sql.join(PersonMapped), qp, PersonMapped) if qs: sql = buildQuery(sql.join(SourceMapped), qs, SourceMapped) sqlLimit = buildLimits(sql, offset, limit) if detailed: return IterPart(sqlLimit.all(), sql.count(), offset, limit) return sqlLimit.all()
def getAllBySourceType(self, sourceTypeKey, offset=None, limit=None, detailed=False, q=None): ''' @see: IPostService.getAllBySourceType ''' assert q is None or isinstance(q, QPost), 'Invalid query %s' % q sql = self._buildQueryBySourceType(sourceTypeKey) sql = self._buildQueryWithCId(q, sql) sqlLimit = buildLimits(sql, offset, limit) if detailed: return IterPart(sqlLimit.all(), sql.count(), offset, limit) return sqlLimit.all()
def getPublished(self, creatorId=None, authorId=None, offset=None, limit=None, detailed=False, q=None): """ @see: IPostService.getPublished """ assert q is None or isinstance(q, QPost), "Invalid query %s" % q sql = self._buildQuery(creatorId, authorId, q) sql = sql.filter(PostMapped.PublishedOn != None) sqlLimit = buildLimits(sql, offset, limit) if detailed: return IterPart(sqlLimit.all(), sql.count(), offset, limit) return sqlLimit.all()
def getAll(self, userId=None, sourceId=None, offset=None, limit=None, detailed=False, qu=None, qs=None): ''' @see: ICollaboratorService.getAll ''' sql = self.session().query(CollaboratorMapped) if userId: sql = sql.filter(CollaboratorMapped.User == userId) sql = sql.filter(UserMapped.DeletedOn == None) if sourceId: sql = sql.filter(CollaboratorMapped.Source == sourceId) if qu: sql = buildQuery(sql.join(UserMapped), qu, UserMapped) if qs: sql = buildQuery(sql.join(SourceMapped), qs, SourceMapped) sqlLimit = buildLimits(sql, offset, limit) if detailed: return IterPart(sqlLimit.all(), sql.count(), offset, limit) return sqlLimit.all()
def getPublishedBySource(self, sourceId, offset=None, limit=None, detailed=False, q=None): ''' @see: IPostService.getPublishedBySource ''' assert q is None or isinstance(q, QPostPublished), 'Invalid query %s' % q sql = self._buildQueryBySource(sourceId) sql = sql.filter(PostMapped.PublishedOn != None) sql = self._buildQueryWithCId(q, sql) sqlLimit = buildLimits(sql, offset, limit) if detailed: return IterPart(sqlLimit.all(), sql.count(), offset, limit) return sqlLimit.all()
def getComponentMessages(self, component, offset=None, limit=None, detailed=False, qm=None, qs=None): """ @see: IMessageService.getComponentMessages """ sql = self.session().query(Message).join(Source).filter(Source.Component == component) if qm: sql = buildQuery(sql, qm, Message) if qs: sql = buildQuery(sql, qs, Source) sqlLimit = buildLimits(sql, offset, limit) if detailed: return IterPart(sqlLimit.all(), sql.count(), offset, limit) return sqlLimit.all()
def getOwned(self, blogId, creatorId, typeId=None, thumbSize=None, offset=None, limit=None, q=None): ''' @see: IBlogPostService.getOwned ''' assert q is None or isinstance(q, QBlogPost), 'Invalid query %s' % q sql = self._buildQuery(blogId, typeId, creatorId, None, q) if q and QBlogPost.isPublished in q: if q.isPublished.value: sql = sql.filter(BlogPostMapped.PublishedOn != None) else: sql = sql.filter(BlogPostMapped.PublishedOn == None) sql = sql.order_by(desc_op(BlogPostMapped.Order)) sql = buildLimits(sql, offset, limit) return self._addImages(sql.all(), thumbSize)
def buildQuery(self, session, scheme, offset=None, limit=1000, q=None): ''' @see: IArticleSearchProvider.buildQuery() Creates the solr query, executes the query against Solr server. Then build a SQL query that will return the Solr founded data. ''' sql = session.query(Article) if q: sql = buildQuery(sql, q, self.Entity) sql = buildLimits(sql, offset, limit)
def getAll(self, blogId, typeKey=None, offset=None, limit=None, detailed=False): ''' @see: IBlogMediaService.getAll ''' sql = self.session().query(BlogMediaMapped) sql = sql.filter(BlogMediaMapped.Blog == blogId) if typeKey: sql = sql.join(BlogMediaTypeMapped).filter(BlogMediaMapped.Key == typeKey) sql = sql.order_by(BlogMediaMapped.Id) sqlLimit = buildLimits(sql, offset, limit) if detailed: return IterPart(sqlLimit.all(), sql.count(), offset, limit) return sqlLimit.all()
def getPublished(self, blogId, typeId=None, creatorId=None, authorId=None, offset=None, limit=None, detailed=False, q=None): ''' @see: IBlogPostService.getPublished ''' assert q is None or isinstance(q, QBlogPostPublished), 'Invalid query %s' % q sql = self._buildQuery(blogId, typeId, creatorId, authorId, q) sql = sql.filter(BlogPostMapped.PublishedOn != None) sql = sql.order_by(BlogPostMapped.PublishedOn.desc()) sqlLimit = buildLimits(sql, offset, limit) if detailed: return IterPart(sqlLimit.all(), sql.count(), offset, limit) return sqlLimit.all()
def getPublished(self, blogId, typeId=None, creatorId=None, authorId=None, offset=None, limit=None, detailed=False, q=None): ''' @see: IBlogPostService.getPublished ''' assert q is None or isinstance(q, QBlogPostPublished), 'Invalid query %s' % q sql = self._buildQuery(blogId, typeId, creatorId, authorId, q) sql = sql.filter(BlogPostMapped.PublishedOn != None) sql = sql.order_by(desc_op(BlogPostMapped.Order)) sqlLimit = buildLimits(sql, offset, limit) if detailed: return IterPart(sqlLimit.all(), sql.count(), offset, limit) return self._trimmDeleted(sqlLimit.all())
def getOwned(self, blogId, creatorId, typeId=None, offset=None, limit=None, q=None): ''' @see: IBlogPostService.getOwned ''' assert q is None or isinstance(q, QBlogPost), 'Invalid query %s' % q sql = self._buildQuery(blogId, typeId, creatorId, None, q) if q and QBlogPost.isPublished in q: if q.isPublished.value: sql = sql.filter(BlogPostMapped.PublishedOn != None) else: sql = sql.filter(BlogPostMapped.PublishedOn == None) #sql = sql.filter(BlogPostMapped.Author == None) sql = sql.order_by(desc_op(BlogPostMapped.Order)) sql = buildLimits(sql, offset, limit) return self._trimmDeleted(sql.all())
def getPluginMessages(self, plugin, offset=None, limit=None, detailed=False, qm=None, qs=None): ''' @see: IMessageService.getPluginMessages ''' sql = self.session().query(Message).join(Source).filter( Source.Plugin == plugin) if qm: sql = buildQuery(sql, qm, Message) if qs: sql = buildQuery(sql, qs, Source) sqlLimit = buildLimits(sql, offset, limit) if detailed: return IterPart(sqlLimit.all(), sql.count(), offset, limit) return sqlLimit.all()
def getPublished(self, blogId, typeId=None, creatorId=None, authorId=None, thumbSize=None, offset=None, limit=None, detailed=False, q=None): ''' @see: IBlogPostService.getPublished ''' assert q is None or isinstance( q, QBlogPostPublished), 'Invalid query %s' % q sql = self._filterQuery(blogId, typeId, creatorId, authorId, q) sqlMore = None if q: if QWithCId.cId in q and q.cId: sql = sql.filter(BlogPostMapped.CId != None) # sql = sql.filter((BlogPostMapped.PublishedOn != None) | ((BlogPostMapped.CId != None) & (BlogPostMapped.DeletedOn == None))) sqlMore = buildQuery(sql, q, BlogPostMapped, exclude=QWithCId.cId) sql = buildQuery(sql, q, BlogPostMapped) if not sqlMore: sql = sql.filter((BlogPostMapped.PublishedOn != None) & (BlogPostMapped.DeletedOn == None)) sql = sql.order_by(desc_op(BlogPostMapped.Order)) sqlLimit = buildLimits(sql, offset, limit) posts = self._addImages(self._trimPosts(sqlLimit.all()), thumbSize) if detailed: posts = IterPost(posts, sql.count(), offset, limit) posts.lastCId = self.session().query(func.MAX( BlogPostMapped.CId)).filter( BlogPostMapped.Blog == blogId).scalar() if sqlMore: posts.offsetMore = sqlMore.count() else: posts.offsetMore = posts.total return posts
def getAll(self, typeKey=None, offset=None, limit=None, detailed=False, q=None): ''' @see: ISourceService.getAll ''' sql = self.session().query(SourceMapped) if typeKey: sql = sql.join(SourceTypeMapped).filter( SourceTypeMapped.Key == typeKey) if q: assert isinstance(q, QSource), 'Invalid source query %s' % q sql = buildQuery(sql, q, SourceMapped) if QSource.all in q: filter = None if AsLike.like in q.all: for col in ALL_NAMES: filter = col.like( q.all.like ) if filter is None else filter | col.like(q.all.like) elif AsLike.ilike in q.all: for col in ALL_NAMES: filter = col.ilike( q.all.ilike ) if filter is None else filter | col.ilike( q.all.ilike) sql = sql.filter(filter) #TODO: Hack to be able to get the list of the chained blog sources for a blog; #It should be removed when the new version of ally-py is used if QSource.blogId in q: sqlIn = self.session().query(BlogSourceDB.source).filter( BlogSourceDB.blog == q.blogId.equal) sql = sql.filter(SourceMapped.Id.in_(sqlIn)) sqlLimit = buildLimits(sql, offset, limit) if detailed: return IterPart(sqlLimit.all(), sql.count(), offset, limit) return sqlLimit.all()