Ejemplo 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)
Ejemplo n.º 2
0
 def _operations_col(self, obj, route_name):
     route_name = route_name+'_action'
     result = '<span class="operations">'
     result += '<a href="%s">Editar</a>' % g.url(route_name, action='update', params=[obj.id])
     result += '&nbsp;'
     result += '<a href="%s" onclick="return confirm(\'Are you sure you want to delete?\')">Remover</a>' % g.url(route_name, action='delete', params=[obj.id])
     result += '</span>'
     return result
Ejemplo n.º 3
0
 def _operations_col(self, obj, route_name):
     route_name = route_name+'_action'
     result = '<span class="operations">'
     result += '<a href="%s">Editar</a>' % g.url(route_name, action='update', params=[obj.id])
     result += '&nbsp;'
     result += '<a href="%s" onclick="return confirm(\'Are you sure you want to delete?\')">Remover</a>' % g.url(route_name, action='delete', params=[obj.id])
     result += '</span>'
     return result
Ejemplo n.º 4
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)
Ejemplo n.º 5
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)
Ejemplo n.º 6
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)
Ejemplo 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)
Ejemplo n.º 8
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)
Ejemplo n.º 9
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)
Ejemplo 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)
Ejemplo n.º 11
0
def post_link(post):
    return g.url('blog_entry', id=post.id, alias=post.alias)
Ejemplo n.º 12
0
 def _do_delete(self):
     item = Session.query(self.model).get(self.get_id())
     Session.delete(item)
     self.request.session.flash(u'Item deleted successfully.', 'success')
     return HTTPFound(location=g.url(self.url_base))
Ejemplo n.º 13
0
def post_link(post):
    return g.url('blog_entry', id=post.id, alias=post.alias)
Ejemplo n.º 14
0
 def _do_delete(self):
     item = Session.query(self.model).get(self.get_id())
     Session.delete(item)
     self.request.session.flash(u'Item deleted successfully.', 'success')
     return HTTPFound(location=g.url(self.url_base))