Ejemplo n.º 1
0
    def update(self, item_id, blibb_id, user, items, tags=None):
        tag_list = []
        if is_valid_id(blibb_id) and is_valid_id(item_id):
            # bid = ObjectId(blibb_id)
            # b = Blibb.get_object({'_id': bid}, {'s': 1})
            # bs = b['s']
            if tags is not None:
                if ',' in tags:
                    tag_list = list(set(tags.lower().split(',')))
                else:
                    tag_list = list(set(tags.lower().split()))
                for t in tag_list:
                    Blibb.add_tag(blibb_id, t)

            # now = datetime.utcnow()
            doc = {"_id": item_id, "b": blibb_id, "i": items}
            objects.update({"_id": ObjectId(item_id)}, {'$set': {"i": items}})
            post_process.send(doc)
            return item_id
        else:
            return Message.get('id_not_valid')
Ejemplo n.º 2
0
    def insert(self, blibb_id, user, items, tags=None):
        tag_list = []
        if is_valid_id(blibb_id):
            bid = ObjectId(blibb_id)
            b = Blibb.get_object({'_id': bid}, {'s': 1})
            bs = b['s']
            if tags is not None:
                if ',' in tags:
                    tag_list = list(set(tags.lower().split(',')))
                else:
                    tag_list = list(set(tags.lower().split()))
                for t in tag_list:
                    Blibb.add_tag(blibb_id, t)

            num = int(NUM_CHARS)
            url_id = "".join(sample(digits + ascii_letters, num))
            now = datetime.utcnow()
            doc = {"b": bid, "u": user, "bs": bs, "c": now, "i": items,
                   "tg": tag_list, "st": "active", "si": url_id}
            newId = objects.insert(doc)
            post_process.send(doc)
            return str(newId)
        else:
            return Message.get('id_not_valid')