def _add_standard_reg_view(self):
     return {
         'reg': View(
             'Registry Ontology',
             'A simple list-of-items view taken from the Registry Ontology',
             ['text/html', 'text/turtle', 'application/rdf+xml', 'application/ld+json', 'application/json', '_internal'],
             'text/html',
             'http://purl.org/linked-data/registry#'
         )
     }
Пример #2
0
 def _add_standard_reg_view(self):
     return {
         'reg': View(
             'Registry Ontology',
             'A simple list-of-items view taken from the Registry Ontology',
             ['text/html', 'application/json'] + self.RDF_MIMETYPES,
             'text/html',
             languages=['en'],  # default 'en' only for now
             namespace='http://purl.org/linked-data/registry'
         )
     }
Пример #3
0
    def __init__(self, uri, request):
        self.uri = uri

        views = {
            'method':
            View('Method',
                 'A TERN method.', ['text/html'] + Renderer.RDF_MIMETYPES,
                 'text/html',
                 namespace='https://w3id.org/tern/ontologies/tern/')
        }

        super().__init__(request, uri, views, 'method')
Пример #4
0
    def __init__(self, uri, request):
        self.uri = uri

        views = {
            'skos':
            View(
                'SKOS',
                'Simple Knowledge Organization System (SKOS) is an area of work developing specifications and standards to support the use of knowledge organization systems (KOS) such as thesauri, classification schemes, subject heading lists and taxonomies within the framework of the Semantic Web.',
                ['text/html'] + Renderer.RDF_MIMETYPES,
                'text/html',
                namespace='http://www.w3.org/2004/02/skos/core#')
        }

        super().__init__(request, uri, views, 'skos')
Пример #5
0
    def __init__(self,
                 request,
                 uri,
                 views,
                 default_view_token,
                 alternates_template=None):
        """
        Init function for class
        :param request: the Flask request object that triggered this class object creation
        :type request: Flask request object
        :param uri: the URI called that triggered this API endpoint (can be via redirects but the main URI is needed)
        :type uri: string
        :param views: a list of views available for this resource
        :type views: list (of View class objects)
        :param default_view_token: the ID of the default view (key of a view in the list of Views)
        :type default_view_token: string (key in views)
        :param alternates_template: the jinja template to use for rendering the HTML alternates view
        :type alternates_template: string | None
        """
        self.request = request
        self.uri = uri

        # ensure alternates isn't hogged by user
        for k, v in views.items():
            if k == 'alternates':
                raise ViewsFormatsException(
                    'You must not manually add a view with token \'alternates\' as this is auto-created'
                )
        self.views = views

        # ensure that the default view is actually a given view
        if default_view_token not in self.views.keys():
            raise ViewsFormatsException(
                'The view token you specified for the default view is not in the list of views you supplied'
            )
        self.default_view_token = default_view_token
        self.alternates_template = alternates_template
        # auto-add in an Alternates view
        self.views['alternates'] = View(
            'Alternates',
            'The view that lists all other views',
            ['text/html', 'application/json', '_internal'] +
            self.RDF_MIMETYPES,
            'text/html',
            languages=['en'],  # default 'en' only for now
            namespace='https://promsns.org/def/alt')

        # get view & format for this request, flag any errors but do not except out
        try:
            self.view = self._get_requested_view()
            try:
                self.format = self._get_requested_format()
                if self.format is None:
                    self.format = self.views[self.view].default_format

                self.language = self._get_requested_language()
                if self.language is None:
                    self.language = self.views[self.view].default_language
            except ViewsFormatsException as e:
                print(e)
                self.vf_error = str(e)
        except ViewsFormatsException as e:
            print(e)
            self.vf_error = str(e)

        self.headers = dict()
Пример #6
0
    def __init__(self,
                 request,
                 uri,
                 views,
                 default_view_token,
                 alternates_template=None):
        """
        Constructor

        :param request: Flask request object that triggered this class object's creation.
        :type request: :class:`flask.request`
        :param uri: The URI that triggered this API endpoint (can be via redirects but the main URI is needed).
        :type uri: str
        :param views: A dictionary of views available for this resource.
        :type views: dict (of :class:`.View` class objects)
        :param default_view_token: The ID of the default view (key of a view in the dictionary of :class:`.View` objects)
        :type default_view_token: str (a key in views)
        :param alternates_template: The Jinja2 template to use for rendering the HTML *alternates view*. If None, then it will default to try and use a template called :code:`alternates.html`.
        :type alternates_template: str

        .. seealso:: See the :class:`.View` class on how to create a dictionary of views.

        """
        self.request = request
        self.uri = uri

        # ensure alternates isn't hogged by user
        for k, v in views.items():
            if k == 'alternates':
                raise ViewsFormatsException(
                    'You must not manually add a view with token \'alternates\' as this is auto-created'
                )
        self.views = views

        # ensure that the default view is actually a given view
        if default_view_token not in self.views.keys():
            raise ViewsFormatsException(
                'The view token you specified for the default view is not in the list of views you supplied'
            )
        self.default_view_token = default_view_token
        self.alternates_template = alternates_template
        # auto-add in an Alternates view
        self.views['alternates'] = View(
            'Alternates',
            'The view that lists all other views',
            ['text/html', 'application/json', '_internal'] +
            self.RDF_MIMETYPES,
            'text/html',
            languages=['en'],  # default 'en' only for now
            namespace='https://promsns.org/def/alt')

        # get view & format for this request, flag any errors but do not except out
        try:
            self.view = self._get_requested_view()
            try:
                self.format = self._get_requested_format()
                if self.format is None:
                    self.format = self.views[self.view].default_format

                self.language = self._get_requested_language()
                if self.language is None:
                    self.language = self.views[self.view].default_language
            except ViewsFormatsException as e:
                print(e)
                self.vf_error = str(e)
        except ViewsFormatsException as e:
            print(e)
            self.vf_error = str(e)

        self.headers = dict()