Пример #1
0
def index_view(request):
    """ Get the search context JSON-LD """
    request = RequestNegotiation().anonymize_request(request)
    rp = RootPath()
    base_url = rp.get_baseurl()
    req_neg = RequestNegotiation('text/html')
    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
        open_graph = {
            'twitter_site': settings.TWITTER_SITE,
            'type': 'website',
            'url': base_url + '/about/',
            'site_name': settings.CANONICAL_SITENAME,
            'description': 'Video and introduction to Open Context, an open-access '
                           'data publication service for archaeology ',
            'image': base_url + '/static/oc/images/index/oc-blue-square-logo.png',
            'video': 'https://opencontext.wistia.com/medias/s0g0fsyqkz'
        }
        template = loader.get_template('about/index.html')
        context = {
            'base_url': base_url,
            'page_title': 'Open Context: About',
            'act_nav': 'about',
            'og': open_graph,
            '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,
                            status=415)
Пример #2
0
 def parse_json_option(self, json_option):
     """ parses json option to populate
         this object
     """
     if 'id' in json_option:
         self.id = json_option['id']
     if 'json' in json_option:
         self.json = json_option['json']
     if 'label' in json_option:
         self.label = json_option['label']
     if 'count' in json_option:
         self.count = json_option['count']
     if 'slug' in json_option:
         self.slug = json_option['slug']
     if 'rdfs:isDefinedBy' in json_option:
         if 'http://' in json_option['rdfs:isDefinedBy'] \
            or 'https://' in json_option['rdfs:isDefinedBy']:
             # assign this to a subheading
             self.set_sub_heading(json_option['rdfs:isDefinedBy'])
             rp = RootPath()
             self.defined_by = rp.convert_local_url(json_option['rdfs:isDefinedBy'])
     self.dom_id = self.dom_id_prefix + '---' + str(self.slug)
     # check to see if we should show this, based in if this is a related property
     # and if self.item_type_limited is False
     self.check_show_related_options()
Пример #3
0
def field_complex_descriptions(request, source_id):
    """ Show HTML form to change group descriptive
        properties together into groups of
        complex descriptions
    """
    if not request.user.is_superuser:
        return HttpResponse('Unauthorized', status=401)
    else:
        rp = RootPath()
        base_url = rp.get_baseurl()
        ip = ImportProfile(source_id)
        if ip.project_uuid is not False:
            ip.get_fields()
            if len(ip.fields) > 0:
                ip.get_field_annotations()
                ip.jsonify_field_annotations()
                imnav = ImportNavigation()
                ip.nav = imnav.set_nav('field-entity-relations',
                                       ip.project_uuid,
                                       source_id)
                template = loader.get_template('imports/field-entity-relations.html')
                context = {
                    'ip': ip,
                    'base_url': base_url,
                    'user': request.user
                }
                return HttpResponse(template.render(context, request))
            else:
                redirect = '../../imports/field-types/' + source_id
                return HttpResponseRedirect(redirect)
        else:
            raise Http404
Пример #4
0
 def __init__(self, id_href=True):
     self.id = self.DOI  # DOI for this
     rp = RootPath()
     base_url = rp.get_baseurl()
     self.href = base_url + '/contexts/item.json'  # URL for this
     if id_href:
         self.id = self.href
     context = LastUpdatedOrderedDict()
     context['rdf'] = 'http://www.w3.org/1999/02/22-rdf-syntax-ns#'
     context['rdfs'] = 'http://www.w3.org/2000/01/rdf-schema#'
     context['xsd'] = 'http://www.w3.org/2001/XMLSchema#'
     context['skos'] = 'http://www.w3.org/2004/02/skos/core#'
     context['owl'] = 'http://www.w3.org/2002/07/owl#'
     context['dc-terms'] = 'http://purl.org/dc/terms/'
     context['dcmi'] = 'http://dublincore.org/documents/dcmi-terms/'
     context['bibo'] = 'http://purl.org/ontology/bibo/'
     context['foaf'] = 'http://xmlns.com/foaf/0.1/'
     context['cidoc-crm'] = 'http://erlangen-crm.org/current/'
     context['dcat'] = 'http://www.w3.org/ns/dcat#'
     context['geojson'] = 'http://ld.geojson.org/vocab#'
     context['cc'] = 'http://creativecommons.org/ns#'
     context['oc-gen'] = 'http://opencontext.org/vocabularies/oc-general/'
     context['oc-pred'] = 'http://opencontext.org/predicates/'
     context['id'] = '@id'
     context['label'] = 'rdfs:label'
     context['uuid'] = 'dc-terms:identifier'
     context['slug'] = 'oc-gen:slug'
     context['type'] = '@type'
     context['category'] = {'@id': 'oc-gen:category', '@type': '@id'}
     context['Feature'] = 'geojson:Feature'
     context['FeatureCollection'] = 'geojson:FeatureCollection'
     context['GeometryCollection'] = 'geojson:GeometryCollection'
     context['Instant'] = 'http://www.w3.org/2006/time#Instant'
     context['Interval'] = 'http://www.w3.org/2006/time#Interval'
     context['LineString'] = 'geojson:LineString'
     context['MultiLineString'] = 'geojson:MultiLineString'
     context['MultiPoint'] = 'geojson:MultiPoint'
     context['MultiPolygon'] = 'geojson:MultiPolygon'
     context['Point'] = 'geojson:Point'
     context['Polygon'] = 'geojson:Polygon'
     context['bbox'] = {'@id': 'geojson:bbox', '@container': '@list'}
     context['circa'] = 'geojson:circa'
     context['coordinates'] = 'geojson:coordinates'
     context['datetime'] = 'http://www.w3.org/2006/time#inXSDDateTime'
     context['description'] = 'dc-terms:description'
     context['features'] = {'@id': 'geojson:features', '@container': '@set'}
     context['geometry'] = 'geojson:geometry'
     context['properties'] = 'geojson:properties'
     context['start'] = 'http://www.w3.org/2006/time#hasBeginning'
     context['stop'] = 'http://www.w3.org/2006/time#hasEnding'
     context['title'] = 'dc-terms:title'
     context['when'] = 'geojson:when'
     context['reference-type'] = {'@id': 'oc-gen:reference-type', '@type': '@id'}
     context['inferred'] = 'oc-gen:inferred'
     context['specified'] = 'oc-gen:specified'
     context['reference-uri'] = 'oc-gen:reference-uri'
     context['reference-label'] = 'oc-gen:reference-label'
     context['location-precision'] = 'oc-gen:location-precision'
     context['location-note'] = 'oc-gen:location-note'
     self.context = context
