Exemplo n.º 1
0
    def update(self):
        item = Session.query(self.model).get(self.get_id())
        params = self.request.params.copy()
    
        k = 'User-%d-password'%item.id
        if params and params[k] != item.password:
            if not params[k]:
                params[k] = item.password
            else:
                params[k] = self.model.get_pass_hash(params[k])

        form = FieldSet(item, data=params or None)
        self.model._configure_form(form)

        if self.request.params:
            if form.validate():
                form.sync()
                self.model._before_update(item, form, params)
                Session.add(form.model)
                self.request.session.flash(u'Item atualizado com sucesso.', 'success')
                return HTTPFound(location=g.url(self.url_base))
            else:
                self.request.session.flash(u'Dados inválidos', 'error')

        params = dict(form=form, url_base=self.url_base)
        
        if self.renderer_base:
            renderer = self.renderer_base+'/edit.jinja2'
        else:
            renderer = '/bases/crud_edit.jinja2'

        return self.render(renderer, params)
Exemplo n.º 2
0
    def login(self):
        form = FieldSet(User, data=self.request.POST if self.request.POST else None)
        form.configure(
            include=[form.email, form.password],
            options=[
                form.password.password()
            ]
        )

        if self.request.POST:
            user = Session.query(User).filter(
                (User.email==self.request.POST['User--email']) &
                (User.password==User.get_pass_hash(self.request.POST['User--password']))
            ).first()

            if user is not None:
                session = self.request.session
                session['user_id'] = user.id
                session['user_name'] = user.nickname
                session['user_email'] = user.email

                return HTTPFound(location=self.request.GET.get('back_to', url('post', self.request)))
        
        print '\n\n\n\n\n'
        return dict(form=form)
Exemplo n.º 3
0
    def _do_create(self):
        form = FieldSet(self.model, data=self.request.params or None)
        self.model._configure_form(form)
        if self.request.params:
            if form.validate():
                form.sync()
                self.model._before_create(form, self.request.params)
                Session.add(form.model)
                self.request.session.flash(u'Item successfully added.', 'success')
                return HTTPFound(location=g.url(self.url_base))
            else:
                self.request.session.flash(u'Invalid data.', 'error')

        return dict(form=form, url_base=self.url_base)
Exemplo n.º 4
0
    def create(self):
        form = FieldSet(self.model, data=self.request.POST or None)
        self.model._configure_form(form)
        if self.request.POST:
            if form.validate():
                form.sync()
                self.model._before_create(form, self.request.POST)
                Session.add(form.model)
                self.request.session.flash(u'Item incluído com sucesso.', 'success')
                return HTTPFound(location=g.url(self.url_base))
            else:
                self.request.session.flash(u'Dados inválidos.', 'error')

        return dict(form=form, url_base=self.url_base)
Exemplo n.º 5
0
    def _do_create(self):
        form = FieldSet(self.model, data=self.request.params or None)
        self.model._configure_form(form)
        if self.request.params:
            if form.validate():
                form.sync()
                self.model._before_create(form, self.request.params)
                Session.add(form.model)
                self.request.session.flash(u'Item successfully added.',
                                           'success')
                return HTTPFound(location=g.url(self.url_base))
            else:
                self.request.session.flash(u'Invalid data.', 'error')

        return dict(form=form, url_base=self.url_base)
Exemplo n.º 6
0
    def _do_update(self):
        item = Session.query(self.model).get(self.get_id())
        
        form = FieldSet(item, data=self.request.params or None)
        self.model._configure_form(form)
        if self.request.params:
            if form.validate():
                form.sync()
                self.model._before_update(item, form, self.request.params)
                Session.add(form.model)
                self.request.session.flash(u'Item atualizado com sucesso.', 'success')
                return HTTPFound(location=g.url(self.url_base))
            else:
                self.request.session.flash(u'Dados inválidos', 'error')

        return dict(form=form, url_base=self.url_base)
Exemplo n.º 7
0
    def _do_update(self):
        item = Session.query(self.model).get(self.get_id())

        form = FieldSet(item, data=self.request.params or None)
        self.model._configure_form(form)
        if self.request.params:
            if form.validate():
                form.sync()
                self.model._before_update(item, form, self.request.params)
                Session.add(form.model)
                self.request.session.flash(u'Item atualizado com sucesso.',
                                           'success')
                return HTTPFound(location=g.url(self.url_base))
            else:
                self.request.session.flash(u'Dados inválidos', 'error')

        return dict(form=form, url_base=self.url_base)
Exemplo n.º 8
0
    def create(self):
        if self.auth():
            return HTTPFound(location=self.urlLogin)

        form = FieldSet(self.model, data=self.request.POST or None)
        self.model._configure_form(form)
        if self.request.POST:
            if form.validate():
                form.sync()
                self.model._before_create(form, self.request.POST)
                Session.add(form.model)
                self.request.session.flash(u'Item incluído com sucesso.', 'success')
                return HTTPFound(location=g.url(self.url_base))
            else:
                self.request.session.flash(u'Dados inválidos.', 'error')

        return dict(form=form, url_base=self.url_base)
Exemplo n.º 9
0
    def login(self):
        form = FieldSet(User,
                        data=self.request.POST if self.request.POST else None)
        form.configure(include=[form.email, form.password],
                       options=[form.password.password()])

        if self.request.POST:
            user = Session.query(User).filter(
                (User.email == self.request.POST['User--email'])
                & (User.password == User.get_pass_hash(
                    self.request.POST['User--password']))).first()

            if user is not None:
                session = self.request.session
                session['user_id'] = user.id
                session['user_name'] = user.nickname
                session['user_email'] = user.email

                return HTTPFound(location=self.request.GET.get(
                    'back_to', url('post', self.request)))

        print '\n\n\n\n\n'
        return dict(form=form)
Exemplo n.º 10
0
    def update(self):
        if self.auth():
            return HTTPFound(location=self.urlLogin)

        item = Session.query(self.model).get(self.get_id())
        params = self.request.params.copy()

        k = 'User-%d-password' % item.id
        if params and params[k] != item.password:
            if not params[k]:
                params[k] = item.password
            else:
                params[k] = self.model.get_pass_hash(params[k])

        form = FieldSet(item, data=params or None)
        self.model._configure_form(form)

        if self.request.params:
            if form.validate():
                form.sync()
                self.model._before_update(item, form, params)
                Session.add(form.model)
                self.request.session.flash(u'Item atualizado com sucesso.',
                                           'success')
                return HTTPFound(location=g.url(self.url_base))
            else:
                self.request.session.flash(u'Dados inválidos', 'error')

        params = dict(form=form, url_base=self.url_base)

        if self.renderer_base:
            renderer = self.renderer_base + '/edit.jinja2'
        else:
            renderer = '/bases/crud_edit.jinja2'

        return self.render(renderer, params)