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)
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 += ' ' 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
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)
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)
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)
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)
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)
def post_link(post): return g.url('blog_entry', id=post.id, alias=post.alias)
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))