Пример #5
0
def pub_view(request):
    """ Get publishing overview page """
    request = RequestNegotiation().anonymize_request(request)
    rp = RootPath()
    base_url = rp.get_baseurl()
    req_neg = RequestNegotiation('text/html')
    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
        open_graph = {
            'twitter_site': settings.TWITTER_SITE,
            'type': 'website',
            'url': base_url + '/about/publishing',
            'site_name': settings.CANONICAL_SITENAME,
            'description': 'How to publish archaeological research data '\
                           'with Open Context',
            'image': base_url + '/static/oc/images/index/oc-blue-square-logo.png',
            'video': False
        }
        template = loader.get_template('about/publishing.html')
        context = {
            'base_url': base_url,
            'page_title': 'Open Context: About - Publishing',
            'act_nav': 'about',
            'og': open_graph,
            '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,
                            status=415)
Пример #6
0
def finalize(request, source_id):
    """ Show HTML form to change relationships for entities
        to be created / or updated from an import table
    """
    if not request.user.is_superuser:
        return HttpResponse('Unauthorized', status=401)
    else:
        rp = RootPath()
        base_url = rp.get_baseurl()
        ip = ImportProfile(source_id)
        if ip.project_uuid is not False:
            ip.get_fields()
            imnav = ImportNavigation()
            ip.nav = imnav.set_nav('finalize',
                                   ip.project_uuid,
                                   source_id)
            template = loader.get_template('imports/finalize.html')
            context = {
                'ip': ip,
                'base_url': base_url,
                'user': request.user
            }
            return HttpResponse(template.render(context, request))
        else:
            raise Http404
Пример #7
0
def bibliography_view(request):
    """ Get page about bibliography / publications """
    request = RequestNegotiation().anonymize_request(request)
    rp = RootPath()
    base_url = rp.get_baseurl()
    req_neg = RequestNegotiation('text/html')
    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
        open_graph = {
            'twitter_site': settings.TWITTER_SITE,
            'type': 'website',
            'url': base_url + '/about/bibliography',
            'site_name': settings.CANONICAL_SITENAME,
            'description': 'Publications related to Open Context and its '\
                           'contributions to research data management, '\
                           'archaeological ethics, scholarly communications, and '\
                           'professional practice',
            'image': base_url + '/static/oc/images/index/oc-blue-square-logo.png',
            'video': False
        }
        template = loader.get_template('about/bibliography.html')
        context = {
            'base_url': base_url,
            'page_title': 'Open Context: About - Bibliography',
            'og': open_graph,
            'act_nav': 'about',
            '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,
                            status=415)
Пример #8
0
def sponsors_view(request):
    """ Get the page about sponsors """
    request = RequestNegotiation().anonymize_request(request)
    rp = RootPath()
    base_url = rp.get_baseurl()
    req_neg = RequestNegotiation('text/html')
    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
        open_graph = {
            'twitter_site': settings.TWITTER_SITE,
            'type': 'website',
            'url': base_url + '/about/sponsors',
            'site_name': settings.CANONICAL_SITENAME,
            'description': 'Sources of financial support for '\
                           'Open Context and collaborative institutions providing '\
                           'complementary services',
            'image': base_url + '/static/oc/images/index/oc-blue-square-logo.png',
            'video': False
        }
        template = loader.get_template('about/sponsors.html')
        context = {
            'base_url': base_url,
            'page_title': 'Open Context: About - Intellectual Property',
            'og': open_graph,
            'act_nav': 'about',
            '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,
                            status=415)
Пример #9
0
 def __init__(self, uuid=None, request=None):
     self.id_href = False  # if True, use the local href as the Context's ID, 
     self.context_path = '/contexts/projects/'  # path for the ID of the context resource
     self.uuid = uuid
     rp = RootPath()
     self.base_url = rp.get_baseurl()
     self.manifest = False
     self.project_obj = False
     self.edit_status = 0
     self.edit_permitted = False
     self.view_permitted = True
     self.assertion_hashes = False
     self.id = False
     self.href = False
     self.cannonical_href = False
     self.json_ld = False
     self.errors = []
     self.pred_sql_dict_list = None
     self.most_recent_date = None
     self.refresh_cache = False
     if uuid is not None:
         if uuid is False or uuid == '0' or uuid == 'open-context':
             self.uuid = '0'
             self.manifest = Manifest()
             self.manifest.uuid = '0'
             self.manifest.project_uuid = '0'
             self.manifest.label = 'Open Context (General)'
             self.manifest.item_type = 'projects'
         else:
             self.dereference_uuid_or_slug(uuid)
             self.set_uri_urls(self.uuid)
             if request is not None:
                 self.check_permissions(request)
Пример #10
0
def services_view(request):
    """ Get page documenting the API """
    request = RequestNegotiation().anonymize_request(request)
    rp = RootPath()
    base_url = rp.get_baseurl()
    req_neg = RequestNegotiation('text/html')
    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
        open_graph = {
            'twitter_site': settings.TWITTER_SITE,
            'type': 'website',
            'url': base_url + '/about/technology',
            'site_name': settings.CANONICAL_SITENAME,
            'description': 'Overview of the APIs (machine-readable data) '\
                           'offered by Open Context to promote '\
                           'interoperability and new uses of data',
            'image': base_url + '/static/oc/images/index/oc-blue-square-logo.png',
            'video': False
        }
        template = loader.get_template('about/services.html')
        context = {
            'base_url': base_url,
            'page_title': 'Open Context: About - Web Services and APIs',
            'og': open_graph,
            'act_nav': 'about',
            'nav_items': settings.NAV_ITEMS
        }
        return HttpResponse(template.render(context))
    else:
        # client wanted a mimetype we don't support
        return HttpResponse(req_neg.error_message,
                            status=415)
