Example #1
0
def json_view(request, uuid):
    ocitem = OCitem()
    if 'hashes' in request.GET:
        ocitem.assertion_hashes = True
    ocitem.get_item(uuid)
    if (ocitem.manifest is not False):
        ts = TypeSupplement(ocitem.json_ld)
        ocitem.json_ld = ts.get_arachne_comparanda()
        req_neg = RequestNegotiation('application/json')
        req_neg.supported_types = ['application/ld+json']
        if 'HTTP_ACCEPT' in request.META:
            req_neg.check_request_support(request.META['HTTP_ACCEPT'])
        if req_neg.supported:
            json_output = json.dumps(ocitem.json_ld,
                                     indent=4,
                                     ensure_ascii=False)
            return HttpResponse(json_output,
                                content_type=req_neg.use_response_type +
                                "; charset=utf8")
        else:
            # client wanted a mimetype we don't support
            return HttpResponse(req_neg.error_message,
                                content_type=req_neg.use_response_type +
                                "; charset=utf8",
                                status=415)
    else:
        raise Http404
Example #2
0
def json_view(request, uuid):
    ocitem = OCitem()
    if 'hashes' in request.GET:
        ocitem.assertion_hashes = True
    ocitem.get_item(uuid)
    if(ocitem.manifest is not False):
        ts = TypeSupplement(ocitem.json_ld)
        ocitem.json_ld = ts.get_arachne_comparanda()
        req_neg = RequestNegotiation('application/json')
        req_neg.supported_types = ['application/ld+json']
        if 'HTTP_ACCEPT' in request.META:
            req_neg.check_request_support(request.META['HTTP_ACCEPT'])
        if req_neg.supported:
            json_output = json.dumps(ocitem.json_ld,
                                     indent=4,
                                     ensure_ascii=False)
            if 'callback' in request.GET:
                funct = request.GET['callback']
                return HttpResponse(funct + '(' + json_output + ');',
                                    content_type='application/javascript' + "; charset=utf8")
            else:
                return HttpResponse(json_output,
                                    content_type=req_neg.use_response_type + "; charset=utf8")
        else:
            # client wanted a mimetype we don't support
            return HttpResponse(req_neg.error_message,
                                content_type=req_neg.use_response_type + "; charset=utf8",
                                status=415)
    else:
        raise Http404
Example #3
0
def html_view(request, uuid):
    request = RequestNegotiation().anonymize_request(request)
    # Handle some content negotiation for the item.    
    req_neg = RequestNegotiation('text/html')
    req_neg.supported_types = []
    if 'HTTP_ACCEPT' in request.META:
        req_neg.check_request_support(request.META['HTTP_ACCEPT'])
    if not req_neg.supported:
        # The client may be wanting a non-HTML representation, so
        # use the following function to get it.
        return items_graph(request, uuid, item_type=ITEM_TYPE)
    # Proceed with constructing the HTML item
    ocitem = OCitem()
    if 'hashes' in request.GET:
        ocitem.assertion_hashes = True
    ocitem.get_item(uuid, True)
    if not ocitem.manifest:
        # Did not find a record for the table, check for redirects
        r_url = RedirectURL()
        r_ok = r_url.get_direct_by_type_id(ITEM_TYPE, uuid)
        if r_ok:
            # found a redirect!!
            return redirect(r_url.redirect, permanent=r_url.permanent)
        # raise Http404
        raise Http404
    # Construnct item the JSON-LD
    request.uuid = ocitem.manifest.uuid
    request.project_uuid = ocitem.manifest.project_uuid
    request.item_type = ocitem.manifest.item_type
    ts = TypeSupplement(ocitem.json_ld)
    ocitem.json_ld = ts.get_arachne_comparanda()
    rp = RootPath()
    base_url = rp.get_baseurl()
    temp_item = TemplateItem(request)
    temp_item.read_jsonld_dict(ocitem.json_ld)
    if not temp_item.view_permitted:
        # The client is not allowed to see this.
        template = loader.get_template('items/view401.html')
        context = {
            'item': temp_item,
            'base_url': base_url,
            'user': request.user
        }
        return HttpResponse(template.render(context, request), status=401)
    # Now add templated item to the a response object
    template = loader.get_template('types/view.html')
    context = {
        'item': temp_item,
        'base_url': base_url,
        'user': request.user
    }
    response = HttpResponse(template.render(context, request))
    patch_vary_headers(response, ['accept', 'Accept', 'content-type'])
    return response
