Esempio n. 1
0
   def create(self, **kw):
      ''' Add new department to DB
      '''
      if DBSession.query(Department).filter(Department.name==kw['name']).all():
         flash(u'Ce service existe déjà, pas créé', 'error')
         redirect('/departments/')

      d = Department()
      d.name = kw['name']
      d.comment = kw['comment']
      DBSession.add(d)
      flash(u'Nouveau service "%s" créé' % (kw['name']))
      redirect('/departments/')
Esempio n. 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)