Esempio n. 1
0
def toRdf(collection, model='saa'):

    g = rdfSubject.db = Graph(identifier=ga.term('collections'))

    collectionNumber = collection.collectionNumber.lower().replace('.', '')
    scanNamespace = Namespace(
        f"https://archief.amsterdam/inventarissen/inventaris/{collectionNumber}.nl.html#"
    )

    col = SAACollection(ga.term(collectionNumber),
                        identifier=collection.collection_id,
                        code=collection.collectionNumber,
                        title=collection.title,
                        publisher=collection.publisher,
                        date=collection.collectionDate,
                        label=[collection.title])

    parts = [
        cToRdf(c,
               parent=col,
               collectionNumber=collectionNumber,
               scanNamespace=scanNamespace) for c in collection.children
    ]

    if parts != []:
        col.hasParts = parts

    return g
 def all_namespaces(self):
     result = []
     # TODO: Correct term "name"
     for a_nsname in [a_mns.name for a_mns in Namespace.select()]:
         result.append('NS "%s" "%s"' % (a_nsname,
                                         nsname_to_nsurl(a_nsname)))
     return u"\n".join(result)
 def description(self, namespace):
     ns = Namespace.byName(namespace)
     result = []
     for ln_link in ns.LNs:
         result.append(u'LN "%s" "%s"' % (ln_link.name, ln_link.url))
     for ns_link in ns.NSs:
         result.append(u'NS "%s" "%s"' % (ns_link.name, ns_link.url))
     return u"\n".join(result)
 def enter_name(self, namespace, password, url):
     ns = Namespace.byName(namespace)
     if ns.password != password:
         incorrect_password_routine()
     return {"namespace": namespace,
             "password": password,
             "namespace_url": turbogears.url("/namespace",
                                             namespace=namespace,
                                             password=password),
             "url": url}
    def namespace(self, namespace, password="",
                  linkkey=None, linkurl=None,
                  deltype=None,  # "LN", "NS", or "PATTERN"
                  delname=None):
        
        """Render namespace page.
        
        Aquire namespace, check password. Register links, delete links.
        """

        a_nsname = namespace
        a_nsname_linkkey = linkkey
        a_nsurl_linkurl = linkurl
        
        try:
            a_mns = Namespace.byName(a_nsname)
        except SQLObjectNotFound:
            a_mns = Namespace(name=a_nsname,
                              password=password)
            set_namespace_ln(a_mns, "this", nsname_to_nsurl(a_nsname))
        
        if a_mns.password != password:
            incorrect_password_routine()
        
        if ((a_nsname_linkkey is not None) and
            (a_nsurl_linkurl is not None)):
            set_namespace_ns(a_mns, a_nsname_linkkey, a_nsurl_linkurl)
            turbogears.flash("Link registered.")
        
        if (deltype is not None) and (delname is not None):
            for entry in {"LN": a_mns.LNs,
                          "NS": a_mns.NSs,
                          "PATTERN": a_mns.PATTERNs}.get(deltype,
                                                         a_mns.LNs):
                if entry.name == delname:
                    entry.destroySelf()
                    turbogears.flash("%s deleted" % entry.name)
        
        store_name_url = cherrypy.request.base + \
                         turbogears.url("/enter_name")
        bookmarklet_url = "javascript:o=location.href;" \
                          "location.href='%s?namespace=%s&password=%s" \
                          "&url='+escape(o)" % (store_name_url,
                                                a_nsname, password)
        
        return {"namespace": a_nsname,
                "password": password,
                "description_url": nsname_to_nsurl(a_nsname),
                "bookmarklet_url": bookmarklet_url}
    def submit_name(self, namespace, password, name, url, confirm=None):
	a_nsname = namespace
	a_lnname = name
	a_lnurl = url
        a_mnamespace = Namespace.byName(a_nsname)
        if a_mnamespace.password != password:
            incorrect_password_routine()
        a_lnurl_lower = a_lnurl.lower()
        if ("password" in a_lnurl_lower) \
               or ("&pw=" in a_lnurl_lower) \
               or ("?pw=" in a_lnurl_lower):
            if confirm is None:
                return {"namespace": a_nsname,
                        "password": password,
                        "name": name,
                        "url": url}
        set_namespace_ln(a_mnamespace, a_lnname, a_lnurl)
        raise cherrypy.HTTPRedirect(a_lnurl)
 def changepassword(self, namespace,
                    oldpassword, newpassword, repeat):
     ns = Namespace.byName(namespace)
     if ns.password != oldpassword:
         msg = INCORRECT_PASSWORD_MSG
     elif newpassword != repeat:
         msg = "The new password didn't match it's repeat."
     else:
         hub.begin()
         ns.password = newpassword
         hub.commit()
         hub.end()
         msg = "Password changed!"
     turbogears.flash(msg)
     url = turbogears.url("/namespace",
                          namespace=namespace,
                          password=ns.password)
     raise cherrypy.HTTPRedirect(url)
Esempio n. 8
0
def cToRdf(c, parent=None, collectionNumber=None, scanNamespace=None):

    if collectionNumber:
        saaCollection = Namespace(
            f"https://data.goldenagents.org/datasets/SAA/{collectionNumber}/")
    else:
        saaCollection = ga

    if (c.scans or not c.children) and collectionNumber:
        # Then this is a book --> InventoryBook

        inventoryId = c.id
        saaInventory = Namespace(
            f"https://data.goldenagents.org/datasets/SAA/{collectionNumber}/{inventoryId}/"
        )

        if c.scans:

            saaScan = Namespace(
                f"https://data.goldenagents.org/datasets/SAA/Scan/")

            urlScans = [scanNamespace.term(i) for i in c.scans]
            scans = [saaInventory.term(i) for i in c.scans]

            parts = [
                SAADoublePageSpread(sUri,
                                    hasDigitalRepresentation=SAAScan(
                                        saaScan.term(img), depiction=imgUri),
                                    partOf=saaCollection.term(c.id))
                for img, sUri, imgUri in zip(c.scans, scans, urlScans)
            ]
        else:
            parts = []

        col = SAAInventoryBook(
            saaCollection.term(c.id),
            identifier=c.id,
            inventoryNumber=c.code,
            title=c.title,
            label=[Literal(f"Inventaris {c.code}", lang='nl')],
            date=c.date,
            hasParts=parts)

        try:
            parsedDate = parseDate(c.date)
        except:
            print(c.date)

        for k, v in parsedDate.items():
            if v:
                col.__setattr__(k, Literal(v.date(), datatype=XSD.date))

    else:
        # Not yet reached the end of the tree

        # collectionId = f"{collectionId}/{c.id}"

        col = SAACollection(saaCollection.term(c.id),
                            identifier=c.id,
                            code=c.code,
                            title=c.title,
                            date=c.date,
                            comment=[c.comment] if c.comment else [],
                            partOf=parent,
                            label=[c.title])

        parts = [
            cToRdf(c,
                   parent=col,
                   collectionNumber=collectionNumber,
                   scanNamespace=scanNamespace) for c in c.children
        ]

        if parts != []:
            col.hasParts = parts

    return col