Ejemplo n.º 1
0
    def r_passage(self, objectId, subreference, lang=None):
        """ Retrieve the text of the passage

        :param objectId: Collection identifier
        :type objectId: str
        :param lang: Lang in which to express main data
        :type lang: str
        :param subreference: Reference identifier
        :type subreference: str
        :return: Template, collections metadata and Markup object representing the text
        :rtype: {str: Any}
        """
        # pdf_path = ''
        collection = self.get_collection(objectId)
        if isinstance(collection, CtsWorkMetadata):
            editions = [t for t in collection.children.values() if isinstance(t, CtsEditionMetadata)]
            if len(editions) == 0:
                raise UnknownCollection('{}.{}'.format(collection.get_label(lang), subreference) + _l(' wurde nicht gefunden.'))
            return redirect(url_for(".r_passage", objectId=str(editions[0].id), subreference=subreference))
        try:
            text = self.get_passage(objectId=objectId, subreference=subreference)
        except IndexError:
            new_subref = self.get_reffs(objectId)[0][0]
            text = self.get_passage(objectId=objectId, subreference=new_subref)
            flash('{}.{}'.format(collection.get_label(lang), subreference) + _l(' wurde nicht gefunden. Der ganze Text wird angezeigt.'))
            subreference = new_subref
        passage = self.transform(text, text.export(Mimetypes.PYTHON.ETREE), objectId)
        if 'notes' in self._transform:
            notes = self.extract_notes(passage)
        else:
            notes = ''
        prev, next = self.get_siblings(objectId, subreference, text)
        # if current_user.project_team is False and str(text.get_creator(lang)) not in self.OPEN_COLLECTIONS:
        #     pdf_path = self.pdf_folder + objectId.split(':')[-1] + '.pdf'
        return {
            "template": "main::text.html",
            "objectId": objectId,
            "subreference": subreference,
            "collections": {
                "current": {
                    "label": collection.get_label(lang),
                    "id": collection.id,
                    "model": str(collection.model),
                    "type": str(collection.type),
                    "author": text.get_creator(lang),
                    "title": text.get_title(lang),
                    "description": text.get_description(lang),
                    "citation": collection.citation,
                    "coins": self.make_coins(collection, text, subreference, lang=lang)
                },
                "parents": self.make_parents(collection, lang=lang)
            },
            "text_passage": Markup(passage),
            "notes": Markup(notes),
            "prev": prev,
            "next": next,
            "open_regest": objectId not in self.half_open_texts,
            "show_notes": objectId in self.OPEN_NOTES,
            "date": "{:04}-{:02}-{:02}".format(date.today().year, date.today().month, date.today().day)
        }
Ejemplo n.º 2
0
def fullscreenviewer(objectId):
    if "manifest" in objectId:
        objectId = re.sub(r'^manifest:', '', objectId)
    collection = current_app.config['nemo_app'].get_collection(objectId)
    if isinstance(collection, CtsWorkMetadata):
        editions = [
            t for t in collection.children.values()
            if isinstance(t, CtsEditionMetadata)
        ]
        if len(editions) == 0:
            raise UnknownCollection('{}'.format(collection.get_label()) +
                                    _l(' hat keine Edition.'))
        objectId = str(editions[0].id)
    if current_app.config['nemo_app'].check_project_team(
    ) is True or objectId in current_app.config['nemo_app'].open_texts:
        template = {'manifest': 'viewer::miradorviewer.html'}
        formulae = current_app.picture_file[
            'manifest:' + current_app.config['nemo_app'].resolver.getMetadata(
                objectId).parent.id]
        #this viewer work when the library or archiv give an IIIF API for the external usage of theirs books
        manifest = url_for('viewer.static', filename=formulae["manifest"])
        return current_app.config['nemo_app'].render(
            template=template['manifest'],
            manifest=manifest,
            objectId=objectId,
            url=dict())
    else:
        flash(_('Diese Formelsammlung ist noch nicht frei zugänglich.'))
        return current_app.config['nemo_app'].render(
            template='main::index.html', url=dict())
Ejemplo n.º 3
0
    def r_passage(self, objectId, subreference, lang=None):
        """ Retrieve the text of the passage

        :param objectId: Collection identifier
        :type objectId: str
        :param lang: Lang in which to express main data
        :type lang: str
        :param subreference: Reference identifier
        :type subreference: str
        :return: Template, collections metadata and Markup object representing the text
        :rtype: {str: Any}
        """
        collection = self.get_collection(objectId)
        if isinstance(collection, CtsWorkMetadata):
            editions = [
                t for t in collection.children.values()
                if isinstance(t, CtsEditionMetadata)
            ]
            if len(editions) == 0:
                raise UnknownCollection("This work has no default edition")
            return redirect(
                url_for(".r_passage",
                        objectId=str(editions[0].id),
                        subreference=subreference))
        text = self.get_passage(objectId=objectId, subreference=subreference)
        passage = self.transform(text, text.export(Mimetypes.PYTHON.ETREE),
                                 objectId)
        prev, next = self.get_siblings(objectId, subreference, text)
        return {
            "template": "main::text.html",
            "objectId": objectId,
            "subreference": subreference,
            "collections": {
                "current": {
                    "label":
                    collection.get_label(lang),
                    "id":
                    collection.id,
                    "model":
                    str(collection.model),
                    "type":
                    str(collection.type),
                    "author":
                    text.get_creator(lang),
                    "title":
                    text.get_title(lang),
                    "description":
                    text.get_description(lang),
                    "citation":
                    collection.citation,
                    "coins":
                    self.make_coins(collection, text, subreference, lang=lang)
                },
                "parents": self.make_parents(collection, lang=lang)
            },
            "text_passage": Markup(passage),
            "prev": prev,
            "next": next
        }