Пример #11
0
 def __init__(self, id_href=True):
     self.id = self.DOI  # DOI for this
     rp = RootPath()
     base_url = rp.get_baseurl()
     self.href = base_url + '/contexts/search.json'  # URL for this
     if id_href:
         self.id = self.href
     item_context_obj = ItemContext()
     context = item_context_obj.context
     self.geo_json_context = GeneralContext.GEO_JSON_CONTEXT_URI # link to geojson
     context['opensearch'] = 'http://a9.com/-/spec/opensearch/1.1/'
     context['totalResults'] = {'@id': 'opensearch:totalResults', '@type': 'xsd:integer'}
     context['startIndex'] = {'@id': 'opensearch:startIndex', '@type': 'xsd:integer'}
     context['itemsPerPage'] = {'@id': 'opensearch:itemsPerPage', '@type': 'xsd:integer'}
     context['oc-api'] = 'http://opencontext.org/vocabularies/oc-api/'
     context['oai-pmh'] = 'http://www.openarchives.org/OAI/2.0/'
     context['rdfs:isDefinedBy'] = {'@type': '@id'}
     context['first'] = {'@id': 'oc-api:first', '@type': '@id'}
     context['previous'] = {'@id': 'oc-api:previous', '@type': '@id'}
     context['next'] = {'@id': 'oc-api:next', '@type': '@id'}
     context['last'] = {'@id': 'oc-api:last', '@type': '@id'}
     context['first-json'] = {'@id': 'oc-api:first', '@type': '@id'}
     context['previous-json'] = {'@id': 'oc-api:previous', '@type': '@id'}
     context['next-json'] = {'@id': 'oc-api:next', '@type': '@id'}
     context['last-json'] = {'@id': 'oc-api:last', '@type': '@id'}
     context['count'] = {'@id': 'oc-api:count', '@type': 'xsd:integer'}
     self.context = context
Пример #12
0
def field_entity_relations(request, source_id):
    """ Show HTML form to change relationships for entities
        to be created / or updated from an import table
    """
    if not request.user.is_superuser:
        return HttpResponse('Unauthorized', status=401)
    else:
        rp = RootPath()
        base_url = rp.get_baseurl()
        ip = ImportProfile(source_id)
        if ip.project_uuid is not False:
            ip.get_fields()
            if len(ip.fields) > 0:
                ip.get_field_annotations()
                ip.jsonify_field_annotations()
                imnav = ImportNavigation()
                ip.nav = imnav.set_nav('field-entity-relations',
                                       ip.project_uuid,
                                       source_id)
                template = loader.get_template('imports/field-entity-relations.html')
                context = RequestContext(request,
                                         {'ip': ip,
                                          'base_url': base_url})
                return HttpResponse(template.render(context))
            else:
                redirect = '../../imports/field-types/' + source_id
                return HttpResponseRedirect(redirect)
        else:
            raise Http404
Пример #13
0
def index(request):
    """ Get the search context JSON-LD """
    rp = RootPath()
    base_url = rp.get_baseurl()
    req_neg = RequestNegotiation("text/html")
    old_view = False
    template = loader.get_template("index/view.html")
    if "test" in request.GET:
        template = loader.get_template("index/view-initial-minimal.html")
        old_view = True
    context = RequestContext(
        request,
        {
            "base_url": base_url,
            "old_view": old_view,
            "page_title": "Open Context: Publisher of Research Data",
            "act_nav": "home",
            "nav_items": settings.NAV_ITEMS,
        },
    )
    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(template.render(context))
    else:
        # client wanted a mimetype we don't support
        return HttpResponse(template.render(context), status=415)
Пример #14
0
def profile_edit(request, profile_uuid):
    """ Handles JSON requests for a profile
    """
    ipt = InputProfileTemplating()
    exists = ipt.check_exists(profile_uuid)
    if exists:
        # now check to see if the we have edit permissions
        proj_inp = ProjectInputs(ipt.project_uuid, request)
        if proj_inp.edit_permitted or request.user.is_superuser:
            rp = RootPath()
            base_url = rp.get_baseurl()
            temp_item = {'uuid': ipt.uuid,
                         'label': ipt.inp_prof.label,
                         'project_uuid': ipt.project_uuid,
                         'project': ipt.project,
                         'context': False,
                         'act_nav': 'profiles'}
            template = loader.get_template('edit/profiles/profile-edit.html')
            context = RequestContext(request,
                                     {'item': temp_item,
                                      'super_user': request.user.is_superuser,
                                      'icons': ItemBasicEdit.UI_ICONS,
                                      'field_group_vis': InputFieldGroup.GROUP_VIS,
                                      'base_url': base_url})
            return HttpResponse(template.render(context))
        else:
            json_output = json.dumps({'error': 'edit permission required'},
                                     indent=4,
                                     ensure_ascii=False)
            return HttpResponse(json_output,
                                content_type='application/json; charset=utf8',
                                status=401)
    else:
        raise Http404
Пример #15
0
 def __init__(self):
     rp = RootPath()
     base_url = rp.get_baseurl()
     self.href = base_url + '/about/estimate'  # URL for this
     self.estimate_id = False
     self.user_name = ''
     self.user_email = False
     # self.user_phone = ''
     self.project_name = ''
     self.is_grad_student = False
     self.duration = 0
     self.count_spec_datasets = 0
     self.count_tables = 0
     self.count_images = 0
     self.count_docs = 0
     self.count_gis = 0
     self.count_other = 0
     self.comments = ''
     self.license_uri = False
     self.license_label = ''
     self.license_note = ''
     self.base_cost = 250  # minimum cost for publishing
     self.max_cost = 7750  # maximum cost for an estimate
     self.image_cost = 5
     self.other_cost = 20
     self.doc_cost = 15
     self.gis_cost = 25
     self.raw_cost = 0
     self.errors = []
