예제 #1
0
def create_phones(base):
   for i in range(0,100):
      p = Phone()
      p.number = '%s%02d' % (base, i)
      p.department_id = -1
      DBSession.add(p)
   DBSession.flush()
   transaction.commit()
예제 #2
0
def main():
   args = parse_args()
   load_config(args.conf_file)

   if len(DBSession.query(Phone).all())==0:
      create_phones('4643')
      create_phones('4752')

   data = csv.reader(open(args.csv_file,'rb'), delimiter=',')

   try:
      dptm = ''
      for row in data:
   

         uname = unicode(re.sub('\W', '', (row[1][0:2] + row[0]).lower()), 'utf-8')
         dname = unicode(row[0] + ' ' + row[1], 'utf-8')
         num = unicode(row[3].replace(' ',''), 'utf-8')
         fax = unicode(row[4].replace(' ',''), 'utf-8')
         dptm = unicode(row[5], 'utf-8')
         #print ' * * * ', uname, dname, num, dptm

         try:
            p = DBSession.query(Phone).filter(Phone.number==num).one()
         except NoResultFound, e:
            # Nouveau tél ???
            p = Phone()
            p.number = num
            p.department_id = -1
            DBSession.add(p)

         try:
            d = DBSession.query(Department).filter(Department.name==dptm).one()
         except NoResultFound, e:
            # Nouveau département
            d = Department()
            d.name = dptm
            DBSession.add(d)

         u = User()
         u.user_name = uname
         u.display_name = dname
         u.phone = [p]
         u.password = u'n5oBwdpytxdvj~Rz1uum'
         p.department = d
         DBSession.add(u)
         DBSession.add(p)
예제 #3
0
파일: postes.py 프로젝트: sysnux/astportal
#from astportal2.model import *
from astportal2.model import init_model, DBSession, Phone

config = ConfigParser.ConfigParser({'here': os.getcwd()})
config.read(os.path.join(os.getcwd(), 'development.ini'))
sqlalchemy_url = config.get('app:main', 'sqlalchemy.url')
engine = create_engine(sqlalchemy_url)
init_model(engine)

import csv, sys


numbers = [p.number for p in DBSession.query(Phone.number).all()]

#for i in range(0,400):
#for i in range(500,700):
for i in range(800,900):
    n = '2%03d' % i
    if n not in numbers:
       p = Phone()
       p.number = n
       p.department_id = 28
       try:
          DBSession.add(p)
          DBSession.flush()
       except:
          sys.exit('ERREUR sur poste ' + n)
       print n, 'OK !'
transaction.commit()