Ejemplo n.º 1
0
class GroupEdit(RequestHandler):

    title = _('Edit User Group')
    template_path = 'admin/user/group_edit.html'

    @has_permission('admin')
    def prepare(self):

        ID = self.get_argument_int('id', 0)
        self.user = self.db.query(User).get(ID)
        if not self.user:
            self.write( _('No such user: %s') % ID )
            return self.finish()

        self.default_choices = []
        group_choices = []
        for G in self.db.query(Group).all():
            group_choices.append( (G.name, G.name) )
            if G in self.user.groups:
                self.default_choices.append( G.name )

        self.form = UserGroupEditForm(self)
        self.form.groups.choices = group_choices

        self.prepare_kwargs['USER'] = self.user
        self.prepare_kwargs['form'] = self.form


    def get(self):

        self.form.groups.default = self.default_choices
        self.form.process()

        self.render()


    def post(self):

        user = self.user

        if self.form.validate():
            groups = self.request.arguments.get('groups', [])
            group_obj = []

            for name in groups:
                G = self.db.query(Group).filter_by(name=name).first()
                if G: group_obj.append( G )

            user.groups = group_obj
            self.db.add(user)
            self.db.commit()

            url = self.reverse_url('admin:user:view')
            url += '?id=%s' % user.id
            return self.redirect( url )

        self.render()
Ejemplo n.º 2
0
class GroupEdit(RequestHandler):

    title = _('Edit User Group')
    template_path = 'admin/user/group_edit.html'

    @has_permission('admin')
    def prepare(self):

        ID = self.get_argument_int('id', 0)
        self.user = self.db.query(User).get(ID)
        if not self.user:
            self.write(_('No such user: %s') % ID)
            return self.finish()

        self.default_choices = []
        group_choices = []
        for G in self.db.query(Group).all():
            group_choices.append((G.name, G.name))
            if G in self.user.groups:
                self.default_choices.append(G.name)

        self.form = UserGroupEditForm(self)
        self.form.groups.choices = group_choices

        self.prepare_kwargs['USER'] = self.user
        self.prepare_kwargs['form'] = self.form

    def get(self):

        self.form.groups.default = self.default_choices
        self.form.process()

        self.render()

    def post(self):

        user = self.user

        if self.form.validate():
            groups = self.request.arguments.get('groups', [])
            group_obj = []

            for name in groups:
                G = self.db.query(Group).filter_by(name=name).first()
                if G: group_obj.append(G)

            user.groups = group_obj
            self.db.add(user)
            self.db.commit()

            url = self.reverse_url('admin:user:view')
            url += '?id=%s' % user.id
            return self.redirect(url)

        self.render()
Ejemplo n.º 3
0
    def get_edit_groups(self):

        choices = []
        default = []

        groups = self.db2.query(Group).all()
        for G in groups:
            choices.append((G.name, G.name))
            if G in self.user.groups:
                default.append(G.name)

        form = UserGroupEditForm()
        form.groups.choices = choices
        form.groups.default = default
        form.process()

        self.render('admin/user/edit_groups.html', form=form, USER=self.user)
Ejemplo n.º 4
0
    def get_edit_groups(self):

        choices = []
        default = []

        groups = self.db2.query(Group).all()
        for G in groups:
            choices.append( (G.name, G.name) )
            if G in self.user.groups:
                default.append( G.name )

        form = UserGroupEditForm(self)
        form.groups.choices = choices
        form.groups.default = default
        form.process()

        self.render( 'admin/user/edit_groups.html',
                     form = form, USER = self.user )
Ejemplo n.º 5
0
    def prepare(self):

        ID = self.get_argument_int('id', 0)
        self.user = self.db.query(User).get(ID)
        if not self.user:
            self.write(_('No such user: %s') % ID)
            return self.finish()

        self.default_choices = []
        group_choices = []
        for G in self.db.query(Group).all():
            group_choices.append((G.name, G.name))
            if G in self.user.groups:
                self.default_choices.append(G.name)

        self.form = UserGroupEditForm(self)
        self.form.groups.choices = group_choices

        self.prepare_kwargs['USER'] = self.user
        self.prepare_kwargs['form'] = self.form
Ejemplo n.º 6
0
    def prepare(self):

        ID = self.get_argument_int('id', 0)
        self.user = self.db.query(User).get(ID)
        if not self.user:
            self.write( _('No such user: %s') % ID )
            return self.finish()

        self.default_choices = []
        group_choices = []
        for G in self.db.query(Group).all():
            group_choices.append( (G.name, G.name) )
            if G in self.user.groups:
                self.default_choices.append( G.name )

        self.form = UserGroupEditForm(self)
        self.form.groups.choices = group_choices

        self.prepare_kwargs['USER'] = self.user
        self.prepare_kwargs['form'] = self.form