Пример #16
0
def html_view(request, uuid):
    ocitem = OCitem()
    ocitem.get_item(uuid, True)
    if(ocitem.manifest is not False):
        rp = RootPath()
        base_url = rp.get_baseurl()
        temp_item = TemplateItem()
        temp_item.read_jsonld_dict(ocitem.json_ld)
        template = loader.get_template('projects/view.html')
        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:
        raise Http404
Пример #17
0
def field_types_more(request, source_id):
    """ Show HTML form further classifying subject fields """
    if not request.user.is_superuser:
        return HttpResponse('Unauthorized', status=401)
    else:
        rp = RootPath()
        base_url = rp.get_baseurl()
        ip = ImportProfile(source_id)
        if ip.project_uuid is not False:
            ip.get_subject_type_fields()
            imnav = ImportNavigation()
            ip.nav = imnav.set_nav('field-types-more',
                                   ip.project_uuid,
                                   source_id)
            if len(ip.fields) > 0:
                template = loader.get_template('imports/field-types-more.html')
                context = {
                    'ip': ip,
                    'base_url': base_url,
                    'user': request.user
                }
                return HttpResponse(template.render(context, request))
            else:
                redirect = '../../imports/field-types/' + source_id
                return HttpResponseRedirect(redirect)
        else:
            raise Http404
Пример #18
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()
        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
Пример #19
0
 def __init__(self):
     self.proj_context_json_ld = None
     self.project_uuid = None
     self.manifest = None
     self.assertion_hashes = False
     self.assertions = None
     self.mediafiles = None
     self.link_annotations = None
     self.stable_ids = None
     self.obs_list = []
     self.item_pred_objs = {} # predicate entity objects, with uuid as a key 
     self.string_obj_dict = {}  # OCstring objects, in a dict, with uuid as key
     self.manifest_obj_dict = {}  # manifest objects, in a dict with uuid as key
     self.assertion_author_uuids = {
         # uuids of DC contribuors (persons/orgs) found in item assertions
         ItemKeys.PREDICATES_DCTERMS_CONTRIBUTOR: [],
         # uuids of DC creators (persons/orgs) found in item assertions
         ItemKeys.PREDICATES_DCTERMS_CREATOR: []
     }
     self.dc_assertions = {}  # dublin core assertions. We add these last, just for aesthetics
     self.dc_title = None  # dublin core title attribute, to use if not via default programatic way
     dc_terms_obj = DCterms()
     self.dc_metadata_preds = dc_terms_obj.get_dc_terms_list()
     self.dc_author_preds = dc_terms_obj.get_dc_authors_list()
     self.dc_inherit_preds = [  # these are dc-terms predicates items can inherit from a project
         ItemKeys.PREDICATES_DCTERMS_CONTRIBUTOR,
         ItemKeys.PREDICATES_DCTERMS_CREATOR,
         ItemKeys.PREDICATES_DCTERMS_TEMPORAL,
         ItemKeys.PREDICATES_DCTERMS_LICENSE
     ]
     self.item_gen_cache = ItemGenerationCache()
     rp = RootPath()
     self.base_url = rp.get_baseurl()
     self.class_uri_list = []  # uris of item classes used in this item
     self.parent_context_list = []  # list of parent context labels, used for making a dc-terms:Title
Пример #20
0
def recipes_view(request):
    """ Get page about recipes using the API """
    request = RequestNegotiation().anonymize_request(request)
    rp = RootPath()
    base_url = rp.get_baseurl()
    req_neg = RequestNegotiation('text/html')
    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
        open_graph = {
            'twitter_site': settings.TWITTER_SITE,
            'type': 'website',
            'url': base_url + '/about/recipes',
            'site_name': settings.CANONICAL_SITENAME,
            'description': 'Specific guidance on the use of Open Context APIs '\
                           '(machine-readable data) to meet certain data '\
                           'management needs',
            'image': base_url + '/static/oc/images/index/oc-blue-square-logo.png',
            'video': False
        }
        template = loader.get_template('about/recipes.html')
        context = {
            'base_url': base_url,
            'page_title': 'Open Context: About - API Cookbook',
            'og': open_graph,
            'act_nav': 'about',
            'nav_items': settings.NAV_ITEMS
        }
        return HttpResponse(template.render(context))
    else:
        # client wanted a mimetype we don't support
        return HttpResponse(req_neg.error_message,
                            status=415)
Пример #21
0
 def __init__(self, json_ld):
     if isinstance(json_ld, dict):
         self.json_ld = json_ld
         self.ok = True
     else:
         self.ok = False
     self.id = None  # the search ID (url of the current results)
     self.geotile_scope = ''  # geo-tile applicable to all data
     self.total_count = 0
     self.start_num = 0
     self.end_num = 0
     self.items_per_page = 0
     self.response_tile_zoom = 0
     # is the item_type_limit is in effect ?
     self.item_type_limited = False
     self.subjects_link = False
     self.filters = []
     self.paging = {}
     self.num_facets = []
     self.date_facets = []
     self.facets = []
     self.geo_records = []
     self.text_search = []
     self.active_sort = {}
     self.sort_options = []
     self.project_layers = False
     self.nav_items = settings.NAV_ITEMS
     self.human_remains_ok = False  # are we explicitly allowing display of human remains?
     self.human_remains_flag = False  # default to NO human remains flagged records in view
     rp = RootPath()
     self.base_url = rp.get_baseurl()