Ejemplo n.º 4
0
 def retrieve(self):
     if not self._parsed["metadata"]:
         query = self._resolver.endpoint.get_collection(self.id)
         data = query.json()
         if not len(data):
             raise UnknownCollection(
                 "The contacted endpoint seems to not have any data about collection %s "
                 % self.id)
         self._parse_metadata(expand(data)[0])
     return True
Ejemplo n.º 5
0
    def __getitem__(self, key):
        """ Retrieve an item by its ID in the tree of a collection

        :param key: Key of the object to delete
        :return: Collection identified by the item
        """
        for obj in self.descendants + [self]:
            if obj.id == key:
                return obj
        raise UnknownCollection("%s is not part of this object" % key)
Ejemplo n.º 6
0
    def r_passage(self, objectId, subreference, lang=None):
        """ Retrieve the text of the passage

        :param objectId: Collection identifier
        :type objectId: str
        :param lang: Lang in which to express main data
        :type lang: str
        :param subreference: Reference identifier
        :type subreference: str
        :return: Template, collections metadata and Markup object representing the text
        :rtype: {str: Any}
        """
        collection = self.get_collection(objectId)
        if isinstance(collection, CtsWorkMetadata):
            editions = [
                t for t in collection.children.values()
                if isinstance(t, CtsEditionMetadata)
            ]
            if len(editions) == 0:
                raise UnknownCollection(
                    '{}.{}'.format(collection.get_label(lang), subreference) +
                    _l(' hat keine Edition.'), objectId)
            objectId = str(editions[0].id)
            collection = self.get_collection(objectId)
        try:
            text = self.get_passage(objectId=objectId,
                                    subreference=subreference)
        except IndexError:
            new_subref = self.get_reffs(objectId)[0][0]
            text = self.get_passage(objectId=objectId, subreference=new_subref)
            flash('{}.{}'.format(collection.get_label(lang), subreference) +
                  _l(' wurde nicht gefunden. Der ganze Text wird angezeigt.'))
            subreference = new_subref
        passage = self.transform(text, text.export(Mimetypes.PYTHON.ETREE),
                                 objectId)
        metadata = self.resolver.getMetadata(objectId=objectId)
        if 'notes' in self._transform:
            notes = self.extract_notes(passage)
        else:
            notes = ''
        prev, next = self.get_siblings(objectId, subreference, text)
        inRefs = []
        for inRef in sorted(metadata.metadata.get(DCTERMS.isReferencedBy)):
            ref = str(inRef).split('%')
            cits = ref[1:]
            for i, cit in enumerate(cits):
                cits[i] = Markup(Markup(cit))
            if ref[0] not in request.url:
                try:
                    inRefs.append([self.resolver.getMetadata(ref[0]), cits])
                except UnknownCollection:
                    inRefs.append(ref[0])
        return {
            "template":
            "main::text.html",
            "objectId":
            objectId,
            "subreference":
            subreference,
            "collections": {
                "current": {
                    "label":
                    str(metadata.metadata.get_single(DC.title, lang=None))
                    or collection.get_label(lang),
                    "id":
                    collection.id,
                    "model":
                    str(collection.model),
                    "type":
                    str(collection.type),
                    "author":
                    str(metadata.metadata.get_single(DC.creator, lang=None))
                    or text.get_creator(lang),
                    "title":
                    text.get_title(lang),
                    "description":
                    str(text.get_description(lang)) or '',
                    "coins":
                    self.make_coins(collection, text, subreference, lang=lang),
                    "pubdate":
                    str(
                        metadata.metadata.get_single(DCTERMS.created,
                                                     lang=lang)),
                    "publang":
                    str(metadata.metadata.get_single(DC.language, lang=lang)),
                    "publisher":
                    str(metadata.metadata.get_single(DC.publisher, lang=lang)),
                    'lang':
                    collection.lang,
                    'citation':
                    str(
                        metadata.metadata.get_single(
                            DCTERMS.bibliographicCitation, lang=lang)),
                    "short_regest":
                    str(metadata.metadata.get_single(DCTERMS.abstract))
                    if 'andecavensis' in collection.id else '',
                    "dating":
                    str(metadata.metadata.get_single(DCTERMS.temporal) or ''),
                    "issued_at":
                    str(metadata.metadata.get_single(DCTERMS.spatial) or '')
                },
                "parents": self.make_parents(collection, lang=lang)
            },
            "text_passage":
            Markup(passage),
            "notes":
            Markup(notes),
            "prev":
            prev,
            "next":
            next,
            "open_regest":
            objectId not in self.half_open_texts,
            "show_notes":
            objectId in self.OPEN_NOTES,
            "urldate":
            "{:04}-{:02}-{:02}".format(date.today().year,
                                       date.today().month,
                                       date.today().day),
            "isReferencedBy":
            inRefs
        }