示例#1
0
    def mt_setPostCategories(self, postid, user, password, categories):
        # Sometimes we receive only id from categories, e.g. from Windows
        # Live Writer, so we must query for the names.
        if categories and 'categoryName' not in categories[0]:
            categories_ids = [
                ObjectId(category.get('categoryId'))
                for category in categories]

            cursor = self.settings['db'].categories.find(
                {"_id": {'$in': categories_ids}}, fields=["name"])

            categories = []
            while (yield cursor.fetch_next):
                category = cursor.next_object()
                categories.append(dict(
                    categoryId=category['_id'],
                    categoryName=category['name']))

        embedded_cats = [
            EmbeddedCategory.from_metaweblog(cat).to_python()
            for cat in categories]

        result = yield self.settings['db'].posts.update(
            {'_id': ObjectId(postid)},
            {'$set': {'categories': embedded_cats}})

        if result['n'] != 1:
            self.result(xmlrpclib.Fault(404, 'Not found'))
        else:
            self.result('')
示例#2
0
    def mt_setPostCategories(self, postid, user, password, categories):
        embedded_cats = [
            EmbeddedCategory.from_metaweblog(cat).to_python()
            for cat in categories]

        result = yield motor.Op(self.settings['db'].posts.update,
            {'_id': ObjectId(postid)},
            {'$set': {'categories': embedded_cats}})

        if result['n'] != 1:
            self.result(xmlrpclib.Fault(404, 'Not found'))
        else:
            self.result('')
示例#3
0
    def mt_setPostCategories(self, postid, user, password, categories):
        embedded_cats = [
            EmbeddedCategory.from_metaweblog(cat).to_python()
            for cat in categories]

        def set_post_categories(result, error):
            if error:
                raise error

            self.result(result['n'] == 1)

        self.settings['db'].posts.update(
            {'_id': ObjectId(postid)},
            {'$set': {'categories': embedded_cats}},
            callback=set_post_categories
        )
示例#4
0
    def mt_setPostCategories(self, postid, user, password, categories):
        embedded_cats = [
            EmbeddedCategory.from_metaweblog(cat).to_python()
            for cat in categories]

        def set_post_categories(result, error):
            if error:
                self.result(xmlrpclib.Fault(500, str(error)))
            elif result['n'] != 1:
                self.result(xmlrpclib.Fault(404, 'Not found'))
            else:
                self.result('')

        self.settings['db'].posts.update(
            {'_id': ObjectId(postid)},
            {'$set': {'categories': embedded_cats}},
            callback=set_post_categories
        )
示例#5
0
    def mt_setPostCategories(self, postid, user, password, categories):
        # Sometimes we receive only id from categories, e.g. from Windows
        # Live Writer, so we must query for the names.
        if categories and 'categoryName' not in categories[0]:
            categories_ids = [
                ObjectId(category.get('categoryId')) for category in categories
            ]

            cursor = self.settings['db'].categories.find(
                {"_id": {
                    '$in': categories_ids
                }}, fields=["name"])

            categories = []
            while (yield cursor.fetch_next):
                category = cursor.next_object()
                categories.append(
                    dict(categoryId=category['_id'],
                         categoryName=category['name']))

        embedded_cats = [
            EmbeddedCategory.from_metaweblog(cat).to_python()
            for cat in categories
        ]

        result = yield self.settings['db'].posts.update(
            {'_id': ObjectId(postid)}, {
                '$set': {
                    'categories': embedded_cats,
                    'mod': datetime.datetime.utcnow(),
                }
            })

        if result['n'] != 1:
            self.result(xmlrpclib.Fault(404, 'Not found'))
        else:
            self.result('')
            cache.event('post_changed')