Пример #22
0
def ip_view(request):
    """ Get page about IP policies """
    request = RequestNegotiation().anonymize_request(request)
    rp = RootPath()
    base_url = rp.get_baseurl()
    req_neg = RequestNegotiation('text/html')
    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
        open_graph = {
            'twitter_site': settings.TWITTER_SITE,
            'type': 'website',
            'url': base_url + '/about/intellectual-property',
            'site_name': settings.CANONICAL_SITENAME,
            'description': 'Intellectual property policies for Open Context and '\
                           'ethical guidance for contributors and users of '\
                           'archaeological research data',
            'image': base_url + '/static/oc/images/index/oc-blue-square-logo.png',
            'video': False
        }
        template = loader.get_template('about/intellectual-property.html')
        context = {
            'base_url': base_url,
            'page_title': 'Open Context: About - Intellectual Property',
            'og': open_graph,
            'act_nav': 'about',
            'nav_items': settings.NAV_ITEMS
        }
        return HttpResponse(template.render(context))
    else:
        # client wanted a mimetype we don't support
        return HttpResponse(req_neg.error_message,
                            status=415)
Пример #23
0
def field_types_more(request, source_id):
    """ Show HTML form further classifying subject fields """
    if not request.user.is_superuser:
        return HttpResponse('Unauthorized', status=401)
    else:
        rp = RootPath()
        base_url = rp.get_baseurl()
        ip = ImportProfile(source_id)
        if ip.project_uuid is not False:
            ip.get_subject_type_fields()
            imnav = ImportNavigation()
            ip.nav = imnav.set_nav('field-types-more', ip.project_uuid,
                                   source_id)
            if len(ip.fields) > 0:
                template = loader.get_template('imports/field-types-more.html')
                context = {
                    'ip': ip,
                    'base_url': base_url,
                    'user': request.user
                }
                return HttpResponse(template.render(context, request))
            else:
                redirect = '../../imports/field-types/' + source_id
                return HttpResponseRedirect(redirect)
        else:
            raise Http404
Пример #24
0
def terms_view(request):
    """ Get the page about Terms """
    request = RequestNegotiation().anonymize_request(request)
    rp = RootPath()
    base_url = rp.get_baseurl()
    req_neg = RequestNegotiation('text/html')
    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
        open_graph = {
            'twitter_site': settings.TWITTER_SITE,
            'type': 'website',
            'url': base_url + '/about/terms',
            'site_name': settings.CANONICAL_SITENAME,
            'description': 'Terms and Conditions of Use, and '\
                           'Privacy Policies for Open Context',
            'image': base_url + '/static/oc/images/index/oc-blue-square-logo.png',
            'video': False
        }
        template = loader.get_template('about/terms.html')
        context = {
            'base_url': base_url,
            'page_title': 'Open Context: About - Terms of Use and Privacy Policies',
            'og': open_graph,
            'act_nav': 'about',
            'nav_items': settings.NAV_ITEMS
        }
        return HttpResponse(template.render(context))
    else:
        # client wanted a mimetype we don't support
        return HttpResponse(req_neg.error_message,
                            status=415)
Пример #25
0
def estimate_view(request):
    """ Get page with publication project cost estimation """
    rp = RootPath()
    base_url = rp.get_baseurl()
    req_neg = RequestNegotiation('text/html')
    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
        open_graph = {
            'twitter_site': settings.TWITTER_SITE,
            'type': 'website',
            'url': base_url + '/about/estimate',
            'site_name': settings.CANONICAL_SITENAME,
            'description': 'Estimate data publication and archiving '\
                           'costs with Open Context to help budget for '\
                           'grant data management plans',
            'image': base_url + '/static/oc/images/index/oc-blue-square-logo.png',
            'video': False
        }
        template = loader.get_template('about/estimate.html')
        context = {
            'base_url': base_url,
            'page_title': 'Open Context: About - Cost Estimate',
            'og': open_graph,
            'act_nav': 'about',
            '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,
                            status=415)
Пример #26
0
def index(request):
    """ redirects requests from the projects index
        to the project-search view
    """
    rp = RootPath()
    base_url = rp.get_baseurl()
    new_url =  base_url + '/projects-search/'
    return redirect(new_url, permanent=True)
Пример #27
0
def index(request):
    """ redirects requests from the media index
        to the media-search view
    """
    rp = RootPath()
    base_url = rp.get_baseurl()
    new_url = base_url + '/search/?type=documents'
    return redirect(new_url, permanent=True)
Пример #28
0
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)
Пример #29
0
def index(request):
    """ redirects requests from the media index
        to the media-search view
    """
    request = RequestNegotiation().anonymize_request(request)
    rp = RootPath()
    base_url = rp.get_baseurl()
    new_url = base_url + '/search/?type=documents'
    return redirect(new_url, permanent=True)
Пример #30
0
def index(request):
    """ redirects requests from the projects index
        to the project-search view
    """
    request = RequestNegotiation().anonymize_request(request)
    rp = RootPath()
    base_url = rp.get_baseurl()
    new_url = base_url + '/projects-search/'
    return redirect(new_url, permanent=True)
Пример #31
0
def index(request):
    """ Redirects requests from the media index
        to the media-search view
    """
    request = RequestNegotiation().anonymize_request(request)
    rp = RootPath()
    base_url = rp.get_baseurl()
    new_url =  base_url + '/media-search/'
    return redirect(new_url, permanent=True)
