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): 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)