当前位置: 首页>>代码示例>>Python>>正文


Python Account.save方法代码示例

本文整理汇总了Python中models.account.Account.save方法的典型用法代码示例。如果您正苦于以下问题:Python Account.save方法的具体用法?Python Account.save怎么用?Python Account.save使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在models.account.Account的用法示例。


在下文中一共展示了Account.save方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: install_account_data

# 需要导入模块: from models.account import Account [as 别名]
# 或者: from models.account.Account import save [as 别名]
def install_account_data():
  """Create all the required accounts if not defined"""
  from application import db
  from models.account import Account, Group
  
  accountList = [
    {
      'alias': 'timur.glushan',
      'first_name': 'Timur',
      'last_name': 'Glushan',
      'email': '[email protected]',
      'info': None,
      'group': Group.query.filter_by(alias='administrator').first()
    }
  ]
  
  for accountItem in accountList:
    account = Account.query.filter_by(alias=accountItem['alias']).first()
    if not account:
      account = Account()
      account.alias = accountItem['alias']
      account.first_name = accountItem['first_name']
      account.last_name = accountItem['last_name']
      account.email = accountItem['email']
      account.info = accountItem['info']
      account.group = accountItem['group']
      account.save()
开发者ID:timur-glushan,项目名称:tt,代码行数:29,代码来源:account.py

示例2: post

# 需要导入模块: from models.account import Account [as 别名]
# 或者: from models.account.Account import save [as 别名]
    def post(self):
        username = self.get_body_argument('inputUsername', '')
        password = self.get_body_argument('inputPassword', '')
        email = self.get_body_argument('inputEmail', '')

        if not username:
            self.render("register.html", msg="用户名不应为空", instance_name=_INSTANCE_NAME)
        elif not password:
            self.render("register.html", msg="密码不应为空", instance_name=_INSTANCE_NAME)
        elif not password:
            self.render("register.html", msg="邮箱不应为空", instance_name=_INSTANCE_NAME)
        elif not self.current_user.has_role('super'):
            self.render("register.html", msg="你没有权限创建用户", instance_name=_INSTANCE_NAME)
        else:
            # check username
            rst = mongodb_client['deployment']['account'].find_one({
                "username": username
            })

            if rst:
                self.render("register.html", msg="用户名已存在", instance_name=_INSTANCE_NAME)
            else:
                m = hashlib.md5()
                m.update(password.encode("utf8"))
                password = m.hexdigest()

                account = Account(username, password, email, ['dev'])

                account.save()

                # log to db
                mongodb_client['deployment']['operation_log'].insert({
                    "userId": self.get_current_user().user_id,
                    "username": self.get_current_user().username,
                    "operation": "register",
                    "register_username": username,
                    "createTimeStamp": int(time.time())
                })

                self.redirect('/deploy/repo')
开发者ID:11dimension,项目名称:niner,代码行数:42,代码来源:register_handler.py

示例3: install_migration_accounts

# 需要导入模块: from models.account import Account [as 别名]
# 或者: from models.account.Account import save [as 别名]
def install_migration_accounts():
  """Migrate the accounts data from the old CouchDB storage"""
  from models.account import Account, Group
  
  defaultGroup = Group.query.filter_by(alias=Group.GROUP_DEFAULT).first()
  
  for row in __couchdb().view('_design/employees/_view/employees_list'):
    value = row['value']
    account = Account.query.filter_by(alias=value.get('_id', '')).first()
    if not account:
      account = Account()
      account.alias = value.get('_id', '')
      account.email = value.get('email')
      account.first_name = value.get('first_name')
      account.last_name = value.get('last_name')
      account.stored_password = account.password = value.get('password', None)
      if value.get('deleted', False):
        account.status = Account.STATUS_ACTIVE | Account.STATUS_DELETED
      account.group_id = defaultGroup.id
      
      account.save()
      print '[MIGRATION:ACCOUNT]', account.__str__()
开发者ID:timur-glushan,项目名称:tt,代码行数:24,代码来源:migration.py

示例4: profile_edit

# 需要导入模块: from models.account import Account [as 别名]
# 或者: from models.account.Account import save [as 别名]
def profile_edit(account_id=None):
  from models.account import Account, Group
  from helpers.account import AccountHelper
  
  account = None
  if not account_id:
    if not app.access('profile', action='create'):
      abort(403)
    account = Account()
    account.status = Account.STATUS_ACTIVE
    account.group_id = Group.query.filter_by(alias=Group.GROUP_DEFAULT).first().id
  else:
    account_id = urllib.unquote_plus(account_id)
    account = Account.query.filter_by(id=account_id).first()
    if not account:
      abort(404)
    elif not app.access('profile', action='update', account=account):
      abort(403)
  
  print '[GROUP]',account.group_id, account.group
  
  validationErrors = []
  if request.method == 'POST' and request.form.get('csrf_token', None):
    account.alias = request.values.get('account_alias', account.alias).strip()
    account.first_name = request.values.get('account_first_name', account.first_name).strip()
    account.last_name = request.values.get('account_last_name', account.last_name).strip()
    account.email = request.values.get('account_email', account.email).strip()
    account.info = request.values.get('account_info', account.info).strip()
    account_group_id = request.values.get('account_group_id', '').strip()
    account.status = int(request.form.get('account_status', account.status).strip())
    
    account_group = None
    if account_group_id:
      account_group = Group.query.filter_by(id=account_group_id).first()
    if not account_group:
      account_group = Group.query.filter_by(alias=Group.GROUP_DEFAULT).first()
    account.group_id = account_group.id
    
    validationErrors = account.validate()
    if not validationErrors:
      account.save()
      flash(g._t('profile submit success'))
      
      if account_id:
        return redirect(url_for('profile_view', account_id=urllib.quote_plus(account_id)))
      else:
        return redirect(url_for('profile_employees'))
  
  if account_id:
    title = g._t('edit profile')
  else:
    title = g._t('new profile')
  
  if account_id:
    breadcrumbs = (
      (((not app.access('authenticated', account=account)) and g._t('employees') or ''), url_for('profile_employees')),
      ((app.access('authenticated', account=account) and g._t('me') or account.__str__()), url_for('profile_view', account_id=account_id)),
      (title, "#")
    )
  else:
    breadcrumbs = (
      (g._t('employees'), url_for('profile_employees')),
      (title, "#")
    )
  
  if app.access('profile', action='administer'):
    groupList = AccountHelper.listGroups()
  else:
    groupList = AccountHelper.listActiveGroups()
  
  return render_template('profile/edit.html', account_id=account_id, account=account, groupList=groupList, title=title, breadcrumbs=breadcrumbs, errors=validationErrors)