Пример #32
0
 def __init__(self, request_dict_json=False):
     self.uuid = False
     self.uri = False  # cannonical uri for the item
     self.href = False  # link to the item in the current deployment
     self.cite_uri = False  # stable / persistent uri
     self.label = False
     self.item_type = False
     self.updated = False
     self.published = False
     self.project_href = False  # link to the project in current deployment
     self.project_uri = False  # cannonical uri for the project
     self.project_label = False
     self.context_href = False  # link to parent context in current deployment
     self.context_uri = False  # link to parent context cannonical uri
     self.context_label = False
     self.category = False
     self.latitude = False
     self.longitude = False
     self.geojson = False
     self.early_date = False
     self.late_date = False
     self.human_remains_flagged = False  # flagged as relating to human remains
     self.thumbnail_href = False
     self.thumbnail_uri = False
     self.thumbnail_scr = False
     self.preview_scr = False
     self.fullfile_scr = False
     self.snippet = False
     self.cite_uri = False  # stable identifier as an HTTP uri
     self.other_attributes = False  # other attributes to the record
     # flatten list of an attribute values to single value
     self.flatten_rec_attributes = False
     # A list of (non-standard) attributes to include in a record
     self.rec_attributes = []
     self.attribute_hierarchies = {}
     self.base_url = settings.CANONICAL_HOST
     rp = RootPath()
     self.base_url = rp.get_baseurl()
     self.m_cache = MemoryCache()  # memory caching object
     self.s_cache = SearchGenerationCache(
     )  # supplemental caching object, specific for searching
     self.request_dict_json = request_dict_json
     if request_dict_json is not False:
         self.request_dict = json.loads(request_dict_json)
     else:
         self.request_dict = False
     self.add_attribute_uris = False
     if self.request_dict and self.request_dict.get('add-attribute-uris'):
         self.add_attribute_uris = True
     self.highlighting = False
     self.recursive_count = 0
     self.min_date = False
     self.max_date = False
     self.thumbnail_data = {}
     self.media_file_data = {}
     self.string_attrib_data = {}
Пример #33
0
 def __init__(self, cannonical_uris=False):
     self.cannonical_uris = cannonical_uris
     self.cache_use = CacheUtilities()
     dc_terms_obj = DCterms()
     self.dc_metadata_preds = dc_terms_obj.get_dc_terms_list()
     rp = RootPath()
     if self.cannonical_uris:
         self.base_url = rp.cannonical_host
     else:
         self.base_url = rp.get_baseurl()
Пример #34
0
 def __init__(self, json_ld):
     rp = RootPath()
     self.base_url = rp.get_baseurl()
     if isinstance(json_ld, dict):
         self.json_ld = json_ld
         self.ok = True
     else:
         self.ok = False
     self.raw_records = []
     self.records = []
Пример #35
0
 def __init__(self,
              request_dict=None,
              current_filters_url=None,
              base_search_url='/search/'):
     rp = RootPath()
     self.base_url = rp.get_baseurl()
     self.base_search_url = base_search_url
     self.request_dict = copy.deepcopy(request_dict)
     self.current_filters_url = current_filters_url
     self.doc_formats = configs.REQUEST_URL_FORMAT_EXTENTIONS
Пример #36
0
 def __init__(self):
     self.entries_per_page = self.DEFAULT_ENTRIES_PER_PAGE
     self.page = self.DEFAULT_PAGE
     self.count = 0
     self.updated = False
     self.last_page = False
     rp = RootPath()
     self.base_url = rp.get_baseurl()
     self.projects_list = []
     self.limit_item_types = []
Пример #37
0
 def __init__(self):
     self.item_gen_cache = ItemGenerationCache()
     rp = RootPath()
     self.base_url = rp.get_baseurl()
     self.class_uri_list = []  # uris of item classes used in this item
     self.manifest_obj_dict = {}  # manifest objects, in a dict with uuid as key
     self.proj_context_json_ld = {}  # general project context JSON-LD, with @graph of predicates, types
     self.stable_id_predicate = False  # predicate to use to add a stable ID to an entity
     self.stable_id_prefix_limit = False  # limit adding stable ID to the following URI prefix
     self.predicate_uri_as_stable_id = False  # add the predicate full URI as a stable id with the stable_id_predicate
Пример #38
0
 def __init__(self, json_ld):
     rp = RootPath()
     self.base_url = rp.get_baseurl()
     if isinstance(json_ld, dict):
         self.json_ld = json_ld
         self.ok = True
     else:
         self.ok = False
     self.raw_records = []
     self.records = []
Пример #39
0
 def __init__(self):
     self.entries_per_page = self.DEFAULT_ENTRIES_PER_PAGE
     self.page = self.DEFAULT_PAGE
     self.count = 0
     self.updated = False
     self.last_page = False
     rp = RootPath()
     self.base_url = rp.get_baseurl()
     self.projects_list = []
     self.limit_item_types = []
Пример #40
0
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
Пример #41
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
Пример #42
0
def old_redirect_view(request):
    """ Redirects from the original PHP version of
        Open Context when ".php" was in URLs
    """
    request = RequestNegotiation().anonymize_request(request)
    rp = RootPath()
    base_url = rp.get_baseurl()
    new_url = base_url + '/subjects-search/'
    if 'item' in request.GET:
        uuid = request.GET['item']
        new_url = base_url + '/subjects/' + uuid
    return redirect(new_url, permanent=True)
Пример #43
0
 def __init__(self, 
     request_dict=None, 
     current_filters_url=None, 
     base_search_url='/search/'
 ):
     rp = RootPath()
     self.base_url = rp.get_baseurl()
     self.base_search_url = base_search_url
     self.request_dict = copy.deepcopy(request_dict)
     if current_filters_url is None:
         current_filters_url = self.base_search_url
     self.current_filters_url = current_filters_url
Пример #44
0
 def __init__(self):
     self.request_errors = []
     self.done_urls = []
     self.follow_count = 200000
     self.start_time = 0
     self.delay_before_request = self.SLEEP_TIME
     rp = RootPath()
     self.base_url = rp.get_baseurl()
     self.urls = [
         (self.base_url + '/subjects-search/'),
         (self.base_url + '/media-search/'),
         (self.base_url + '/search/'),
     ]
