コード例 #1
0
ファイル: views.py プロジェクト: upenn-libraries/DM
def import_old_data(request):
    everything_graph = Graph()
    bind_namespaces(everything_graph)

    # Either gather post data (must be one project/user graph at a time)
    if request.method == 'POST':
        logger.debug('!!!!!!!!!!!!!!! views.py - import_old_data')
        parse_request_into_graph(request, everything_graph)

        add_all_users(everything_graph)

        # Create each user's default project
        # Due to the structure of the data when exported from the old system, this also
        #  add each annotation to the project as an aggregated resource
        create_project(everything_graph)

    # or serialize from a folder, where each file is one project/user graph
    else:
        i = 0
        for file_name in listdir("output/"):
            if file_name.startswith('.'):
                continue

            try:
                everything_graph.parse("output/" + file_name, format=guess_format(file_name) or 'turtle')
            except Exception as e:
                print "Failed to decode file '%s' with error message '%s'"%(file_name, e.args[-1])
            else:
                add_all_users(everything_graph)
                create_project(everything_graph)
        

    return HttpResponse("I finished migrating data without errors.")
コード例 #2
0
def import_old_data(request):
    everything_graph = Graph()
    bind_namespaces(everything_graph)

    # Either gather post data (must be one project/user graph at a time)
    if request.method == 'POST':
        logger.debug('!!!!!!!!!!!!!!! views.py - import_old_data')
        parse_request_into_graph(request, everything_graph)

        add_all_users(everything_graph)

        # Create each user's default project
        # Due to the structure of the data when exported from the old system, this also
        #  add each annotation to the project as an aggregated resource
        create_project(everything_graph)

    # or serialize from a folder, where each file is one project/user graph
    else:
        i = 0
        for file_name in listdir("output/"):
            if file_name.startswith('.'):
                continue

            try:
                everything_graph.parse("output/" + file_name,
                                       format=guess_format(file_name)
                                       or 'turtle')
            except Exception as e:
                print "Failed to decode file '%s' with error message '%s'" % (
                    file_name, e.args[-1])
            else:
                add_all_users(everything_graph)
                create_project(everything_graph)

    return HttpResponse("I finished migrating data without errors.")
コード例 #3
0
ファイル: users.py プロジェクト: bobclewell/DM
def update_user(request, username):
    if request.user.is_authenticated():
        try:
            input_graph = parse_request_into_graph(request)
        except (ParserError, SyntaxError) as e:
            return HttpResponse(status=400, content="Unable to parse serialization.\n%s" % e)

        if permission_updates_are_allowed(request, input_graph):
            user_uri = URIRef(uris.uri('semantic_store_users', username=username))
            user_graph = Graph(store=rdfstore(), identifier=USER_GRAPH_IDENTIFIER)

            with transaction.commit_on_success():
                try:
                    user = User.objects.get(username=username)
                except ObjectDoesNotExist:
                    return HttpResponse('User %s does not exist' % (username), status=400)
                else:
                    for t in input_graph.triples((user_uri, NS.dm.lastOpenProject, None)):
                        user_graph.set(t)

                    for project in input_graph.objects(user_uri, NS.perm.mayRead):
                        grant_read_permissions(project, user=user)

                    for project in input_graph.objects(user_uri, NS.perm.mayUpdate):
                        grant_write_permissions(project, user=user)

                    for project in input_graph.objects(user_uri, NS.perm.mayAdminister):
                        grant_admin_permissions(project, user=user)

            return HttpResponse(status=204)
        else:
            return HttpResponseForbidden('The PUT graph contained permissions updates which were not allowed')
    else:
        return HttpResponse(status=401)
