Commits

Tatiana de la O committed cc99361

-
-changed collection.by_user method for get_by_user to keep in line with the rest of methods

Comments (0)

Files changed (4)

openbiblio/model/base.py

         results = [ self.get_by_uri(uri) for uri in results ]
         return results
 
-    def as_dict(self):
+    def to_dict(self):
         out = {'id': str(self.identifier)}
         for s,p,o in self.graph.triples((None,None,None)):
             if s == self.identifier:
                 for ns_nick, ns_uri in ordf.namespace.namespaces.items():
                     ourns_uri = str(ns_uri) 
                     if ourp.startswith(ourns_uri):
-                        ourp = ns_nick + ':' + ourp[len(ourns_uri):]
+                        ourp = ourp[len(ourns_uri):]
                         break
                 out[ourp] = val
         return out
-    
-    def from_dict(self):
-        pass
 
 
+    def from_dict(self,objectdict):
+        for key, value in objectdict.items():
+# need to distinguish between lits and uris, next commit hopefully!
+            self.__setattr__(key, value)
+
+

openbiblio/model/collection.py

         self.type = BIBO.Collection
 
     @classmethod
-    def by_user(cls, user):
+    def get_by_user(cls, user):
         q = u"""
         PREFIX bb: <http://bibliographica.org/onto#>
 
         """ % user.n3()
         for collection, in handler.query(q):
             return cls.get_by_uri(collection)
-

openbiblio/model/entry.py

     bl_id = predicate(OV.blid)
     creators = object_predicate(DC.contributor, Entity) 
     publishers = object_predicate(DC.publisher, Entity) 
+    subject = object_predicate(DC.subject, Entity)
 
     def __init__(self, *av, **kw):
         super(Entry, self).__init__(*av, **kw)

openbiblio/tests/model/test_collection.py

     entrylabel = 'my-test-entry'
     label = 'my-test-collection'
     openid = 'http://myopen.id/2'
+    onedict = {
+            'title': 'Interplanetary flight : an introduction to astronautics',
+            'id': '<http://bnb.bibliographica.org/entry/GB5006595>',
+            'subject': 'astronautics'
+    }
+
+
 
     @classmethod
     def setup_class(self):
         assert len(entries) == 1, entries
 
     def test_02_by_user(self):
-        collection = model.Collection.by_user(self.account_id)
+        collection = model.Collection.get_by_user(self.account_id)
         assert collection.label[0] == self.label, collection
 
     def test_03_find(self):
         assert len(out) == 1, out
         assert self.collection_id == out[0].identifier, out
 
-    def test_04_asdict(self):
+    def test_04_todict(self):
         collection = model.Collection.get_by_uri(self.collection_id)
-        out = collection.as_dict()
+        out = collection.to_dict()
         pprint.pprint(out)
-        assert out['rdfs:label'] == self.label
+        assert out['label'] == self.label
         assert out['id'] == str(self.collection_id)
-        assert out['biblio-ont:owner'] == self.account_id.n3()
+        assert out['owner'] == self.account_id.n3()
+    def test_05_from_dict(self):
+        collection = model.Collection.create()
+        out = collection.from_dict(self.onedict)
+        pprint.pprint(out)
+        collection.save(collection.identifier.n3())
 
+