开发者ID:timur-glushan,项目名称:tt,代码行数:73,代码来源:profile.py

示例5: test_data_create

# 需要导入模块: from models.account import Account [as 别名]
# 或者: from models.account.Account import save [as 别名]
def test_data_create():
  from models.account import Account
  from models.project import Project
  from models.report import Report
  from models.variable import Variable
  
  data = {'accounts':[], 'projects':[]}
  
  roles = {
    'administrator':[], 
    'privileged_manager':[], 
    'manager':[], 
    'privileged_member':[], 
    'member':[], 
  }
  rolesVariable = Variable.query.filter_by(name='roles', scope='permissions').first()
  roles.update(rolesVariable.value or {})
  
  # administrator
  administrator_1 = Account({'id':'test.administrator_1', 'email':'[email protected]'})
  administrator_1.save()
  roles['administrator'].append(administrator_1.id)
  data['accounts'].append(administrator_1)
  
  # privileged manager to see everything, manage a project and share management with other manager on a second project
  privileged_manager_1 = Account({'id':'test.privileged_manager_1', 'email':'[email protected]'})
  privileged_manager_1.save()
  roles['privileged_manager'].append(privileged_manager_1.id)
  data['accounts'].append(privileged_manager_1)
  
  # managers, one for a single project to manage, another to manage 2 more projects
  manager_1 = Account({'id':'test.manager_1', 'email':'[email protected]'})
  manager_1.save()
  roles['manager'].append(manager_1.id)
  data['accounts'].append(manager_1)
  
  manager_2 = Account({'id':'test.manager_2', 'email':'[email protected]'})
  manager_2.save()
  roles['manager'].append(manager_2.id)
  data['accounts'].append(manager_2)
  
  # privileged members aka leads
  privileged_member_1 = Account({'id':'test.privileged_member_1', 'email':'[email protected]'})
  privileged_member_1.save()
  roles['privileged_member'].append(privileged_member_1.id)
  data['accounts'].append(privileged_member_1)
  
  privileged_member_2 = Account({'id':'test.privileged_member_2', 'email':'[email protected]'})
  privileged_member_2.save()
  roles['privileged_member'].append(privileged_member_2.id)
  data['accounts'].append(privileged_member_2)
  
  # members - developers
  member_1 = Account({'id':'test.member_1', 'email':'[email protected]'})
  member_1.save()
  roles['member'].append(member_1.id)
  data['accounts'].append(member_1)
  
  member_2 = Account({'id':'test.member_2', 'email':'[email protected]'})
  member_2.save()
  roles['member'].append(member_2.id)
  data['accounts'].append(member_2)
  
  member_3 = Account({'id':'test.member_3', 'email':'[email protected]'})
  member_3.save()
  roles['member'].append(member_3.id)
  data['accounts'].append(member_3)
  
  member_4 = Account({'id':'test.member_4', 'email':'[email protected]'})
  member_4.save()
  roles['member'].append(member_4.id)
  data['accounts'].append(member_4)
  
  member_5 = Account({'id':'test.member_5', 'email':'[email protected]'})
  member_5.save()
  roles['member'].append(member_5.id)
  data['accounts'].append(member_5)
  
  rolesVariable.value = roles
  rolesVariable.save()
  
  
  
  # projects
  project_1 = Project({'id':'TEST/PROJECT_1', 'title':'project_1', 
    'partitions':{'ONE':{'': 'number one', '1': 'first'}}, 
    'members':{
      administrator_1.id:'admin' 
    }})
  project_1.save()
  data['projects'].append(project_1)
  
  project_2 = Project({'id':'TEST/PROJECT_2', 'title':'project_2', 
    'partitions':{'TWO':{'': 'number two', '1': 'first', '2':'second'}}, 
    'members':{
      manager_1.id:Project.MANAGER_MEMBER, 
      privileged_member_1.id:'lead', 
      member_1.id:'markup', 
      member_2.id:'db_admin', 
      member_3.id:'developer' 
#.........这里部分代码省略.........
开发者ID:timur-glushan,项目名称:tt,代码行数:103,代码来源:data.py


注:本文中的models.account.Account.save方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。