def view(self, uuid):
        """
        View object
        If this is basic HTTP request, this will redirect to the record
        If the request is for RDF (content negotiation) return the rdf
        """
        if uuid in ABYSSLINE_UUIDS:
            self.abyssline_object_redirect(uuid)

        # Is the request for a particular format
        _format = check_access_header()

        if _format:
            return self.rdf(uuid, _format)
        else:
            try:
                # This is a normal HTTP request, so redirect to the object record
                record, resource = get_record_by_uuid(uuid)
            except TypeError:
                pass
            else:
                if record:
                    package_id = resource.get_package_id()
                    package = get_action("package_show")(self.context, {"id": package_id})
                    h.redirect_to(
                        controller="ckanext.nhm.controllers.record:RecordController",
                        action="view",
                        package_name=package["name"],
                        resource_id=resource.id,
                        record_id=record["_id"],
                    )

        abort(404, _("Record not found"))
    def view(self, uuid, version=None):
        '''
        View object. If this is normal HTTP request, this will redirect to the record, otherwise if
        the request is for RDF (content negotiation) return the rdf.

        :param uuid: the uuid of the object
        :param version: the version of the object, or None for current version
        '''
        if uuid in ABYSSLINE_UUIDS:
            self.abyssline_object_redirect(uuid, version)

        try:
            # get the record at the given version
            record, resource = get_record_by_uuid(uuid, version)
        except TypeError:
            pass
        else:
            if record:
                # is the request for a particular format
                requested_format = check_access_header()

                if requested_format:
                    # if so provide the kwargs necessary to build the object rdf url
                    url_kwargs = dict(
                        controller='ckanext.nhm.controllers.object:ObjectController',
                        action='rdf',
                        uuid=uuid,
                        _format=requested_format,
                    )
                else:
                    # otherwise, the user wants html so provide the kwargs necessary to build the
                    # record page
                    package_id = resource.get_package_id()
                    package = get_action('package_show')(self.context, {'id': package_id})
                    url_kwargs = dict(
                        controller='ckanext.nhm.controllers.record:RecordController',
                        action='view',
                        package_name=package['name'],
                        resource_id=resource.id,
                        record_id=record['_id'],
                    )

                # add the version if we have one
                if version is not None:
                    url_kwargs['version'] = version

                # redirect using a 303 (as recommended by CETAF)
                base.redirect(h.url_for(**url_kwargs), code=303)

        abort(404, _('Record not found'))
Exemple #3
0
def object_rdf(context, data_dict):
    """
    Get record RDF
    :param context:
    :param data_dict:
    :return:
    """

    # Validate the data
    context = {'model': model, 'session': model.Session, 'user': c.user or c.author}
    schema = context.get('schema', nhm_schema.object_rdf_schema())
    data_dict, errors = _validate(data_dict, schema, context)
    # Raise any validation errors
    if errors:
        raise p.toolkit.ValidationError(errors)

    # Get the record
    record_dict, resource_dict = get_record_by_uuid(data_dict['uuid'])
    if record_dict:
        record_dict['uuid'] = data_dict['uuid']
        serializer = RDFSerializer()
        output = serializer.serialize_record(record_dict, resource_dict, _format=data_dict.get('format'))
        return output
    raise NotFound