Beispiel #1
0
    def addSource(self, blogId, source):
        '''
        @see: IBlogSourceService.addSource
        '''
        assert isinstance(blogId, int), 'Invalid blog identifier %s' % blogId
        assert isinstance(source, Source), 'Invalid source %s' % source

        # insert source if it didn't exist yet for the given blog
        sql = self.session().query(SourceMapped)
        sql = sql.join(BlogSyncMapped, SourceMapped.Id == BlogSyncMapped.Source)
        sql = sql.filter(BlogSyncMapped.Blog == blogId)
        sql = sql.filter(and_(SourceMapped.Name == source.Name, SourceMapped.URI == source.URI))
        
        try:
            sourceId = source.Id = sql.one().Id
            self.sourceService.update(source)
        except NoResultFound:
            sourceId = self.sourceService.insert(source)    
           
            blogSync = BlogSyncMapped()
            blogSync.Blog = blogId
            blogSync.Source = sourceId
            blogSync.CId = 0
            blogSync.Auto = False
            self.blogSyncService.insert(blogSync)  
                  
        ent = BlogSourceDB()
        ent.blog = blogId
        ent.source = sourceId
        try:
            self.session().add(ent)
            self.session().flush((ent,))
        except SQLAlchemyError:
            raise InputError(Ref(_('Cannot add blog-source link.'),))
        return sourceId
Beispiel #2
0
    def addSource(self, blogId, source):
        '''
        @see: IBlogSourceService.addSource
        NB: The source must have the correct type set in.
            This way, we can reuse it for other purposes, apart from the chained blogs.
        '''
        assert isinstance(blogId, int), 'Invalid blog identifier %s' % blogId
        assert isinstance(source, Source), 'Invalid source %s' % source

        # insert source if it didn't exist yet
        q = QSource(name=source.Name, uri=source.URI)
        sources = self.sourceService.getAll(typeKey=source.Type, q=q)
        if not sources: sourceId = self.sourceService.insert(source)
        else:
            source.Id = sourceId = sources[0].Id
            self.sourceService.update(source)

        ent = BlogSourceDB()
        ent.blog = blogId
        ent.source = sourceId
        try:
            self.session().add(ent)
            self.session().flush((ent,))
        except SQLAlchemyError:
            raise InputError(Ref(_('Cannot add blog-source link.'),))
        return sourceId
Beispiel #3
0
    def addSource(self, blogId, source):
        '''
        @see: IBlogSourceService.addSource
        '''
        assert isinstance(blogId, int), 'Invalid blog identifier %s' % blogId
        assert isinstance(source, Source), 'Invalid source %s' % source

        # insert source if it didn't exist yet for the given blog
        sql = self.session().query(SourceMapped)
        sql = sql.join(BlogSyncMapped,
                       SourceMapped.Id == BlogSyncMapped.Source)
        sql = sql.filter(BlogSyncMapped.Blog == blogId)
        sql = sql.filter(
            and_(SourceMapped.Name == source.Name,
                 SourceMapped.URI == source.URI))

        try:
            sourceId = source.Id = sql.one().Id
            self.sourceService.update(source)
        except NoResultFound:
            sourceId = self.sourceService.insert(source)

            blogSync = BlogSyncMapped()
            blogSync.Blog = blogId
            blogSync.Source = sourceId
            blogSync.CId = 0
            blogSync.Auto = False
            self.blogSyncService.insert(blogSync)

        ent = BlogSourceDB()
        ent.blog = blogId
        ent.source = sourceId
        try:
            self.session().add(ent)
            self.session().flush((ent, ))
        except SQLAlchemyError:
            raise InputError(Ref(_('Cannot add blog-source link.'), ))
        return sourceId
Beispiel #4
0
    def addSource(self, blogId, source):
        '''
        @see: IBlogSourceService.addSource
        NB: The source must have the correct type set in.
            This way, we can reuse it for other purposes, apart from the chained blogs.
        '''
        assert isinstance(blogId, int), 'Invalid blog identifier %s' % blogId
        assert isinstance(source, Source), 'Invalid source %s' % source

        # insert source if it didn't exist yet
        q = QSource(name=source.Name)
        sources = self.sourceService.getAll(typeKey=source.Type, q=q)
        if not sources: sourceId = self.sourceService.insert(source)
        else: sourceId = sources[0].Id

        ent = BlogSourceDB()
        ent.blog = blogId
        ent.source = sourceId
        try:
            self.session().add(ent)
            self.session().flush((ent, ))
        except SQLAlchemyError as e:
            handle(e, ent)
        return sourceId