def display_results(search_query, category, page_id=1): if category == 'posts': posts = BlogPost.query.msearch(search_query).all() return handle_page( endpoint="index.html", items_arg='all_posts', items_lst=posts, count_arg='posts_count', page_id=page_id, title="Search Results", subtitle=f"Displaying user search results for: {search_query}", search=True, mode='posts', query=search_query, category=category) else: users = [ user for user in User.query.msearch(search_query).all() if user.confirmed_email is True ] return handle_page( endpoint="index.html", items_arg='results', items_lst=users, count_arg='posts_count', page_id=page_id, title="Search Results", subtitle=f"Displaying user search results for: {search_query}", search=True, mode='users', query=search_query, category=category)
def handle_account_settings(page_id): options = get_options() title = "Account Settings" subtitle = "Here you will be able to configure your account settings." errors = {} return handle_page(endpoint='index.html', settings="True", items_lst=options, errors=errors, title=title, subtitle=subtitle, page_id=page_id, mode='user', items_arg='options')
def deleted_posts(page_id=1): return handle_page(endpoint='index.html', items_lst=get_deleted_posts(), deleted="True", items_arg='deleted_posts', title="Deleted Posts", subtitle="View and recover deleted posts!", page_id=page_id)
def notifications(page_id=1): notification_items = get_notifications_dict(current_user) return handle_page(endpoint='user.html', notification=True, items_lst=notification_items, page_id=page_id, items_arg='notification_items', title='Notifications', subtitle='View all of your notifications.')
def handle_user_deletion_report(user, **kwargs): if current_user.is_authenticated and current_user.email == User.query.get(user.id).email \ or current_user.admin is True: requested_report = get_user_deletion_report(user.id) if requested_report: return handle_page(endpoint='user.html', items_arg='all_posts', items_lst=requested_report, page_id=1, pre_defined=True, title=f"{user.name}'s Profile", user=user, current_mode='delete-report', admin_count=get_admin_count(), subtitle=f"{user.name}'s Deletion Request Report", api_exists=user_has_api_key(user.id)) else: return abort(404)
def menu(page_id=1): options, title, subtitle, errors = load_menu_elements() return handle_page(endpoint='index.html', settings="True", items_lst=options, errors=errors, title=title, subtitle=subtitle, page_id=page_id, mode='admin', items_arg='options')
def logs(page_id=1): view_filter = request.args.get('view_filter') requested_logs = get_logs_by_filter(view_filter) return handle_page(endpoint='index.html', logs="True", items_lst=requested_logs, page_id=page_id, items_arg='log_items', title='Website Logs', current_view=view_filter, subtitle='View all of the website logs.')
def handle_user_comments(user, page_id=1, **kwargs): return handle_page(endpoint='user.html', items_lst=user.comments, items_arg='comments', page_id=page_id, user=user, current_mode='comments', title=f"{user.name}'s Profile", subtitle=f"{user.name}'s Comments", api_exists=user_has_api_key(user.id), report_exists=user_has_deletion_request(user.id), admin_count=get_admin_count())
def user_table(page_id=1): view_filter = request.args.get('view_filter') users = get_users_by_filter(view_filter) users_dict = get_full_users_dict(users) return handle_page(endpoint='index.html', items_lst=list(users_dict.values()), page_id=page_id, user_table="True", title="User Database Table", subtitle="Visualize your user database effortlessly.", current_view=view_filter, unconfirmed=if_unconfirmed_users(), items_arg='users')
def handle_user_api(user, page_id=1, **kwargs): if current_user.is_authenticated and current_user.email == User.query.get(user.id).email \ or current_user.admin is True: try: requested_api = get_user_api(user.id) except AttributeError: return abort(400) if requested_api: return handle_page(endpoint='user.html', items_lst=requested_api, items_arg='all_posts', page_id=page_id, pre_defined=True, report_exists=user_has_deletion_request(user.id), current_mode='api', title=f"{user.name}'s Profile", subtitle=f"{user.name}'s API Key", user=user, admin_count=get_admin_count(), api_operations=user_has_api_operations(user)) else: return abort(404)
def newsletter_subscribers_table(page_id=1): view_filter = request.args.get('view_filter') requested_subscribers = get_subscribers_by_filter(view_filter) subscribers_dict = get_subscribers_dict(requested_subscribers) return handle_page( endpoint='index.html', newsletter_table="True", items_lst=subscribers_dict, page_id=page_id, items_arg='subscribers', title='Newsletter Subscribers Database', current_view=view_filter, subtitle='Visualize your newsletter subscribers database effortlessly.' )
def show_post(post_id): deleted = request.args.get('deleted') comment_page = request.args.get('c_page', 1) form = CommentForm() requested_post, post_comments = get_post_elements(post_id, deleted) if form.validate_on_submit(): return add_comment(requested_post, form.comment.data) return handle_page("post.html", post=requested_post, deleted=str(deleted), post_id=post_id, form=form, items_arg='comments', count_arg='c_count', items_lst=post_comments, page_arg='current_c', page_id=comment_page)
def show_comment(comment_id): form = ReplyForm() reply_page = request.args.get('c_page', 1) deleted = request.args.get('deleted') post_id = request.args.get('post_id') requested_comment, replies, parent_post = get_comment_elements( comment_id, deleted, post_id) if form.validate_on_submit(): return add_reply(requested_comment, form.reply.data, reply_page) return handle_page(endpoint='post.html', count_arg='c_count', page_id=reply_page, page_arg='current_c', items_lst=replies, items_arg='replies', original_comment=requested_comment, post=parent_post, comments=[requested_comment], form=form, deleted=str(deleted), post_id=post_id, comment=True)
def fetch_page(search_url): page = session.get(search_url).json() handle_page(page) next_url = page["_links"].get("_next") if next_url: fetch_page(next_url)