def create_project_text_from_request(request, project_uri, request_text_uri): if request.user.is_authenticated(): if has_permission_over(project_uri, user=request.user, permission=NS.perm.mayUpdate): try: logger.debug('!!!!!!!!!!!!!!! project_texts.py - create_project_text_from_request') g = parse_request_into_graph(request) except (ParserError, SyntaxError) as e: logger.debug('!!!!!!!!!!!!!!! project_texts.py - create_project_text_from_request - EXCEPTION !!!!!!!!') return HttpResponse(status=400, content="Unable to parse serialization.\n%s" % e) else: logger.debug('!!!!!!!!!!!!!!! project_texts.py - create_project_text_from_request - ELSE !!!!!!!!') text_uri = URIRef(uris.uuid()) logger.debug("uris.uuid(): %s", uris.uuid()) logger.debug("text_uri: %s", text_uri) logger.debug('!!!!!!!!!!!!!!! project_texts.py - create_project_text_from_request - CREATING TEXT... !!!!!!!!') update_project_text(g, project_uri, text_uri, request.user) logger.debug('!!!!!!!!!!!!!!! project_texts.py - create_project_text_from_request - CREATING TEXT COMPLETE !!!!!!!!') logger.debug('!!!!!!!!!!!!!!! project_texts.py - create_project_text_from_request - UPDATING... !!!!!!!!') update_project_text(g, project_uri, request_text_uri, request.user) logger.debug('!!!!!!!!!!!!!!! project_texts.py - create_project_text_from_request - UPDATING COMPLETE !!!!!!!!') return NegotiatedGraphResponse(request, read_project_text(project_uri, text_uri)) else: return HttpResponseForbidden() else: return HttpResponse(status=401)
def post(self, request, project_uri): project_uri = URIRef(project_uri) project_graph = get_project_graph(project_uri) project_metadata_graph = get_project_metadata_graph(project_uri) canvas_graph = Graph() image_file = request.FILES['image_file'] title = request.POST.get('title', '') uri = uris.uuid() if hasattr(settings, 'MAX_IMAGE_UPLOAD_FILE_SIZE' ) and image_file.size > settings.MAX_IMAGE_UPLOAD_FILE_SIZE: return HttpResponse(status=406) if not image_file.content_type.startswith('image/'): return HttpResponse(status=406) uploaded = UploadedImage.objects.create(imagefile=image_file, owner=request.user) create_canvas_from_upload(canvas_graph, uploaded, uri, request.user, title) # Make the canvas a top level project resource canvas_graph.add((project_uri, NS.ore.aggregates, uri)) project_graph += canvas_graph project_metadata_graph += canvas_graph canvas_graph += metadata_triples(project_metadata_graph, project_uri) canvas_graph += project_metadata_graph.triples( (project_uri, NS.ore.aggregates, None)) return NegotiatedGraphResponse(request, canvas_graph)
def post(self, request, project_uri): project_uri = URIRef(project_uri) project_graph = get_project_graph(project_uri) project_metadata_graph = get_project_metadata_graph(project_uri) canvas_graph = Graph() image_file = request.FILES['image_file'] title = request.POST.get('title', '') uri = uris.uuid() if hasattr(settings, 'MAX_IMAGE_UPLOAD_FILE_SIZE') and image_file.size > settings.MAX_IMAGE_UPLOAD_FILE_SIZE: return HttpResponse(status=406) if not image_file.content_type.startswith('image/'): return HttpResponse(status=406) uploaded = UploadedImage.objects.create(imagefile=image_file, owner=request.user) create_canvas_from_upload(canvas_graph, uploaded, uri, request.user, title) # Make the canvas a top level project resource canvas_graph.add((project_uri, NS.ore.aggregates, uri)) project_graph += canvas_graph project_metadata_graph += canvas_graph canvas_graph += metadata_triples(project_metadata_graph, project_uri) canvas_graph += project_metadata_graph.triples((project_uri, NS.ore.aggregates, None)) return NegotiatedGraphResponse(request, canvas_graph)
def create_canvas_from_upload(graph, uploaded_image, uri, user=None, title=None): graph.add((uri, NS.rdf.type, NS.sc.Canvas)) if title: graph.add((uri, NS.dc.title, Literal(title))) graph.add((uri, NS.rdfs.label, Literal(title))) if user: user_uri = users.user_uri(user=user) graph.add((uri, NS.dc.creator, user_uri)) image_uri = uris.absolutize(uploaded_image.imagefile.url) graph.add((image_uri, NS.rdf.type, NS.dcmitype.Image)) width = Literal(uploaded_image.imagefile.width) height = Literal(uploaded_image.imagefile.height) graph.add((image_uri, NS.exif.width, width)) graph.add((image_uri, NS.exif.height, height)) graph.add((uri, NS.exif.width, width)) graph.add((uri, NS.exif.height, height)) anno_uri = uris.uuid() graph.add((anno_uri, NS.rdf.type, NS.oa.Annotation)) graph.add((anno_uri, NS.oa.motivatedBy, NS.sc.painting)) graph.add((anno_uri, NS.oa.hasBody, image_uri)) graph.add((anno_uri, NS.oa.hasTarget, uri)) return graph
def create_project_text_from_request(request, project_uri, request_text_uri): if request.user.is_authenticated(): if has_permission_over(project_uri, user=request.user, permission=NS.perm.mayUpdate): try: logger.debug( '!!!!!!!!!!!!!!! project_texts.py - create_project_text_from_request' ) g = parse_request_into_graph(request) except (ParserError, SyntaxError) as e: logger.debug( '!!!!!!!!!!!!!!! project_texts.py - create_project_text_from_request - EXCEPTION !!!!!!!!' ) return HttpResponse( status=400, content="Unable to parse serialization.\n%s" % e) else: logger.debug( '!!!!!!!!!!!!!!! project_texts.py - create_project_text_from_request - ELSE !!!!!!!!' ) text_uri = URIRef(uris.uuid()) logger.debug("uris.uuid(): %s", uris.uuid()) logger.debug("text_uri: %s", text_uri) logger.debug( '!!!!!!!!!!!!!!! project_texts.py - create_project_text_from_request - CREATING TEXT... !!!!!!!!' ) update_project_text(g, project_uri, text_uri, request.user) logger.debug( '!!!!!!!!!!!!!!! project_texts.py - create_project_text_from_request - CREATING TEXT COMPLETE !!!!!!!!' ) logger.debug( '!!!!!!!!!!!!!!! project_texts.py - create_project_text_from_request - UPDATING... !!!!!!!!' ) update_project_text(g, project_uri, request_text_uri, request.user) logger.debug( '!!!!!!!!!!!!!!! project_texts.py - create_project_text_from_request - UPDATING COMPLETE !!!!!!!!' ) return NegotiatedGraphResponse( request, read_project_text(project_uri, text_uri)) else: return HttpResponseForbidden() else: return HttpResponse(status=401)
def create_project_text_from_request(request, project_uri): if request.user.is_authenticated(): if has_permission_over(project_uri, user=request.user, permission=NS.perm.mayUpdate): try: g = parse_request_into_graph(request) except (ParserError, SyntaxError) as e: return HttpResponse(status=400, content="Unable to parse serialization.\n%s" % e) else: text_uri = URIRef(uris.uuid()) update_project_text(g, project_uri, text_uri, request.user) return NegotiatedGraphResponse(request, read_project_text(project_uri, text_uri)) else: return HttpResponseForbidden() else: return HttpResponse(status=401)
def create_project_graph(host, user, title, project): if not project: project = uris.uuid() elif not (type(project) == URIRef): project = URIRef(project) g = Graph() bind_namespaces(g) if not title: title = "Default Project" g.add((project, NS.rdf.type, NS.foaf.Project)) g.add((project, NS.rdf.type, NS.dm.Project)) g.add((project, NS.rdf['type'], NS.dcmitype['Collection'])) g.add((project, NS.rdf['type'], NS.ore['Aggregation'])) g.add((project, NS.dc['title'], Literal(title))) g.add((project, NS.dcterms['created'], Literal(datetime.utcnow()))) return g
def create_project_graph(host, user, title, project): if not project: project = uris.uuid() elif not (type(project) == URIRef): project = URIRef(project) g = Graph() bind_namespaces(g) if not title: title = "Default Project" g.add((project, NS.rdf.type, NS.foaf.Project)) g.add((project, NS.rdf.type, NS.dm.Project)) g.add((project, NS.rdf['type'], NS.dcmitype['Collection'])) g.add((project, NS.rdf['type'], NS.ore['Aggregation'])) g.add((project, NS.dc['title'], Literal(title))) g.add((project, NS.dcterms['created'], Literal(datetime.utcnow()))) return g