Esempio n. 1
0
def edit_group(id):
    """
    Edit a group
    """
    check_admin()

    add_group = False

    group = Group.query.get_or_404(id)
    form = GroupForm(obj=group)
    if form.validate_on_submit():
        group.name = form.name.data
        group.description = form.description.data
        db.session.commit()
        flash('You have successfully edited the group.')

        # redirect to the groups page
        return redirect(url_for('admin.list_groups'))

    form.description.data = group.description
    form.name.data = group.name
    return render_template('admin/groups/group.html',
                           action="Edit",
                           add_group=add_group,
                           form=form,
                           group=group,
                           title="Edit Group")
Esempio n. 2
0
def add_group():
    """
    Add a group to the database
    """
    check_admin()

    add_group = True

    form = GroupForm()
    if form.validate_on_submit():
        group = Group(name=form.name.data, description=form.description.data)
        try:
            # add group to the database
            db.session.add(group)
            db.session.commit()
            flash('You have successfully added a new group.')
        except:
            # in case group name already exists
            flash('Error: group name already exists.')

        # redirect to groups page
        return redirect(url_for('admin.list_groups'))

    # load group template
    return render_template('admin/groups/group.html',
                           action="Add",
                           add_group=add_group,
                           form=form,
                           title="Add Group")