All pastes #54470 Raw Edit

ccd

public text v1 · immutable
#54470 ·published 2006-05-09 06:45 UTC
rendered paste body
#!/usr/bin/python
import re
import sys
import sqlobject
from sqlobject.sqlite import builder


conn = builder()('sqlobject_demo21.db')

class Account(sqlobject.SQLObject):
        _connection     = conn
        accountnumber   = sqlobject.StringCol(length=255, unique=True)
        accountname     = sqlobject.StringCol(length=255, unique=True)
        owner           = sqlobject.ForeignKey('Instution')

Account.createTable(ifNotExists=True)


class Instution(sqlobject.SQLObject):
        _idName         = 'fooID'
        _connection     = conn
        name            = sqlobject.StringCol(length=255, unique=True)
        accounts        = sqlobject.MultipleJoin('Account', joinColumn='owner_id')
#       def _set_phonenumber(self, value):
#               if not re.match('\([0-9]{3}\) [0-9]{3}-[0-9]{4}', value):   #It's not in the format we expect.
 #                      if re.match('[0-9]{10}', value):                    #It's totally unformatted; add the formatting.
#                               print "totallu unformatted"
#                               value = "(%s) %s-%s" % (value[:3], value[3:6], value[6:])
#                       else:
#                               raise ValueError, 'Not a number number: %s' % value
 #                      self._SO_set_phonenumber(value)

Instution.createTable(ifNotExists=True)





#newinstution = Instution(company=sys.argv[1],abbrevation=sys.argv[2],address=sys.argv[3],number=sys.argv[4],fax=sys.argv[5])

tfcu  = Instution(name='Tucson Federal Credit Union')
pyramid = Instution(name='Pyramid Credit Union')
sharebuilder = Instution(name='Sharebuilder')
chase = Instution(name='Chase')
citibank = Instution(name='Citibank')

print tfcu
print pyramid
print sharebuilder
print chase
print citibank

newaccount = Account(accountnumber='00',accountname='REGULAR SAVINGS ACCT',owner=tfcu)
newaccount1 = Account(accountnumber='09',accountname='CUSTOM CHECKING',owner=tfcu)
newaccount2 = Account(accountnumber='12',accountname='PRIMELINE 2ND',owner=tfcu)
newaccount3 = Account(accountnumber='25',accountname='UNSECURED VISA',owner=tfcu)
newaccount4 = Account(accountnumber='80',accountname='CHECK-LINE RESERVE',owner=tfcu)
newaccount5 = Account(accountnumber='001',accountname='REGULAR',owner=pyramid)
newaccount6 = Account(accountnumber='009',accountname='CHECKING',owner=pyramid)
newaccount7 = Account(accountnumber='100-005234-01',accountname='Individual',owner=sharebuilder)
newaccount8 = Account(accountnumber='3471',accountname='Credit Card',owner=chase)
newaccount9 = Account(accountnumber='5972',accountname='Consumer Credit Card',owner=citibank)


print newaccount
print newaccount9

print tfcu.accounts