コード例 #4
0
ファイル: project_texts.py プロジェクト: upenn-libraries/DM
def update_project_text_from_request(request, project_uri, text_uri):
    logger.debug("************** update_project_text_from_request")
    logger.debug("%%%%%%%%%%%%%% request.body:")
    logger.debug("\r" + request.body)
    logger.debug("%%%%%%%%%%%%%% project_uri:")
    logger.debug("\r" + project_uri)
    logger.debug("%%%%%%%%%%%%%% text_uri:")
    logger.debug("\r" + 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 - update_project_text_from_request'
                )
                g = parse_request_into_graph(request)
            except (ParserError, SyntaxError) as e:
                return HttpResponse(
                    status=400,
                    content="Unable to parse serialization. %s" % e)
            else:
                # On successful parse, send to basic method
                update_project_text(g, project_uri, text_uri, request.user)
                return HttpResponse(status=204)
        else:
            return HttpResponseForbidden()
    else:
        return HttpResponse(status=401)
コード例 #5
0
ファイル: views.py プロジェクト: upenn-libraries/DM
def specific_resource_graph(request, project_uri, specific_resource, source):
    if request.method == 'GET':
        return NegotiatedGraphResponse(request, read_specific_resource(project_uri, specific_resource, source))
    elif request.method == 'PUT':
        logger.debug('!!!!!!!!!!!!!!! views.py - specific_resource_graph')
        g = parse_request_into_graph(request)
        update_specific_resource(g, URIRef(project_uri), URIRef(specific_resource))
コード例 #6
0
ファイル: projects.py プロジェクト: timandres/DM
def delete_triples_from_project(request, uri):
    """Deletes the triples in a graph provided by a request object from the project graph.
    Returns an HttpResponse of all the triples which were successfully removed from the graph."""
    if request.user.is_authenticated():
        if permissions.has_permission_over(uri, user=request.user, permission=NS.perm.mayUpdate):
            removed = Graph()
            bind_namespaces(removed)

            try:
                g = parse_request_into_graph(request)
            except (ParserError, SyntaxError) as e:
                return HttpResponse(status=400, content="Unable to parse serialization.\n%s" % e)

            project_g = get_project_graph(uri)
            project_metadata_g = get_project_metadata_graph(uri)

            for t in g:
                if t in project_g:
                    project_g.remove(t)
                    removed.add(t)
                project_metadata_g.remove(t)

            return NegotiatedGraphResponse(request, removed)
        else:
            return HttpResponseForbidden('User "%s" does not have update permissions over project "%s"' % (request.user.username, uri))
    else:
        return HttpResponse(status=401)
コード例 #7
0
ファイル: projects.py プロジェクト: upenn-libraries/DM
def delete_triples_from_project(request, uri):
    """Deletes the triples in a graph provided by a request object from the project graph.
    Returns an HttpResponse of all the triples which were successfully removed from the graph."""
    if request.user.is_authenticated():
        if permissions.has_permission_over(uri, user=request.user, permission=NS.perm.mayUpdate):
            removed = Graph()
            bind_namespaces(removed)

            try:
                logger.debug('!!!!!!!!!!!!!!! project_texts.py - delete_triples_from_project')
                g = parse_request_into_graph(request)
            except (ParserError, SyntaxError) as e:
                return HttpResponse(status=400, content="Unable to parse serialization.\n%s" % e)

            project_g = get_project_graph(uri)
            project_metadata_g = get_project_metadata_graph(uri)

            for t in g:
                if t in project_g:
                    project_g.remove(t)
                    removed.add(t)
                project_metadata_g.remove(t)

            return NegotiatedGraphResponse(request, removed)
        else:
            return HttpResponseForbidden('User "%s" does not have update permissions over project "%s"' % (request.user.username, uri))
    else:
        return HttpResponse(status=401)
コード例 #8
0
ファイル: project_texts.py プロジェクト: upenn-libraries/DM
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)
コード例 #9
0
ファイル: views.py プロジェクト: bobclewell/DM
def project_canvases(request, project_uri, canvas_uri):
    if request.method == 'GET':
        return NegotiatedGraphResponse(request, read_canvas(request, project_uri, canvas_uri))
    elif request.method == 'PUT':
        input_graph = parse_request_into_graph(request)
        return NegotiatedGraphResponse(request, update_canvas(project_uri, canvas_uri, input_graph))
    else:
        return HttpResponseNotAllowed(('GET', 'PUT'))