Пример #45
0
 def get_thumbnail(self, solr_rec):
     """ get media record and thumbnai if it exists """
     if 'uuid' in solr_rec:
         uuid = solr_rec['uuid']
         if uuid in self.thumbnail_data:
             if self.thumbnail_data[uuid] is not False:
                 self.thumbnail_href = self.thumbnail_data[uuid]['href']
                 self.thumbnail_uri = self.thumbnail_data[uuid]['uri']
                 self.thumbnail_scr = self.thumbnail_data[uuid]['scr']
                 rp = RootPath()
                 self.thumbnail_scr = rp.convert_to_https(self.thumbnail_scr)
         else:
             # did not precache thumbnail data, get an indivitual record
             self.get_thumbnail_from_database(solr_rec)
Пример #46
0
 def get_media_files(self, solr_rec):
     """ get media record and thumbnai if it exists """
     if 'uuid' in solr_rec:
         uuid = solr_rec['uuid']
         if uuid in self.media_file_data:
             if self.media_file_data[uuid] is not False:
                 rp = RootPath()
                 for file_type, file_uri in self.media_file_data[uuid].items():
                     if file_type == 'oc-gen:thumbnail':
                         self.thumbnail_scr = rp.convert_to_https(file_uri)
                     elif file_type == 'oc-gen:preview':
                         self.preview_scr = rp.convert_to_https(file_uri)
                     elif file_type == 'oc-gen:fullfile':
                         self.fullfile_scr = rp.convert_to_https(file_uri)
Пример #47
0
 def __init__(self, request_dict=False):
     rp = RootPath()
     self.base_url = rp.get_baseurl()
     self.base_search_link = '/sets/'
     self.base_request = request_dict
     self.base_request_json = False
     self.base_r_full_path = False
     self.spatial_context = False
     self.testing = settings.DEBUG
     self.hierarchy_delim = '---'
     self.partial_param_val_match = False
     self.remove_start_param = True
     self.SOLR_FIELD_PARAM_MAPPINGS = self.BASE_SOLR_FIELD_PARAM_MAPPINGS
     for param_key, solr_field in DCterms.DC_META_FIELDS.items():
         self.SOLR_FIELD_PARAM_MAPPINGS[solr_field] = param_key
Пример #48
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
 def __init__(self,
              request_dict=None,
              current_filters_url=None,
              facet_fields_to_client_request={},
              base_search_url='/search/'):
     rp = RootPath()
     self.base_url = rp.get_baseurl()
     self.base_search_url = base_search_url
     self.request_dict = copy.deepcopy(request_dict)
     if current_filters_url is None:
         current_filters_url = self.base_search_url
     self.current_filters_url = current_filters_url
     # Dictionary of keyed by facet fields that are derived from the
     # raw request paths provided by clients. This dictionary makes
     # it easier to generate links for different facet options.
     self.facet_fields_to_client_request = facet_fields_to_client_request
Пример #50
0
 def __init__(self, id_href=True):
     self.id = self.DOI  # DOI for this
     rp = RootPath()
     base_url = rp.get_baseurl()
     self.href = base_url + '/contexts/item.json'  # URL for this
     if id_href:
         self.id = self.href
     gen_context = GeneralContext()
     context = gen_context.context
     self.geo_json_context = GeneralContext.GEO_JSON_CONTEXT_URI
     context['oc-gen:has-path-items'] = {'@container': '@list'}  # order of containment semantically important
     context['dc-terms:creator'] = {'@container': '@list'}  # order of authorship semantically important
     context['dc-terms:contributor'] = {'@container': '@list'}  # order of authorship semantically important
     context['oc-gen:has-path-items'] = {'@container': '@list'}
     # below are GeoJSON-LD context declarations, commented out to
     """
     context['Feature'] = 'geojson:Feature'
     context['FeatureCollection'] = 'geojson:FeatureCollection'
     context['GeometryCollection'] = 'geojson:GeometryCollection'
     context['LineString'] = 'geojson:LineString'
     context['MultiLineString'] = 'geojson:MultiLineString'
     context['MultiPoint'] = 'geojson:MultiPoint'
     context['MultiPolygon'] = 'geojson:MultiPolygon'
     context['Point'] = 'geojson:Point'
     context['Polygon'] = 'geojson:Polygon'
     context['bbox'] = {'@id': 'geojson:bbox', '@container': '@list'}
     context['coordinates'] = 'geojson:coordinates'
     context['features'] = {'@id': 'geojson:features', '@container': '@set'}
     context['geometry'] = 'geojson:geometry'
     context['properties'] = 'geojson:properties'
     """
     context['Instant'] = 'http://www.w3.org/2006/time#Instant'
     context['Interval'] = 'http://www.w3.org/2006/time#Interval'
     context['datetime'] = 'http://www.w3.org/2006/time#inXSDDateTime'
     context['circa'] = 'geojson:circa'
     context['start'] = 'http://www.w3.org/2006/time#hasBeginning'
     context['stop'] = 'http://www.w3.org/2006/time#hasEnding'
     context['when'] = 'geojson:when'
     context['title'] = 'dc-terms:title'
     context['reference-type'] = {'@id': 'oc-gen:reference-type', '@type': '@id'}
     context['inferred'] = 'oc-gen:inferred'
     context['specified'] = 'oc-gen:specified'
     context['reference-uri'] = 'oc-gen:reference-uri'
     context['reference-label'] = 'oc-gen:reference-label'
     context['location-precision'] = 'oc-gen:location-precision'
     context['location-note'] = 'oc-gen:location-note'
     self.context = context
Пример #51
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)
    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
    # check to see if there's related data via API calls. Add if so.
    request.uuid = ocitem.manifest.uuid
    request.project_uuid = ocitem.manifest.project_uuid
    request.item_type = ocitem.manifest.item_type
    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 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)
    # The client is allowd to see the current item.
    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
