def search(): form = SearchForm() if form.validate_on_submit(): return redirect(url_for('search_results', query=form.search.data)) else: return redirect(url_for('index'))
def test_get_search_term_from_request_none(self): """ Test getting the search term if there is none. Expected result: `None` is returned. """ form = SearchForm() search_term = form._get_search_term_from_request() self.assertIsNone(search_term)
def test_get_search_term_from_request(self): """ Test getting the search term if there is a search term. Expected result: The search term is returned. """ search_term = 'Test Search' form = SearchForm() self.request_context.request.args = {form.search_param: search_term} search_term_from_request = form._get_search_term_from_request() self.assertEqual(search_term, search_term_from_request)
def before_request(): # current_user if current_user.is_authenticated: userController = UserController() current_user.last_seen = userController.set_timpstamp() userController.update(current_user) g.search_form = SearchForm()
def test_search_param(self): """ Test getting the search parameter. Expected result: The name of the search field including the form's prefix is returned. """ prefix = 'text_' form = SearchForm(prefix=prefix) self.assertEqual(f'{prefix}search', form.search_param)
def test_search_term(self): """ Test getting the search term from the form. Expected result: The data of the search field is returned. """ search_term = 'Test SearchÄ' form = SearchForm() form.search.data = search_term self.assertEqual(search_term, form.search_term)
def test_init(self): """ Test initializing the form if a search term is set in the request. Expected result: The search term is set on the search field. """ search_term = 'Test Search' self.request_context.request.args = {'search': search_term} form = SearchForm() self.assertEqual(search_term, form.search.data)
def users_list() -> ResponseType: """ Show a list of all users. :return: The response for this view. """ # Get a search term and the resulting query. If no search term is given, all users will be returned. search_form = SearchForm() user_query = User.get_search_query(search_term=search_form.search_term) pagination = UserPagination(user_query.order_by(User.name)) title = _('Users') return render_template('administration/users.html', title=title, pagination=pagination, search_form=search_form)
def roles_list() -> ResponseType: """ Show a list of all roles. :return: The response for this view. """ # Get a search term and the resulting query. If no search term is given, all roles will by returned. search_form = SearchForm() role_query = Role.get_search_query(search_term=search_form.search_term) # noinspection PyProtectedMember pagination = RolePagination(role_query.order_by(Role._name)) title = _('Roles') return render_template('administration/roles.html', title=title, pagination=pagination, search_form=search_form)
def role_users(name: str) -> str: """ Show a list of all users to whom the given role is assigned. :param name: The name of the role. :return: The response for this view. """ role = Role.load_from_name(name) if role is None: abort(404) # Get a search term and the resulting query. If no search term is given, all users will be returned. search_form = SearchForm() user_query = User.get_search_query(query=role.users, search_term=search_form.search_term) # noinspection PyProtectedMember pagination = UserPagination(user_query.order_by(User.name, User._email)) return render_template('administration/role_users.html', role=name, pagination=pagination, search_form=search_form)
def before_request(): if current_user.is_authenticated: current_user.last_seen = datetime.utcnow() userController = UserController() userController.update(current_user) g.search_form = SearchForm()