def view_group(id): if not load_user(current_user.get_id()): return abort(401, description="Unauthorised to view this page") # Check admin status profile_id = request.args["profile_id"] admin_check = GroupMembers.query.filter_by(profile_id=profile_id, group_id=id).first() # Retrieve group members members = GroupMembers.query.with_entities( GroupMembers.group_id, GroupMembers.profile_id, Profile.name).filter_by(group_id=id).outerjoin(Profile) # SELECT group_members.group_id AS group_members_group_id, # profiles.name AS profiles_name # FROM group_members # LEFT OUTER JOIN profiles # ON profiles.profile_id = group_members.profile_id # WHERE group_members.group_id = %(group_id_1)s # Retrieve group details group = Group.query.filter_by(group_id=id).first() # load remove button form = RemoveButton() return render_template("view_group.html", id=id, admin_check=admin_check, members=members, group=group, form=form, profile_id=profile_id)
def restore_content(id, content_id): form = RemoveButton() if form.submit.data: profile = Profile.query.filter_by(profile_id=id).first() content = Content.query.filter_by(content_id=content_id).first() for item in profile.unrecommend: if item.content_id == content.content_id: profile.unrecommend.remove(item) db.session.commit() return redirect( url_for("web_profiles.view_profile", id=profile.profile_id))
def view_workhistory(id): user = load_user(current_user.get_id()) workhistory = WorkHistory.query.filter_by(id=id).first() if not workhistory: flash("workhistory not found") return redirect( url_for("web_workhistory.view_workhistory", id=workhistory.id)) form1 = UnrecommendButton() form2 = RemoveButton() return render_template("view_workhistory.html", workhistory=workhistory, form1=form1, form2=form2)
def view_profile(id): user = load_user(current_user.get_id()) profile = Profile.query.filter_by( profile_id=id, user_id=user.user_id).first() if not profile: flash("Profile not found") return redirect( url_for("web_profiles.view_profile", id=profile.profile_id)) contents = Content.query.all() form1 = UnrecommendButton() form2 = RemoveButton() return render_template( "view_profile.html", contents=contents, profile=profile, form1=form1, form2=form2)
def remove_content(id): if not load_user(current_user.get_id()): return abort(401, description="Unauthorised to view this page") form = RemoveButton() if form.submit.data: group = Group.query.filter_by(group_id=id).first() content = Content.query.filter_by( content_id=request.args["content_id"]).first() for item in group.content: if item == content: group.content.remove(item) db.session.commit() flash(f"Removed content {item.title} from group {id}") return redirect( url_for("web_groups.view_group", id=id, profile_id=request.args["profile_id"]))
def remove_member(id, member_id): if not load_user(current_user.get_id()): return abort(401, description="Unauthorised to view this page") form = RemoveButton() if form.submit.data: member = GroupMembers.query.filter_by(group_id=id, profile_id=member_id).first() if not member: flash("Member not found") return redirect( url_for("web_groups.view_group", id=id, profile_id=request.args["profile_id"])) db.session.delete(member) db.session.commit() flash(f"Member {member.profile_id} removed") return redirect( url_for("web_groups.view_group", id=id, profile_id=request.args["profile_id"]))