Example #4
0
def html_view(request, uuid):
    ocitem = OCitem()
    ocitem.get_item(uuid)
    if (ocitem.manifest is not False):
        rp = RootPath()
        base_url = rp.get_baseurl()
        ts = TypeSupplement(ocitem.json_ld)
        ocitem.json_ld = ts.get_arachne_comparanda()
        temp_item = TemplateItem(request)
        temp_item.read_jsonld_dict(ocitem.json_ld)
        template = loader.get_template('types/view.html')
        if temp_item.view_permitted:
            req_neg = RequestNegotiation('text/html')
            req_neg.supported_types = [
                'application/json', 'application/ld+json'
            ]
            if 'HTTP_ACCEPT' in request.META:
                req_neg.check_request_support(request.META['HTTP_ACCEPT'])
            if req_neg.supported:
                if 'json' in req_neg.use_response_type:
                    # content negotiation requested JSON or JSON-LD
                    return HttpResponse(
                        json.dumps(ocitem.json_ld,
                                   ensure_ascii=False,
                                   indent=4),
                        content_type=req_neg.use_response_type +
                        "; charset=utf8")
                else:
                    context = RequestContext(request, {
                        'item': temp_item,
                        'base_url': base_url
                    })
                    return HttpResponse(template.render(context))
            else:
                # client wanted a mimetype we don't support
                return HttpResponse(req_neg.error_message,
                                    content_type=req_neg.use_response_type +
                                    "; charset=utf8",
                                    status=415)
        else:
            template = loader.get_template('items/view401.html')
            context = RequestContext(request, {
                'item': temp_item,
                'base_url': base_url
            })
            return HttpResponse(template.render(context), status=401)
    else:
        raise Http404
Example #5
0
def html_view(request, uuid):
    ocitem = OCitem()
    ocitem.get_item(uuid)
    if(ocitem.manifest is not False):
        rp = RootPath()
        base_url = rp.get_baseurl()
        ts = TypeSupplement(ocitem.json_ld)
        ocitem.json_ld = ts.get_arachne_comparanda()
        temp_item = TemplateItem(request)
        temp_item.read_jsonld_dict(ocitem.json_ld)
        template = loader.get_template('types/view.html')
        if temp_item.view_permitted:
            req_neg = RequestNegotiation('text/html')
            req_neg.supported_types = ['application/json',
                                       'application/ld+json']
            if 'HTTP_ACCEPT' in request.META:
                req_neg.check_request_support(request.META['HTTP_ACCEPT'])
            if req_neg.supported:
                if 'json' in req_neg.use_response_type:
                    # content negotiation requested JSON or JSON-LD
                    return HttpResponse(json.dumps(ocitem.json_ld,
                                        ensure_ascii=False, indent=4),
                                        content_type=req_neg.use_response_type + "; charset=utf8")
                else:
                    context = RequestContext(request,
                                             {'item': temp_item,
                                              'base_url': base_url})
                    return HttpResponse(template.render(context))
            else:
                # client wanted a mimetype we don't support
                return HttpResponse(req_neg.error_message,
                                    content_type=req_neg.use_response_type + "; charset=utf8",
                                    status=415)
        else:
            template = loader.get_template('items/view401.html')
            context = RequestContext(request,
                                     {'item': temp_item,
                                      'base_url': base_url})
            return HttpResponse(template.render(context), status=401)
    else:
        raise Http404
Example #6
0
def json_view(request, uuid):
    ocitem = OCitem()
    if "hashes" in request.GET:
        ocitem.assertion_hashes = True
    ocitem.get_item(uuid)
    if ocitem.manifest is not False:
        ts = TypeSupplement(ocitem.json_ld)
        ocitem.json_ld = ts.get_arachne_comparanda()
        req_neg = RequestNegotiation("application/json")
        req_neg.supported_types = ["application/ld+json"]
        if "HTTP_ACCEPT" in request.META:
            req_neg.check_request_support(request.META["HTTP_ACCEPT"])
        if req_neg.supported:
            json_output = json.dumps(ocitem.json_ld, indent=4, ensure_ascii=False)
            return HttpResponse(json_output, content_type=req_neg.use_response_type + "; charset=utf8")
        else:
            # client wanted a mimetype we don't support
            return HttpResponse(
                req_neg.error_message, content_type=req_neg.use_response_type + "; charset=utf8", status=415
            )
    else:
        raise Http404