Пример #52
0
def query_html(request, spatial_context=None):
    """HTML representation for searching Open Context """

    request_dict = utilities.make_request_obj_dict(
        request, spatial_context=spatial_context)
    response_dict = process_solr_query(request_dict.copy())

    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'])

    # Associate the request media type with the request so we can
    # make sure that different representations of this resource get different
    # cache responses.
    request.content_type = req_neg.use_response_type
    if not req_neg.supported:
        # Client wanted a mimetype we don't support
        response = HttpResponse(req_neg.error_message,
                                content_type=req_neg.use_response_type +
                                "; charset=utf8",
                                status=415)
        patch_vary_headers(response, ['accept', 'Accept', 'content-type'])
        return response

    if req_neg.use_response_type.endswith('json'):
        return make_json_response(request, req_neg, response_dict)

    rp = RootPath()
    # Disable the search template and just use vue with the JSON
    # API.
    # search_temp = SearchTemplate(response_dict.copy())
    context = {
        'st': response_dict.copy(),
        'base_url': rp.get_baseurl(),
        'api_url': response_dict.get('id'),
        'configs': configs,
    }
    template = loader.get_template('search_vue/view.html')
    response = HttpResponse(template.render(context, request))
    patch_vary_headers(response, ['accept', 'Accept', 'content-type'])
    return response
Пример #53
0
def field_types(request, source_id):
    """ Show HTML form listing fields classified by field type """
    if not request.user.is_superuser:
        return HttpResponse('Unauthorized', status=401)
    else:
        rp = RootPath()
        base_url = rp.get_baseurl()
        ip = ImportProfile(source_id)
        if ip.project_uuid is not False:
            ip.get_fields()
            imnav = ImportNavigation()
            ip.nav = imnav.set_nav('field-types', ip.project_uuid, source_id)
            template = loader.get_template('imports/field-types.html')
            context = {'ip': ip, 'base_url': base_url, 'user': request.user}
            return HttpResponse(template.render(context, request))
        else:
            raise Http404
Пример #54
0
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)
Пример #55
0
 def __init__(self, request_dict_json=False):
     self.uuid = False
     self.uri = False  # cannonical uri for the item
     self.href = False  # link to the item in the current deployment
     self.cite_uri = False  # stable / persistent uri
     self.label = False
     self.item_type = False
     self.updated = False
     self.published = False
     self.project_href = False  # link to the project in current deployment
     self.project_uri = False  # cannonical uri for the project
     self.project_label = False
     self.context_href = False  # link to parent context in current deployment
     self.context_uri = False  # link to parent context cannonical uri
     self.context_label = False
     self.category = False
     self.latitude = False
     self.longitude = False
     self.geojson = False
     self.early_date = False
     self.late_date = False
     self.thumbnail_href = False
     self.thumbnail_uri = False
     self.thumbnail_scr = False
     self.snippet = False
     self.cite_uri = False  # stable identifier as an HTTP uri
     self.other_attributes = False  # other attributes to the record
     # flatten list of an attribute values to single value
     self.flatten_rec_attributes = False
     # A list of (non-standard) attributes to include in a record
     self.rec_attributes = []
     self.attribute_hierarchies = {}
     self.base_url = settings.CANONICAL_HOST
     rp = RootPath()
     self.base_url = rp.get_baseurl()
     self.entities = {}
     self.request_dict_json = request_dict_json
     if request_dict_json is not False:
         self.request_dict = json.loads(request_dict_json)
     else:
         self.request_dict = False
     self.highlighting = False
     self.recursive_count = 0
     self.min_date = False
     self.max_date = False
Пример #56
0
 def __init__(self):
     rp = RootPath()
     self.base_url = rp.get_baseurl()
     self.uri = None
     self.uuid = False
     self.vocab_uri = None
     self.json_obj = LastUpdatedOrderedDict()
     self.entity = None  # entity object for the concept or vocabulary item
     self.vocab_entity = None  # entity object for the parent vocabulary
     self.project_uuid = None
     self.version_control_uri = False  # uri to vocab version control
     self.default_comment = None
     self.comment = None
     self.root_classes = []
     self.root_properties = []
     self.json_tree = False
     self.parents = []
     self.children = []
Пример #57
0
 def __init__(self, response_dict_json):
     rp = RootPath()
     self.base_url = rp.get_baseurl()
     self.entities = {}
     self.response_dict_json = response_dict_json
     self.response_dict = json.loads(response_dict_json)
     self.highlighting = False
     # make values to these fields "flat" not a list
     self.flatten_rec_fields = True
     self.geojson_recs = []
     self.non_geo_recs = []
     self.total_found = False
     self.rec_start = False
     self.min_date = False
     self.max_date = False
     # flatten list of an attribute values to single value
     self.flatten_rec_attributes = False
     # A list of (non-standard) attributes to include in a record
     self.rec_attributes = []
Пример #58
0
    def __init__(self, request_dict, total_found=0, start=0):
        rp = RootPath()
        self.request_dict = copy.deepcopy(request_dict)
        self.base_url = rp.get_baseurl()
        self.total_found = total_found
        self.start = start

        # Flatten attributes into single value strings?
        self.flatten_attributes = False
        rec_flatten_attributes = utilities.get_request_param_value(
            self.request_dict,
            param='flatten-attributes',
            default=False,
            as_list=False,
            solr_escape=False,
        )
        if rec_flatten_attributes:
            self.flatten_attributes = True
        self.multivalue_attrib_resp_delim = configs.MULTIVALUE_ATTRIB_RESP_DELIM
Пример #59
0
 def __init__(self):
     self.project_uuid = None
     self.manifest = None
     dc_terms_obj = DCterms()
     self.DC_META_PREDS = dc_terms_obj.get_dc_terms_list()
     self.item_gen_cache = ItemGenerationCache()
     rp = RootPath()
     self.base_url = rp.get_baseurl()
     self.contexts = False
     self.linked_contexts = False
     self.geo_meta = False  #
     self.temporal_meta = False
     self.event_meta = False
     self.contents = False
     self.assertion_hashes = False
     self.cannonical_uris = True
     self.class_uri_list = []  # uris of item classes used in this item
     self.parent_context_list = [
     ]  # list of parent context labels, used for making a dc-terms:Title