def _process(self): form = SearchForm(obj=FormDefaults(exact=True)) form_data = form.data search_results = None num_of_users = User.query.count() num_deleted_users = User.find(is_deleted=True).count() if form.validate_on_submit(): search_results = [] exact = form_data.pop('exact') include_deleted = form_data.pop('include_deleted') include_pending = form_data.pop('include_pending') external = form_data.pop('external') form_data = {k: v for (k, v) in form_data.iteritems() if v and v.strip()} matches = search_users(exact=exact, include_deleted=include_deleted, include_pending=include_pending, external=external, **form_data) for entry in matches: if isinstance(entry, User): search_results.append(UserEntry( profile_url=url_for('.user_profile', entry), **{k: getattr(entry, k) for k in IDENTITY_ATTRIBUTES} )) else: search_results.append(UserEntry( profile_url=None, full_name="{first_name} {last_name}".format(**entry.data.to_dict()), **{k: entry.data.get(k) for k in (IDENTITY_ATTRIBUTES - {'full_name'})} )) search_results.sort(key=attrgetter('first_name', 'last_name')) num_reg_requests = RegistrationRequest.query.count() return WPUsersAdmin.render_template('users_admin.html', form=form, search_results=search_results, num_of_users=num_of_users, num_deleted_users=num_deleted_users, num_reg_requests=num_reg_requests)
def _process(self): admins = set( User.query.filter_by(is_admin=True, is_deleted=False).order_by( db.func.lower(User.first_name), db.func.lower(User.last_name))) form = AdminsForm(admins=admins) if form.validate_on_submit(): added = form.admins.data - admins removed = admins - form.admins.data for user in added: user.is_admin = True logger.warn('Admin rights granted to %r by %r [%s]', user, session.user, request.remote_addr) flash( _('Admin added: {name} ({email})').format( name=user.name, email=user.email), 'success') for user in removed: user.is_admin = False logger.warn('Admin rights revoked from %r by %r [%s]', user, session.user, request.remote_addr) flash( _('Admin removed: {name} ({email})').format( name=user.name, email=user.email), 'success') return redirect(url_for('.admins')) return WPUsersAdmin.render_template('admins.html', 'admins', form=form)
def _process(self): form = MergeForm() if form.validate_on_submit(): source = form['source_user'].data target = form['target_user'].data merge_users(source, target) flash(_('The users have been successfully merged.'), 'success') return redirect(url_for('.user_profile', user_id=target.id)) return WPUsersAdmin.render_template('users_merge.html', form=form)
def _process(self): form = MergeForm() if form.validate_on_submit(): source = form.source_user.data target = form.target_user.data errors, warnings = _get_merge_problems(source, target) if errors: raise BadRequest(_('Merge aborted due to failed sanity check')) if warnings: logger.info("User %s initiated merge of %s into %s (with %d warnings)", session.user, source, target, len(warnings)) else: logger.info("User %s initiated merge of %s into %s", session.user, source, target) merge_users(source, target) flash(_('The users have been successfully merged.'), 'success') return redirect(url_for('.user_profile', user_id=target.id)) return WPUsersAdmin.render_template('users_merge.html', 'users', form=form)
def _process(self): form = SearchForm(obj=FormDefaults(exact=True)) form_data = form.data search_results = None num_of_users = User.query.count() num_deleted_users = User.query.filter_by(is_deleted=True).count() if form.validate_on_submit(): search_results = [] exact = form_data.pop('exact') include_deleted = form_data.pop('include_deleted') include_pending = form_data.pop('include_pending') external = form_data.pop('external') form_data = {k: v for (k, v) in form_data.items() if v and v.strip()} matches = search_users(exact=exact, include_deleted=include_deleted, include_pending=include_pending, include_blocked=True, external=external, allow_system_user=True, **form_data) for entry in matches: if isinstance(entry, User): search_results.append(UserEntry( avatar_url=entry.avatar_url, profile_url=url_for('.user_profile', entry), user=entry, **{k: getattr(entry, k) for k in IDENTITY_ATTRIBUTES} )) else: if not entry.data['first_name'] and not entry.data['last_name']: full_name = '<no name>' initial = '?' else: full_name = f'{entry.data["first_name"]} {entry.data["last_name"]}'.strip() initial = full_name[0] search_results.append(UserEntry( avatar_url=url_for('assets.avatar', name=initial), profile_url=None, user=None, full_name=full_name, **{k: entry.data.get(k) for k in (IDENTITY_ATTRIBUTES - {'full_name'})} )) search_results.sort(key=attrgetter('full_name')) num_reg_requests = RegistrationRequest.query.count() return WPUsersAdmin.render_template('users_admin.html', 'users', form=form, search_results=search_results, num_of_users=num_of_users, num_deleted_users=num_deleted_users, num_reg_requests=num_reg_requests)
def _process(self): admins = set(User.query .filter_by(is_admin=True, is_deleted=False) .order_by(db.func.lower(User.first_name), db.func.lower(User.last_name))) form = AdminsForm(admins=admins) if form.validate_on_submit(): added = form.admins.data - admins removed = admins - form.admins.data for user in added: user.is_admin = True logger.warn('Admin rights granted to %r by %r [%s]', user, session.user, request.remote_addr) flash(_('Admin added: {name} ({email})').format(name=user.name, email=user.email), 'success') for user in removed: user.is_admin = False logger.warn('Admin rights revoked from %r by %r [%s]', user, session.user, request.remote_addr) flash(_('Admin removed: {name} ({email})').format(name=user.name, email=user.email), 'success') return redirect(url_for('.admins')) return WPUsersAdmin.render_template('admins.html', 'admins', form=form)
def _process(self): requests = RegistrationRequest.query.order_by(RegistrationRequest.email).all() return WPUsersAdmin.render_template('registration_requests.html', 'users', pending_requests=requests)
def _process(self): requests = RegistrationRequest.query.order_by( RegistrationRequest.email).all() return WPUsersAdmin.render_template('registration_requests.html', pending_requests=requests)
def _process(self): form = LocalRegistrationForm() return WPUsersAdmin.render_template('users_create.html', form=form)