예제 #1
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)
예제 #2
0
파일: user.py 프로젝트: sysnux/astportal
   def create(self, pwd1, pwd2, **kw):
      ''' Add new user to DB
      '''
      if DBSession.query(User).filter(User.user_name==kw['user_name']).all():
         flash(u'Ce compte existe déjà, utilisateur pas créé', 'error')
         redirect('/users/')

      log.info('new ' + kw['user_name'])
      u = User()
      u.user_name = kw['user_name']
      u.firstname = kw['firstname']
      u.lastname = kw['lastname']
      u.email_address = kw['email_address']
      u.fax = kw['fax']
      u.voicemail = kw['voicemail']
      u.email_voicemail = kw['email_voicemail']
      u.password = pwd1
      u.display_name = u.lastname + ' ' + u.firstname
      u.ascii_name = asterisk_string(u.display_name)
      over = kw.get('over')
      if over is not None:
         Globals.manager.send_action({'Action': 'DBput',
            'Family': 'over', 'Key': over, 'Val': 'context'})

      if 'groups' in kw:
         u.groups = DBSession.query(Group).\
               filter(Group.group_id.in_(kw['groups'])).all()

      DBSession.add(u)
      flash(u'Nouvel utilisateur "%s" créé' % (kw['user_name']))

      redirect('/users/')