Example #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")
Example #2
0
    def post_edit(self):

        perm_choices = []
        for P in self.db.query(Permission).all():
            perm_choices.append( (P.codename, P.name) )

        form = GroupForm(self)
        form.perms.choices = perm_choices

        if form.validate():

            self.group.name = form.name.data
            self.group.description = form.description.data
            bak = self.group.permissions
            self.group.permissions = []
            for codename in form.perms.data:
                P = self.db.query(Permission).filter_by(
                    codename = codename ).first()
                self.group.permissions.append(P)
            #print 'self.group.permissions = ', self.group.permissions

            self.db.commit()

            url = self.application.reverse_url('admin:group')
            return self.redirect( url )

        # Have a error
        self.render( 'admin/group/edit.html',
                     form = form, GROUP = self.group )
Example #3
0
    def post_edit(self):

        perm_choices = []
        for P in self.db.query(Permission).all():
            perm_choices.append((P.codename, P.name))

        form = GroupForm(self)
        form.perms.choices = perm_choices

        if form.validate():

            self.group.name = form.name.data
            self.group.description = form.description.data
            bak = self.group.permissions
            self.group.permissions = []
            for codename in form.perms.data:
                P = self.db.query(Permission).filter_by(
                    codename=codename).first()
                self.group.permissions.append(P)
            #print 'self.group.permissions = ', self.group.permissions

            self.db.commit()

            url = self.application.reverse_url('admin:group')
            return self.redirect(url)

        # Have a error
        self.render('admin/group/edit.html', form=form, GROUP=self.group)
Example #4
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")
Example #5
0
def form(request, id=False):
    if id:
        instance = Core.current_user().get_permitted_objects("VIEW",
                                                             Group).get(id=id)
        msg = _("Successfully edited group")
    else:
        instance = Group()
        msg = _("Successfully added new group")

    #Save and set to active, require valid form
    if request.method == 'POST':
        form = GroupForm(request.POST, instance=instance)
        if form.is_valid():
            o = form.save(commit=False)
            o.company = Core.current_user().get_company()
            o.save()
            form.save_m2m()

            request.message_success(msg)
            return redirect(overview)

    else:
        form = GroupForm(instance=instance)

    return render(request, "admin/groups/form.html", {
        'title': _("Group"),
        'group': instance,
        'form': form
    })
Example #6
0
    def get_edit(self):

        perm_choices = []
        perm_default = []

        for P in self.db2.query(Permission).all():
            perm_choices.append((P.codename, P.name))
            if P in self.group.permissions:
                perm_default.append(P.codename)

        form = GroupForm()
        form.perms.choices = perm_choices
        form.perms.default = perm_default
        form.process()
        form.name.data = self.group.name
        form.description.data = self.group.description

        self.render("admin/group/edit.html", title=_("Edit Group %s") % self.group.name, GROUP=self.group, form=form)
Example #7
0
    def get_edit(self):

        perm_choices = []
        perm_default = []

        for P in self.db.query(Permission).all():
            perm_choices.append((P.codename, P.name))
            if P in self.group.permissions:
                perm_default.append(P.codename)

        form = GroupForm(self)
        form.perms.choices = perm_choices
        form.perms.default = perm_default
        form.process()
        form.name.data = self.group.name
        form.description.data = self.group.description

        self.render('admin/group/edit.html',
                    title=self.trans(_('Edit Group %s')) % self.group.name,
                    GROUP=self.group,
                    form=form)
Example #8
0
    def post_add(self):

        form = GroupForm(self.request.arguments)

        if form.validate():

            group = self.db2.query(Group).filter_by(name=form.name.data).all()
            if group:
                form.name.errors.append(_("This name is occupied"))

            else:
                newgroup = Group(name=form.name.data, description=form.description.data)

                self.db2.add(newgroup)
                self.db2.commit()

                url = self.application.reverse_url("admin:group")
                return self.redirect(url)

        # Have a error
        self.render("admin/group/add.html", form=form, group=self.group)
Example #9
0
def form (request, id=False):
    if id:
        instance = Core.current_user().get_permitted_objects("VIEW", Group).get(id=id)
        msg = _("Successfully edited group")
    else:
        instance = Group()
        msg = _("Successfully added new group")

    #Save and set to active, require valid form
    if request.method == 'POST':
        form = GroupForm(request.POST, instance=instance)
        if form.is_valid():
            o = form.save(commit=False)
            o.company = Core.current_user().get_company()
            o.save()
            form.save_m2m()

            request.message_success(msg)
            return redirect(overview)

    else:
        form = GroupForm(instance=instance)

    return render(request, "admin/groups/form.html",
                  {'title': _("Group"), 'group': instance, 'form': form})
Example #10
0
    def post_add(self):

        form = GroupForm(self)

        if form.validate():

            group = self.db.query(Group).filter_by(name=form.name.data).all()
            if group:
                form.name.errors.append(self.trans(_('This name is occupied')))

            else:
                newgroup = Group(name=form.name.data,
                                 description=form.description.data)

                self.db.add(newgroup)
                self.db.commit()

                url = self.application.reverse_url('admin:group')
                return self.redirect(url)

        # Have a error
        self.render('admin/group/add.html', form=form, group=self.group)
Example #11
0
    def post_add(self):

        form = GroupForm(self)

        if form.validate():

            group = self.db.query(Group).filter_by( name=form.name.data ).all()
            if group:
                form.name.errors.append( self.trans(_('This name is occupied')) )

            else:
                newgroup = Group(
                    name = form.name.data,
                    description = form.description.data )

                self.db.add(newgroup)
                self.db.commit()

                url = self.application.reverse_url('admin:group')
                return self.redirect( url )

        # Have a error
        self.render( 'admin/group/add.html', form = form, group = self.group )
Example #12
0
 def get_add(self):
     self.render('admin/group/add.html',
                 title=self.trans(_('Create New Group')),
                 form=GroupForm(self))