Last active
August 29, 2015 14:05
-
-
Save vsanjuan/56cb064a3392c35bf8c3 to your computer and use it in GitHub Desktop.
A file to test ZODB storage an object retrieval
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Persistent class is imported so the Class can | |
# be saved later in ZODB | |
from persistent import Persistent | |
class Catalogo(Persistent): | |
def __init__(self): | |
self.catalogo = [] | |
def anadir(self, codigo, nombre, siglo): | |
self.catalogo.append(Antiguedad(codigo,nombre,siglo)) | |
def buscar(self, codigo): | |
for antiguedad in self.catalogo : | |
#print antiguedad.codigo | |
if codigo == antiguedad.codigo : | |
print "Esta en el catalogo" | |
break | |
print "No esta en el catalogo" | |
class Antiguedad(Persistent): | |
""" Tres Atributos""" | |
def __init__(self, codigo, nombre, siglo): | |
self.codigo = codigo | |
self.nombre = nombre | |
self.siglo = siglo | |
if __name__ == "__main__": | |
catalogo = Catalogo() | |
catalogo.anadir(1, "Pintura", "XVII") | |
catalogo.anadir(2, "Esculutura", "XV") | |
catalogo.buscar(3) | |
print type(catalogo.catalogo[0]) | |
print catalogo.catalogo[0].codigo | |
print catalogo.catalogo[0].nombre | |
import ZODB, ZODB.FileStorage | |
import transaction | |
storage = ZODB.FileStorage.FileStorage('mydata.fs') | |
db = ZODB.DB(storage) | |
connection = db.open() | |
root = connection.root | |
root.catalogo = catalogo | |
# root.catalogo.anadir(1, "Pintura", "XVII") | |
# root.catalogo.anadir(2, "Esculutura", "XV") | |
transaction.commit() | |
connection.close() | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import ZODB, ZODB.FileStorage | |
import transaction | |
from catalogo import Catalogo | |
storage = ZODB.FileStorage.FileStorage('mydata.fs') | |
db = ZODB.DB(storage) | |
connection = db.open() | |
root = connection.root | |
print len(root.catalogo.catalogo) | |
print type(root.catalogo.catalogo[0]) | |
print root.catalogo.buscar(1) | |
print root.catalogo.catalogo[0].codigo | |
#help(root.catalogo.catalogo[0]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment