def PUT_tags(request): img = URIRef(request.args['uri'][0]) user = webuser.getUserKlein(request) log.info('user %r', user) body = cgi.parse_qs(request.content.read()) saveTags(graph, foafUser=user, img=img, tagString=body.get('tags', [''])[0], desc=body.get('desc', [''])[0]) request.setHeader("Content-Type", "text/json") return json.dumps(getTags(graph, user, img))
def POST_alt(request): uri = URIRef(request.args['uri'][0]) desc = json.load(request.content) if desc['source'] != str(uri): # sometimes this happens on a : vs %3A disagreement, which # is something I think I workaround elsewhere. Drop # 'source' attr entirely? figure out where this new : # escaping is happening? raise ValueError("source %r != %r" % (desc['source'], str(uri))) newAltUri = pickNewUri(uri, desc['tag']) ctx = URIRef(newAltUri + "#create") now = Literal(datetime.datetime.now(tzlocal())) creator = webuser.getUserKlein(request) if not creator: raise ValueError("missing creator") stmts = [ (uri, PHO.alternate, newAltUri), (newAltUri, RDF.type, FOAF.Image), (newAltUri, DCTERMS.creator, creator), (newAltUri, DCTERMS.created, now), ] for k, v in desc.items(): if k in ['source']: continue if k == 'types': for typeUri in v: stmts.append((newAltUri, RDF.type, URIRef(typeUri))) else: # this handles basic json types at most. consider # JSON-LD or just n3 as better input formats, but make # sure all their statements are about the uri, not # arbitrary data that could change security # permissions and stuff stmts.append((newAltUri, PHO[k], Literal(v))) graph.add(stmts, context=ctx) return "added %s statements to context %s" % (len(stmts), ctx)
def GET_tags(request): """description too, though you can get that separately if you want""" img = URIRef(request.args['uri'][0]) user = webuser.getUserKlein(request) request.setHeader("Content-Type", "text/json") return json.dumps(getTags(graph, user, img))