def group_home(param): group = Groups.query.filter_by(id=param).first() if not group: groups = Groups.find_usernames_for_group_owners() return render_template("index.html", groups=groups, error="That group does not exist") stat = GroupAccountLink.query.filter_by(account_id=current_user.get_id(), group_id=param).first() if not stat: s = False elif stat.get_status(): groups = Groups.find_usernames_for_group_owners() return render_template("index.html", groups=groups, error="You are banned from this group") else: s = True mem = Account.find_usernames_for_members(param) disc = Discussion.find_usernames_for_discussion_owners(param) return render_template("group/index.html", discussions=disc, target=param, status=s, members=mem, group_owner=group.owner_id)
def group_new(): form = GroupForm(request.form) if not form.validate(): return render_template("groups/newGroup.html", form=form) g = Groups(form.heading.data) g.account_id = current_user.id db.session().add(g) db.session().commit() return redirect(url_for("all_groups"))
def group_messages(group_id): categories = Groups.categories(group_id) messages = Groups.findMessagesByGroup(group_id) ug = user_getter() g = Groups.query.get(group_id) return render_template("messages/messages.html", messages=messages, group_id=group_id, g=g, ug=ug, categories=categories, form=MessageForm())
def groups_create(): form = GroupsForm(request.form) if not form.validate(): return render_template("groups/new.html", form=form) members = current_user.id t = Groups(form.name.data, form.desc.data, members) t.account_id = current_user.id db.session().add(t) db.session().commit() return redirect(url_for("index"))
def user_own(): groups = Groups.find_owned_groups(current_user.get_id()) discussions = Discussion.find_owned_discussions(current_user.get_id()) form = EditForm() return render_template("users/own.html", groups=groups, discussions=discussions, form=form)
def group_edit(param): toEdit = Groups.query.filter_by(id=param).first() if request.method == "GET": form = GroupForm() form.name.data = toEdit.name return render_template("group/edit.html", form=form, id=param) form = GroupForm(request.form) if not form.validate(): form = GroupForm() form.name.data = toEdit.name return render_template("group/edit.html", form=form, id=param, error="Minimum length for name is 4") Groups.edit_group(form.name.data, param) return redirect(url_for("user_own"))
def search(): form = SearchForm(request.form) if not form.validate(): groups = Groups.find_usernames_for_group_owners() return render_template("index.html", groups=groups, form=SearchForm(), error="Please search for something") return redirect( url_for("search_results", param=request.form.get("search"), page=1))
def groups_create(): form = GroupsForm(request.form) if not form.validate(): return render_template("groups/new.html", form=form) t = Groups(form.name.data) db.session().add(t) db.session().commit() return redirect(url_for("groups_index"))
def modify_group_form(group_id): g = Groups.query.get(group_id).heading form = GroupForm() form.heading.default = g form.process() categories = Groups.categories(group_id) return render_template("groups/modifyGroup.html", form=form, group_id=group_id, categories=categories)
def search_results(param, page): if page < 1: return redirect(url_for("search_results", param=param, page=1)) groups = Groups.search(param, page) discussions = Discussion.search(param, page) if (not groups or not discussions) and page != 1: return redirect(url_for("search_results", param=param, page=page - 1)) return render_template("search.html", groups=groups, discussions=discussions, current=page, param=param)
def groups_create(): form = GroupForm(request.form) if not form.validate(): return render_template("group/new.html", form=GroupForm(), error="Minimum length for name is 4") g = Groups(form.name.data, current_user.get_id()) db.session().add(g) db.session().commit() ga = GroupAccountLink(g.id, current_user.get_id(), False) db.session().add(ga) db.session().commit() return redirect(url_for("group_home", param=g.id))
def user_edit(): form = EditForm(request.form) groups = Groups.find_usernames_for_group_owners() if not form.validate(): e = "Minimum length for name and password is 3" return render_template("index.html", groups=groups, error=e) p1 = request.form.get("password_new1") p2 = request.form.get("password_new2") pold = request.form.get("password_old") old = Account.query.filter_by(id=current_user.get_id()).first() if old.password == pold: if p1 == p2: Account.change_password(p1, current_user.get_id()) return redirect(url_for("user_own")) else: e = "Your passwords do not match" else: e = "Your old password was wrong" return render_template("index.html", groups=groups, error=e)
def index(): groups = Groups.find_usernames_for_group_owners() return render_template("index.html", groups=groups, form=SearchForm())
def groups_index(): groups = Groups.find_usernames_for_all_discussion_owners() return render_template("group/index.html", groups=groups, error=error)