コード例 #1
0
ファイル: blog_post.py プロジェクト: gizm0bill/Superdesk
    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
コード例 #2
0
ファイル: blog_post.py プロジェクト: robchrstr/Superdesk
    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
コード例 #3
0
ファイル: blog_post.py プロジェクト: robchrstr/Superdesk
    def getUnpublished(self, blogId, typeId=None, creatorId=None, authorId=None, 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._filterQuery(blogId, typeId, creatorId, authorId, q)

        deleted = False
        if q:
            if QBlogPostUnpublished.isDeleted in q:
                deleted = q.isDeleted.value  
                
            if QWithCId.cId in q and q.cId:
                sql = sql.filter(BlogPostMapped.CId != None)
            sql = buildQuery(sql, q, BlogPostMapped)
            
            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:
                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(), unpublished=False, published=True), thumbSize)
        if detailed:
            posts = IterPost(posts, sql.distinct().count(), offset, limit)
            posts.lastCId = self.session().query(func.MAX(BlogPostMapped.CId)).filter(BlogPostMapped.Blog == blogId).scalar()
        return posts
コード例 #4
0
    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
コード例 #5
0
ファイル: comment.py プロジェクト: patriciagarcia/Live-Blog
 def getComments(self, blogId, offset=None, limit=None, detailed=False, q=None):
     '''
     @see: IBlogCommentService.getComments
     '''
     sql = self.session().query(BlogPostMapped).filter(BlogPostMapped.Blog == blogId)
     sql = sql.join(CollaboratorMapped).join(SourceMapped).join(SourceTypeMapped)
     sql = sql.filter(SourceTypeMapped.Key == self.source_type_key)
     
     deleted = False
     if q:
         assert isinstance(q, QBlogPostUnpublished), 'Invalid query %s' % q
         if QBlogPostUnpublished.isDeleted in q:
             deleted = q.isDeleted.value                
         sql = buildQuery(sql, q, BlogPostMapped)
         
     if q:
         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))
         
     sqlLimit = buildLimits(sql, offset, limit)
     posts = self._trimPosts(sqlLimit.all(), deleted= not deleted, unpublished=False, published=True)
     if detailed:
         posts = IterPost(posts, sql.count(), offset, limit)
         
         lastCidSql = self.session().query(func.MAX(BlogPostMapped.CId))
         lastCidSql = lastCidSql.join(CollaboratorMapped, BlogPostMapped.Author == CollaboratorMapped.Id)
         lastCidSql = lastCidSql.join(SourceMapped).join(SourceTypeMapped)
         lastCidSql = lastCidSql.filter(SourceTypeMapped.Key == self.source_type_key)
         
         posts.lastCId = lastCidSql.scalar()
         
     return posts
コード例 #6
0
    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

        postVerification = aliased(PostVerificationMapped,
                                   name='post_verification_filter')

        sinceLastCId = 0
        sql = self._filterQuery(blogId, typeId, creatorId, authorId, q)

        if q:
            if QWithCId.cId in q and q.cId:
                sql = sql.filter(BlogPostMapped.CId != None)
                sinceLastCId = q.cId.since
            sql = buildQuery(sql, q, BlogPostMapped)

            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 q is None or QWithCId.cId not in q:
            sql = sql.filter((BlogPostMapped.PublishedOn != None)
                             & (BlogPostMapped.DeletedOn == None))

        #filter updates that were not published yet
        sql = sql.filter(BlogPostMapped.WasPublished == True)

        sql = sql.order_by(desc_op(BlogPostMapped.Order))

        sqlLimit = buildLimits(sql, offset, limit)
        posts = self._addImages(self._trimPosts(sqlLimit.distinct()),
                                thumbSize)
        if detailed:
            posts = IterPost(posts, sql.distinct().count(), offset, limit)
            posts.lastCId = self.session().query(func.MAX(
                BlogPostMapped.CId)).filter(
                    BlogPostMapped.Blog == blogId).scalar()
            posts.sinceLastCId = sinceLastCId
        return posts
コード例 #7
0
    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