当前位置: 首页>>代码示例>>Python>>正文


Python RequestNegotiation.supported_types方法代码示例

本文整理汇总了Python中opencontext_py.libs.requestnegotiation.RequestNegotiation.supported_types方法的典型用法代码示例。如果您正苦于以下问题:Python RequestNegotiation.supported_types方法的具体用法?Python RequestNegotiation.supported_types怎么用?Python RequestNegotiation.supported_types使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在opencontext_py.libs.requestnegotiation.RequestNegotiation的用法示例。


在下文中一共展示了RequestNegotiation.supported_types方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: html_view

# 需要导入模块: from opencontext_py.libs.requestnegotiation import RequestNegotiation [as 别名]
# 或者: from opencontext_py.libs.requestnegotiation.RequestNegotiation import supported_types [as 别名]
def html_view(request, uuid):
    ocitem = OCitem()
    ocitem.get_item(uuid)
    if ocitem.manifest is not False:
        rp = RootPath()
        base_url = rp.get_baseurl()
        temp_item = TemplateItem(request)
        temp_item.read_jsonld_dict(ocitem.json_ld)
        template = loader.get_template("media/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, "fullview": False, "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
开发者ID:portableant,项目名称:open-context-py,代码行数:37,代码来源:views.py

示例2: gazetteer

# 需要导入模块: from opencontext_py.libs.requestnegotiation import RequestNegotiation [as 别名]
# 或者: from opencontext_py.libs.requestnegotiation.RequestNegotiation import supported_types [as 别名]
def gazetteer(request):
    """ Returns RDF void data describing different datasets for
        Pelagious
    """
    p_gg = PelagiosGazetteerGraph()
    p_gg.request = request
    if 'refresh' in request.GET:
        # we're going to refresh the cache
        p_gg.refresh_cache = True
    p_gg.make_graph()
    req_neg = RequestNegotiation('text/turtle')
    req_neg.supported_types = ['application/rdf+xml',
                               'text/n3',
                               'application/n-triples']
    if 'HTTP_ACCEPT' in request.META:
        req_neg.check_request_support(request.META['HTTP_ACCEPT'])
        if req_neg.supported:
            content_type = req_neg.use_response_type + '; charset=utf8'
            output = p_gg.g.serialize(format=req_neg.use_response_type)
            return HttpResponse(output,
                                content_type=content_type)
        else:
            # client wanted a mimetype we don't support
            return HttpResponse(req_neg.error_message,
                                content_type="text/plain; charset=utf8",
                                status=415)
    else:
        # default to outputting in turtle
        output = p_gg.g.serialize(format='turtle')
        return HttpResponse(output,
                            content_type='text/turtle; charset=utf8')
开发者ID:mfindeisen,项目名称:open-context-py,代码行数:33,代码来源:views.py

示例3: index_atom

# 需要导入模块: from opencontext_py.libs.requestnegotiation import RequestNegotiation [as 别名]
# 或者: from opencontext_py.libs.requestnegotiation.RequestNegotiation import supported_types [as 别名]
def index_atom(request):
    """ Get the search context JSON-LD """
    mf = ManifestFeed()
    xml_string = mf.make_feed(request.GET)
    if xml_string is not False:
        req_neg = RequestNegotiation('application/atom+xml')
        req_neg.supported_types = ['application/atom+xml']
        if 'HTTP_ACCEPT' in request.META:
            req_neg.check_request_support(request.META['HTTP_ACCEPT'])
        if req_neg.supported:
            if 'atom' in req_neg.use_response_type:
                # content negotiation requested Atom
                return HttpResponse(xml_string,
                                    content_type=req_neg.use_response_type + "; charset=utf8")
            else:
                # give atom anyway
                return HttpResponse(xml_string,
                                    content_type='application/atom+xml' + "; charset=utf8")
        else:
            # client wanted a mimetype we don't support
            return HttpResponse(req_neg.error_message,
                                content_type='text/html' + "; charset=utf8",
                                status=415)
    else:
        # no feed of this page or type
        raise Http404
开发者ID:ekansa,项目名称:open-context-py,代码行数:28,代码来源:views.py

示例4: projects_json

# 需要导入模块: from opencontext_py.libs.requestnegotiation import RequestNegotiation [as 别名]
# 或者: from opencontext_py.libs.requestnegotiation.RequestNegotiation import supported_types [as 别名]
def projects_json(request, uuid):
    """ provides a JSON-LD context for
        the data in a project. This will include
        annotations of predicates and types
    """
    proj_context = ProjectContext(uuid, request)
    if 'hashes' in request.GET:
        proj_context.assertion_hashes = True
    if proj_context.manifest is not False:
        req_neg = RequestNegotiation('application/json')
        req_neg.supported_types = ['application/ld+json',
                                   'application/vnd.geo+json']
        if 'HTTP_ACCEPT' in request.META:
            req_neg.check_request_support(request.META['HTTP_ACCEPT'])
        if req_neg.supported:
            json_ld = proj_context.make_context_json_ld()
            json_output = json.dumps(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
开发者ID:mfindeisen,项目名称:open-context-py,代码行数:35,代码来源:views.py

示例5: json_view

# 需要导入模块: from opencontext_py.libs.requestnegotiation import RequestNegotiation [as 别名]
# 或者: from opencontext_py.libs.requestnegotiation.RequestNegotiation import supported_types [as 别名]
def json_view(request, spatial_context=None):
    """ API for searching Open Context """
    rd = RequestDict()
    request_dict_json = rd.make_request_dict_json(request,
                                                  spatial_context)
    solr_s = SolrSearch()
    if solr_s.solr is not False:
        response = solr_s.search_solr(request_dict_json)
        m_json_ld = MakeJsonLd(request_dict_json)
        # share entities already looked up. Saves database queries
        m_json_ld.entities = solr_s.entities
        m_json_ld.request_full_path = request.get_full_path()
        m_json_ld.spatial_context = spatial_context
        json_ld = m_json_ld.convert_solr_json(response.raw_content)
        req_neg = RequestNegotiation('application/json')
        req_neg.supported_types = ['application/ld+json']
        recon_obj = Reconciliation()
        json_ld = recon_obj.process(request.GET,
                                    json_ld)
        if 'HTTP_ACCEPT' in request.META:
            req_neg.check_request_support(request.META['HTTP_ACCEPT'])
        if req_neg.supported:
            # requester wanted a mimetype we DO support
            return HttpResponse(json.dumps(json_ld,
                                ensure_ascii=False, indent=4),
                                content_type=req_neg.use_response_type + "; charset=utf8")
        else:
            # client wanted a mimetype we don't support
            return HttpResponse(req_neg.error_message,
                                status=415)
    else:
        template = loader.get_template('500.html')
        context = RequestContext(request,
                                 {'error': 'Solr Connection Problem'})
        return HttpResponse(template.render(context), status=503)
开发者ID:portableant,项目名称:open-context-py,代码行数:37,代码来源:views.py

示例6: json_view

# 需要导入模块: from opencontext_py.libs.requestnegotiation import RequestNegotiation [as 别名]
# 或者: from opencontext_py.libs.requestnegotiation.RequestNegotiation import supported_types [as 别名]
def json_view(request, uuid):
    ocitem = OCitem()
    if 'hashes' in request.GET:
        ocitem.assertion_hashes = True
    ocitem.get_item(uuid, True)
    if(ocitem.manifest is not False):
        req_neg = RequestNegotiation('application/json')
        req_neg.supported_types = ['application/ld+json',
                                   'application/vnd.geo+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
开发者ID:mfindeisen,项目名称:open-context-py,代码行数:31,代码来源:views.py

示例7: html_view

# 需要导入模块: from opencontext_py.libs.requestnegotiation import RequestNegotiation [as 别名]
# 或者: from opencontext_py.libs.requestnegotiation.RequestNegotiation import supported_types [as 别名]
def html_view(request, spatial_context=None):
    rp = RootPath()
    base_url = rp.get_baseurl()
    rd = RequestDict()
    request_dict_json = rd.make_request_dict_json(request,
                                                  spatial_context)
    url = request.get_full_path()
    if 'http://' not in url \
       and 'https://' not in url:
        url = base_url + url
    if '?' in url:
        json_url = url.replace('?', '.json?')
    else:
        json_url = url + '.json'
    solr_s = SolrSearch()
    if solr_s.solr is not False:
        response = solr_s.search_solr(request_dict_json)
        m_json_ld = MakeJsonLd(request_dict_json)
        # share entities already looked up. Saves database queries
        m_json_ld.entities = solr_s.entities
        m_json_ld.request_full_path = request.get_full_path()
        m_json_ld.spatial_context = spatial_context
        json_ld = m_json_ld.convert_solr_json(response.raw_content)
        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 'json' in req_neg.use_response_type:
            # content negotiation requested JSON or JSON-LD
            recon_obj = Reconciliation()
            json_ld = recon_obj.process(request.GET,
                                        json_ld)
            return HttpResponse(json.dumps(json_ld,
                                ensure_ascii=False, indent=4),
                                content_type=req_neg.use_response_type + "; charset=utf8")
        else:
            # now make the JSON-LD into an object suitable for HTML templating
            st = SearchTemplate(json_ld)
            st.process_json_ld()
            template = loader.get_template('sets/view.html')
            context = RequestContext(request,
                                     {'st': st,
                                      'url': url,
                                      'json_url': json_url,
                                      'base_url': base_url})
            if req_neg.supported:
                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('500.html')
        context = RequestContext(request,
                                 {'error': 'Solr Connection Problem'})
        return HttpResponse(template.render(context), status=503)
开发者ID:portableant,项目名称:open-context-py,代码行数:60,代码来源:views.py

示例8: html_view

# 需要导入模块: from opencontext_py.libs.requestnegotiation import RequestNegotiation [as 别名]
# 或者: from opencontext_py.libs.requestnegotiation.RequestNegotiation import supported_types [as 别名]
def html_view(request, identifier):
    rp = RootPath()
    base_url = rp.get_baseurl()
    uri = 'http://opencontext.org/vocabularies/' + str(identifier)
    lequiv = LinkEquivalence()
    id_list = lequiv.get_identifier_list_variants(uri)
    lequiv = LinkEquivalence()
    id_s_list = lequiv.get_identifier_list_variants(uri + '/')
    for id_s in id_s_list:
        if id_s not in id_list:
            # add the slashed version to the list
            id_list.append(id_s)
    entity = False
    for test_id in id_list:
        ent = Entity()
        found = ent.dereference(test_id)
        if found is False:
            found = ent.dereference(test_id, test_id)
        if found:
            entity = ent
            break
    if entity is not False:
        t_vocab = TemplateVocab()
        t_vocab.create_template_for_entity(entity)
        t_vocab.make_json_for_html()
        req_neg = RequestNegotiation('text/html')
        req_neg.supported_types = ['application/ld+json',
                                   'application/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
                json_obj = t_vocab.make_json_obj()
                return HttpResponse(json.dumps(json_obj,
                                    ensure_ascii=False, indent=4),
                                    content_type=req_neg.use_response_type + "; charset=utf8")
            else:
                template = loader.get_template('vocabularies/view.html')
                context = {
                    'item': t_vocab,
                    'base_url': base_url,
                    'page_title': 'Open Context: Vocabularies + Ontologies',
                    'act_nav': 'vocabularies',
                    'nav_items': settings.NAV_ITEMS
                }
                return HttpResponse(template.render(context, request))
        else:
             # client wanted a mimetype we don't support
            return HttpResponse(req_neg.error_message,
                                content_type="text/plain; charset=utf8",
                                status=415)
    else:
        raise Http404
开发者ID:ekansa,项目名称:open-context-py,代码行数:56,代码来源:views.py

示例9: project_annotations

# 需要导入模块: from opencontext_py.libs.requestnegotiation import RequestNegotiation [as 别名]
# 或者: from opencontext_py.libs.requestnegotiation.RequestNegotiation import supported_types [as 别名]
def project_annotations(request, identifier):
    """ Returns RDF open annotation assertions conforming to
        Pelagios specifications that link
        Open Context resources with place entities in
        gazetteers
    """
    ent = Entity()
    found = ent.dereference(identifier)
    if found or identifier == 'web':
        if ent.item_type == 'projects' or identifier == 'web':
            pelagios = PelagiosGraph()
            pelagios.test_limit = None
            if 'refresh' in request.GET:
                # we're going to refresh the cache
                pelagios.refresh_cache = True
            if identifier != 'web':
                pp = ProjectPermissions(ent.uuid)
                permitted = pp.view_allowed(request)
                pelagios.project_uuids = [ent.uuid]
            else:
                # we're doing web annotations
                pelagios.do_web_annotations = True
                permitted = True
            if permitted:
                pelagios.get_graph()
                req_neg = RequestNegotiation('text/turtle')
                req_neg.supported_types = ['application/rdf+xml',
                                           'text/n3',
                                           'application/n-triples']
                if 'HTTP_ACCEPT' in request.META:
                    req_neg.check_request_support(request.META['HTTP_ACCEPT'])
                    if req_neg.supported:
                        content_type = req_neg.use_response_type + '; charset=utf8'
                        output = pelagios.g.serialize(format=req_neg.use_response_type)
                        return HttpResponse(output,
                                            content_type=content_type)
                    else:
                        # client wanted a mimetype we don't support
                        return HttpResponse(req_neg.error_message,
                                            content_type="text/plain; charset=utf8",
                                            status=415)
                else:
                    # default to outputting in turtle
                    output = pelagios.g.serialize(format='turtle')
                    return HttpResponse(output,
                                        content_type='text/turtle; charset=utf8')
            else:
                return HttpResponse('Not authorized to get this resource',
                                    content_type='text/html; charset=utf8',
                                    status=401)
        else:
            found = False
    if found is False:
        raise Http404
开发者ID:mfindeisen,项目名称:open-context-py,代码行数:56,代码来源:views.py

示例10: html_view

# 需要导入模块: from opencontext_py.libs.requestnegotiation import RequestNegotiation [as 别名]
# 或者: from opencontext_py.libs.requestnegotiation.RequestNegotiation import supported_types [as 别名]
def html_view(request, uuid, full_view=False):
    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)
    # Construnct the item
    ocitem = OCitem()
    ocitem.get_item(uuid)
    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
    request.uuid = ocitem.manifest.uuid
    request.project_uuid = ocitem.manifest.project_uuid
    request.item_type = ocitem.manifest.item_type
    rp = RootPath()
    base_url = rp.get_baseurl()
    temp_item = TemplateItem(request)
    temp_item.read_jsonld_dict(ocitem.json_ld)
    if full_view:
        template = loader.get_template('media/full.html')
    else:
        template = loader.get_template('media/view.html')
    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
    context = {
        'item': temp_item,
        'fullview': full_view,
        'base_url': base_url,
        'user': request.user
    }
    response = HttpResponse(template.render(context, request))
    patch_vary_headers(response, ['accept', 'Accept', 'content-type'])
    return response
开发者ID:ekansa,项目名称:open-context-py,代码行数:55,代码来源:views.py

示例11: index_json

# 需要导入模块: from opencontext_py.libs.requestnegotiation import RequestNegotiation [as 别名]
# 或者: from opencontext_py.libs.requestnegotiation.RequestNegotiation import supported_types [as 别名]
def index_json(request):
    spatial_context=None
    rp = RootPath()
    base_url = rp.get_baseurl()
    rd = RequestDict()
    request_dict_json = rd.make_request_dict_json(request,
                                                  spatial_context)
    url = request.get_full_path()
    if 'http://' not in url \
       and 'https://' not in url:
        url = base_url + url
    if '?' in url:
        json_url = url.replace('?', '.json?')
    else:
        json_url = url + '.json'
    json_url = json_url.replace('/projects/.json', '')
    solr_s = SolrSearch()
    solr_s.do_context_paths = False
    solr_s.item_type_limit = 'projects'
    if solr_s.solr is not False:
        response = solr_s.search_solr(request_dict_json)
        m_json_ld = MakeJsonLd(request_dict_json)
        m_json_ld.base_search_link = '/projects/'
        # share entities already looked up. Saves database queries
        m_json_ld.entities = solr_s.entities
        m_json_ld.request_full_path = request.get_full_path()
        m_json_ld.spatial_context = spatial_context
        json_ld = m_json_ld.convert_solr_json(response.raw_content)
        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:
            # requester wanted a mimetype we DO support
            return HttpResponse(json.dumps(json_ld,
                                ensure_ascii=False, indent=4),
                                content_type=req_neg.use_response_type + "; charset=utf8")
        else:
            # client wanted a mimetype we don't support
            return HttpResponse(req_neg.error_message,
                                status=415)
    else:
        template = loader.get_template('500.html')
        context = RequestContext(request,
                                 {'error': 'Solr Connection Problem'})
        return HttpResponse(template.render(context), status=503)
开发者ID:portableant,项目名称:open-context-py,代码行数:48,代码来源:views.py

示例12: index

# 需要导入模块: from opencontext_py.libs.requestnegotiation import RequestNegotiation [as 别名]
# 或者: from opencontext_py.libs.requestnegotiation.RequestNegotiation import supported_types [as 别名]
def index(request):
    """ Get the item context JSON-LD """
    oai_obj = OAIpmh()
    req_neg = RequestNegotiation('application/xml')
    req_neg.supported_types = ['application/xml']
    if 'HTTP_ACCEPT' in request.META:
        req_neg.check_request_support(request.META['HTTP_ACCEPT'])
    if req_neg.supported:
        # requester wanted a mimetype we DO support
        xml = oai_obj.process_request(request)
        return HttpResponse(oai_obj.output_xml_string(),
                            content_type=req_neg.use_response_type + "; charset=utf8",
                            status=oai_obj.http_resp_code)
    else:
        # client wanted a mimetype we don't support
        return HttpResponse(req_neg.error_message,
                            status=415)
开发者ID:ekansa,项目名称:open-context-py,代码行数:19,代码来源:views.py

示例13: search_view

# 需要导入模块: from opencontext_py.libs.requestnegotiation import RequestNegotiation [as 别名]
# 或者: from opencontext_py.libs.requestnegotiation.RequestNegotiation import supported_types [as 别名]
def search_view(request):
    """ Get the search context JSON-LD """
    search_context_obj = SearchContext()
    json_ld = LastUpdatedOrderedDict()
    json_ld['@context'] = search_context_obj.context
    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:
        # requester wanted a mimetype we DO support
        return HttpResponse(json.dumps(json_ld,
                            ensure_ascii=False, indent=4),
                            content_type=req_neg.use_response_type + "; charset=utf8")
    else:
        # client wanted a mimetype we don't support
        return HttpResponse(req_neg.error_message,
                            status=415)
开发者ID:mfindeisen,项目名称:open-context-py,代码行数:20,代码来源:views.py

示例14: json_view

# 需要导入模块: from opencontext_py.libs.requestnegotiation import RequestNegotiation [as 别名]
# 或者: from opencontext_py.libs.requestnegotiation.RequestNegotiation import supported_types [as 别名]
def json_view(request, uuid):
    ocitem = OCitem()
    ocitem.get_item(uuid)
    if ocitem.manifest is not False:
        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
开发者ID:portableant,项目名称:open-context-py,代码行数:20,代码来源:views.py

示例15: html_view

# 需要导入模块: from opencontext_py.libs.requestnegotiation import RequestNegotiation [as 别名]
# 或者: from opencontext_py.libs.requestnegotiation.RequestNegotiation import supported_types [as 别名]
def html_view(request, uuid):
    ocitem = OCitem()
    ocitem.get_item(uuid)
    if ocitem.manifest is not False:
        # check to see if there's related data via API calls. Add if so.
        subj_s = SubjectSupplement(ocitem.json_ld)
        ocitem.json_ld = subj_s.get_catal_related()
        rp = RootPath()
        base_url = rp.get_baseurl()
        temp_item = TemplateItem(request)
        temp_item.read_jsonld_dict(ocitem.json_ld)
        template = loader.get_template('subjects/view.html')
        if temp_item.view_permitted:
            req_neg = RequestNegotiation('text/html')
            req_neg.supported_types = ['application/json',
                                       'application/ld+json',
                                       'application/vnd.geo+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})
            return HttpResponse(template.render(context), status=401)
    else:
        raise Http404
开发者ID:mfindeisen,项目名称:open-context-py,代码行数:44,代码来源:views.py


注:本文中的opencontext_py.libs.requestnegotiation.RequestNegotiation.supported_types方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。