def create_blob(self, user, web_id, content, mime_type=None, title=None, tags=[], revises=[]) : if web_id not in [w.id for w in models.UserWebAccess.get_for_user(user)] : raise Exception("no such web") # makes sure has explicit access web = models.Web.get_by_id(web_id) content_type = "mime:" + (mime_type or "plain/text") c = models.Content.get_by_stuff(str(content)) b = models.Blob.make_blob(user, content_type, c) models.WebBlobAccess.add_for_blob(web, b) for puuid in revises : parent_blob = models.Blob.get_by_uuid(puuid) if parent_blob : relations.BinaryRelation.make(web, user, "revises", b, parent_blob) # we don't want to just add tags and title; we want to ensure their presence inherited = relations.get_inherited_relations(web, b) if title : inherited_title = [r for r in inherited if not r.deleted and r.name == "title"] for r in inherited_title : if r.payload != title : relations.BinaryRelation.make(web, user, "deletes", b, r.blob) print "deleting",r if not any(r.payload == title for r in inherited_title) : relations.BinaryRelation.make(web, user, "title", b, title) print "adding" tags = set([t.strip() for t in tags if t.strip()]) inherited_tags = [r for r in inherited if not r.deleted and r.name == "tag"] inherited_tags_payloads = set(r.payload for r in inherited_tags) for r in inherited_tags : if r.payload not in tags : relations.BinaryRelation.make(web, user, "deletes", b, r.blob) for tag in tags : if tag not in inherited_tags_payloads : relations.BinaryRelation.make(web, user, "tag", b, tag) self.channels.broadcast([channel.NewBlobMessage(b)]) return b.uuid
def remove_tag(self, user, web_id, uuid, tag) : if web_id not in [w.id for w in models.UserWebAccess.get_for_user(user)] : raise Exception("no such web") # makes sure has explicit access web = models.Web.get_by_id(web_id) b = models.Blob.get_by_uuid(uuid) inherited = relations.get_inherited_relations(web_id, b) inherited_tags = [r for r in inherited if not r.deleted and r.name == "tag"] for r in inherited_tags : if r.payload == tag : relations.BinaryRelation.make(web, user, "deletes", b, r.blob) return True
def get_blob_metadata(self, user, web_id, uuids) : if web_id not in [w.id for w in models.UserWebAccess.get_for_user(user)] : raise Exception("no such web") # makes sure has explicit access blobs = [] for uuid in set(uuids) : b = models.Blob.get_by_uuid(uuid) if b != None : srels = relations.get_inherited_relations(web_id, uuid) orels = relations.CachedRelation.get_for_object(web_id, uuid) blobs.append({"blob" : self.blob_as_dict(b), "srels" : [self.rel_as_dict(r) for r in srels], "orels" : [self.rel_as_dict(r) for r in orels]}) return blobs