예제 #1
0
class ResourceAdd(RequestHandler):

    title = _('Add Resource For User')
    template_path = 'admin/user/resource_add.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()

        type_choices = []
        for x, y in Resource.RESOURCE_TYPE:
            type_choices.append( (str(x), y) )

        self.form = ResourceForm(self)
        self.form.type.choices = type_choices

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

    def get(self):

        self.form.process()
        self.render()

    def post(self):

        form = self.form
        user = self.user

        if form.validate():
            new = Resource( user = user,
                            rtype = form.type.data,
                            size = form.size.data,
                            effect_date = form.effect_date.data,
                            expired_date = form.expired_date.data )
            self.db.add( new )
            self.db.commit()

            user.profile.update_resource_total()
            self.db.commit()

            # count be choices, email notice
            resource_mail_notice(self, user)

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

        self.render()
예제 #2
0
class ResourceAdd(RequestHandler):

    title = _('Add Resource For User')
    template_path = 'admin/user/resource_add.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()

        type_choices = []
        for x, y in Resource.RESOURCE_TYPE:
            type_choices.append((str(x), y))

        self.form = ResourceForm(self)
        self.form.type.choices = type_choices

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

    def get(self):

        self.form.process()
        self.render()

    def post(self):

        form = self.form
        user = self.user

        if form.validate():
            new = Resource(user=user,
                           rtype=form.type.data,
                           size=form.size.data,
                           effect_date=form.effect_date.data,
                           expired_date=form.expired_date.data)
            self.db.add(new)
            self.db.commit()

            # count be choices, email notice
            resource_mail_notice(self, user)

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

        self.render()
예제 #3
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()

        type_choices = []
        for x, y in Resource.RESOURCE_TYPE:
            type_choices.append((str(x), y))

        self.form = ResourceForm(self)
        self.form.type.choices = type_choices

        self.prepare_kwargs['form'] = self.form
        self.prepare_kwargs['USER'] = self.user
예제 #4
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()

        type_choices = []
        for x, y in Resource.RESOURCE_TYPE:
            type_choices.append( (str(x), y) )

        self.form = ResourceForm(self)
        self.form.type.choices = type_choices

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