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': '*****@*****.**', '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()
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__()
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)