def join_community(name): """ Route that handles adding the current user as a community member. """ community = community_service.get_community(name) if community: community_member = community_service.get_community_member( community.id, current_user.id) if community_member == None: community_service.create_community_member(community, current_user) flash("Successfully joined community.", "primary") return redirect(url_for("community.community", name=community.name)) else: abort(404)
def leave_community(name): """ Route that handles removing the current user as a community member. """ community = community_service.get_community(name) if community: community_member = community_service.get_community_member( community.id, current_user.id) if community_member: community_service.delete_community_member(community_member) flash("Successfully left community.", "primary") return redirect(url_for("community.community", name=community.name)) else: abort(404)
def top_community(name): """ Route for page displaying a community and its posts sorted by number of upvotes. """ page = int(request.args.get("page", 1)) community = community_service.get_community(name) if community: posts = community_service.get_community_posts(community.id, page, True) community_member = None if current_user.is_authenticated: community_member = community_service.get_community_member( community.id, current_user.id) return render_template( "community.jinja2", tab="top", community=community, posts=posts, community_member=community_member, ) else: abort(404)
def community(name): """ Route for page displaying a community and its posts sorted by date created. """ page = int(request.args.get("page", 1)) community = community_service.get_community(name) if community: posts = community_service.get_community_posts(community.id, page, False) community_member = None if current_user.is_authenticated: community_member = community_service.get_community_member( community.id, current_user.id) return render_template( "community.html", tab="recent", community=community, posts=posts, community_member=community_member, ) else: abort(404)