Пример #1
0
    def post(self):
        errors=dict()
        action=request.args.get('action')
        
        def dict2str(get_dict):
                this_list = get_dict.values()
                return this_list[0]
            
        if action=='add':
            user_dict = get_dict(request.form, 'account', 'pwd', 'name', 'email' )
            try:
                User(**user_dict).save()
            except ValidationError as e:
                return redirect(url_for('admin.list',**e.errors))

            except:
                errors=dict({"unique":u"帳號重複請重新輸入"})
                return redirect(url_for('admin.list',**errors))

        if action=='modify':
            user_dict=get_dict(request.form, 'set__account', 'set__name' ,'set__email')
            to_md5_dict = get_dict(request.form, 'set__pwd')
            to_md5_list=to_md5_dict.values()
            to_md5_str=str(to_md5_list[0])

            set_pwd_md5 = hashlib.md5()# use hashlib.md5
            set_pwd_md5.update(to_md5_str) # to md5
            set_pwd = set_pwd_md5.hexdigest()#print 編碼後的結果至終端
            user_dict['set__pwd'] = set_pwd

            try:
                User.objects(id=request.form['objid']).update(**user_dict)
            except ValidationError as e:
                return redirect(url_for('admin.list',**e.errors))

        if action=='delete':
            try:
                User(id=request.form["objid"]).delete()

            except ValidationError as e:
                return redirect(url_for('admin.list',**e.errors))

        return redirect(url_for('admin.list'))
Пример #2
0
def names_generator(total_name):
  '''
    Names Generator
    Params:
      - total_name: Number of names that will generated
  '''
  items = get_dict()
  names = list()
  for i in xrange(total_name):
    names.append(" ".join(generate_name(items)))

  return names
Пример #3
0
 def post(self):
     user_dict = get_dict(request.form, u'account', u'pwd', u'name')
     u = User(**user_dict)
     u.save()
     return redirect(url_for('users.login'))