Example #1
0
def edit(group_id):
    if not (ModuleAPI.can_write("group")):
        return abort(403)

    group = Group.by_id(group_id)

    form = EditGroup(request.form, group)
    if request.method == "POST":
        form = EditGroup(request.form)

        if form.validate_on_submit():
            name = form.data["name"].strip()
            maillist = form.data["maillist"].strip().lower()

            valid_form = True

            group_with_same_name = Group.query.filter(Group.name == name, Group.id != group_id).first()
            if group_with_same_name is not None:
                flash("The naam van de groep wordt al gebruikt", "danger")
                valid_form = False

            if valid_form:
                group.name = name
                group.maillist = maillist
                if maillist == "":
                    group.maillist = None
                else:
                    group.maillist = maillist

                db.session.commit()
                google.create_group_if_not_exists(name, maillist)
                group.add_members_to_maillist()

                flash("De groep is aangepast.", "success")

                return redirect(url_for("group.view"))

    return render_template("group/create.htm", title="Pas groep aan", form=form, group=group)
Example #2
0
def create():
    if not (ModuleAPI.can_write("group")):
        return abort(403)

    form = EditGroup(request.form)

    if form.validate_on_submit():
        name = request.form["name"].strip()
        maillist = request.form["maillist"].strip()
        committee_url = form.committee_url.data.strip()
        valid_form = True

        if Group.query.filter(Group.name == name).count() > 0:
            flash("The naam van de groep wordt al gebruikt", "danger")
            valid_form = False

        if valid_form:
            maillist = maillist.strip().lower()
            if maillist == "":
                group = Group(name, None)
            else:
                group = Group(name, maillist)

            db.session.add(group)
            db.session.commit()

            flash("De groep is aangemaakt.", "success")

            if committee_url != "":
                return redirect(
                    "%s?group_id=%d" % (url_for("committee.edit_committee", committee=committee_url), group.id)
                )

            return redirect(url_for("group.view"))

    return render_template("group/create.htm", title="Maak groep", form=form, group=None)