コード例 #10
0
ファイル: projects.py プロジェクト: timandres/DM
def create_project_from_request(request):
    """Takes a graph via an http request, and creates a project in the database (and the metadata cache) from an input graph"""
    try:
        g = parse_request_into_graph(request)
    except (ParserError, SyntaxError) as e:
        return HttpResponse(status=400, content="Unable to parse serialization.\n%s" % e)

    create_project(g)
    return HttpResponse("Successfully created the project.")
コード例 #11
0
ファイル: views.py プロジェクト: timandres/DM
def specific_resource_graph(request, project_uri, specific_resource, source):
    if request.method == 'GET':
        return NegotiatedGraphResponse(
            request,
            read_specific_resource(project_uri, specific_resource, source))
    elif request.method == 'PUT':
        g = parse_request_into_graph(request)
        update_specific_resource(g, URIRef(project_uri),
                                 URIRef(specific_resource))
コード例 #12
0
ファイル: views.py プロジェクト: timandres/DM
def project_canvases(request, project_uri, canvas_uri):
    if request.method == 'GET':
        return NegotiatedGraphResponse(
            request, read_canvas(request, project_uri, canvas_uri))
    elif request.method == 'PUT':
        input_graph = parse_request_into_graph(request)
        return NegotiatedGraphResponse(
            request, update_canvas(project_uri, canvas_uri, input_graph))
    else:
        return HttpResponseNotAllowed(('GET', 'PUT'))
コード例 #13
0
ファイル: projects.py プロジェクト: upenn-libraries/DM
def create_project_from_request(request):
    """Takes a graph via an http request, and creates a project in the database (and the metadata cache) from an input graph"""
    try:
        logger.debug('!!!!!!!!!!!!!!! project_texts.py - create_project_from_request')
        g = parse_request_into_graph(request)
    except (ParserError, SyntaxError) as e:
        return HttpResponse(status=400, content="Unable to parse serialization.\n%s" % e)

    create_project(g)
    return HttpResponse("Successfully created the project.")
コード例 #14
0
ファイル: annotation_views.py プロジェクト: bobclewell/DM
def create_or_update_annotations(request, dest_graph_uri=None, anno_uri=None):
    dest_g = destination_graph(dest_graph_uri)
    annotations_g = graph()
    try:
        parse_request_into_graph(request, annotations_g)
    except (ParserError, SyntaxError) as e:
        return HttpResponse(status=400, content="Unable to parse serialization.\n%s" % e)
    anno_uris = annotation_uris(annotations_g)
    if not anno_uris:
        return HttpResponse(status=400, 
                            content="No %s nodes found." % URIRef(NS.oa['Annotation']))

    if not valid_annotations(dest_g, annotations_g, anno_uris):
        return HttpResponse(status=400, content=validator.failure)

    with transaction.commit_on_success():
        for i in anno_uris:
            stored_g = update_annotation(request, dest_g, annotations_g, i)

    return NegotiatedGraphResponse(request, stored_g, status=201)
コード例 #15
0
def create_or_update_annotations(request, dest_graph_uri=None, anno_uri=None):
    dest_g = destination_graph(dest_graph_uri)
    annotations_g = graph()
    try:
        parse_request_into_graph(request, annotations_g)
    except (ParserError, SyntaxError) as e:
        return HttpResponse(status=400,
                            content="Unable to parse serialization.\n%s" % e)
    anno_uris = annotation_uris(annotations_g)
    if not anno_uris:
        return HttpResponse(status=400,
                            content="No %s nodes found." %
                            URIRef(NS.oa['Annotation']))

    if not valid_annotations(dest_g, annotations_g, anno_uris):
        return HttpResponse(status=400, content=validator.failure)

    with transaction.commit_on_success():
        for i in anno_uris:
            stored_g = update_annotation(request, dest_g, annotations_g, i)

    return NegotiatedGraphResponse(request, stored_g, status=201)
コード例 #16
0
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)
コード例 #17
0
ファイル: projects.py プロジェクト: bobclewell/DM
def update_project(request, uri):
    """Updates the project and metadata graph from a put or post request"""
    if request.user.is_authenticated():
        if permissions.has_permission_over(uri, user=request.user, permission=NS.perm.mayUpdate):
            try:
                input_graph = parse_request_into_graph(request)
            except (ParserError, SyntaxError) as e:
                return HttpResponse(status=400, content="Unable to parse serialization.\n%s" % e)

            update_project_graph(input_graph, URIRef(uri))

            return HttpResponse(status=204)
        else:
            return HttpResponseForbidden('User "%s" does not have update permissions over project "%s"' % (request.user.username, uri))
    else:
        return HttpResponse('Unauthorized', status=401)
コード例 #18
0
ファイル: project_texts.py プロジェクト: upenn-libraries/DM
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)
コード例 #19
0
ファイル: users.py プロジェクト: bobclewell/DM
def remove_triples_from_user(request, username):
    removed = Graph()
    user = User.objects.get(username=username)

    try:
        input_graph = parse_request_into_graph(request)
    except (ParserError, SyntaxError) as e:
        return HttpResponse(status=400, content="Unable to parse serialization.\n%s" % e)

    with transaction.commit_on_success():
        for t in input_graph:
            if is_allowed_update_triple(t, username, request):
                removed.add(t)
                user_uri, perm, project = t

                revoke_permission_by_uri(perm, project, user=user)
            else:
                print "Triple %s was rejected to be removed from user graph" % unicode(t)

    return HttpResponse(status=204)
コード例 #20
0
ファイル: projects.py プロジェクト: upenn-libraries/DM
def update_project(request, uri):
    """Updates the project and metadata graph from a put or post request"""
    if request.user.is_authenticated():
        if (permissions.has_permission_over(uri, user=request.user, permission=NS.perm.mayUpdate) or
            permissions.is_abandoned_project(uri)):
            logger.debug("$$$$$$$$$$$ update_project (request)")
            logger.debug(request)
            
            try:
                logger.debug('!!!!!!!!!!!!!!! project_texts.py - update_project')
                input_graph = parse_request_into_graph(request)
            except (ParserError, SyntaxError) as e:
                return HttpResponse(status=400, content="Unable to parse serialization.\n%s" % e)

            update_project_graph(input_graph, URIRef(uri))

            return HttpResponse(status=204)
        else:
            return HttpResponseForbidden('User "%s" does not have update permissions over project "%s"' % (request.user.username, uri))
    else:
        return HttpResponse('Unauthorized', status=401)
コード例 #21
0
ファイル: project_texts.py プロジェクト: upenn-libraries/DM
def update_project_text_from_request(request, project_uri, text_uri):
    logger.debug("************** update_project_text_from_request")
    logger.debug("%%%%%%%%%%%%%% request.body:")
    logger.debug("\r" + request.body)
    logger.debug("%%%%%%%%%%%%%% project_uri:")
    logger.debug("\r" + project_uri)
    logger.debug("%%%%%%%%%%%%%% text_uri:")
    logger.debug("\r" + 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 - update_project_text_from_request')
                g = parse_request_into_graph(request)
            except (ParserError, SyntaxError) as e:
                return HttpResponse(status=400, content="Unable to parse serialization. %s" % e)
            else:
                # On successful parse, send to basic method
                update_project_text(g, project_uri, text_uri, request.user)
                return HttpResponse(status=204)
        else:
            return HttpResponseForbidden()
    else:
        return HttpResponse(status=401)