With longer bits of code like this you might want to consider using our
paste instance at: http://paste.turbogears.org
It is a lot easier to just give the link than it is to let the mailing
list mangle your Python code on longer snippets like this.
I am guessing that your problem is that accessing everything as an
'Administrador_orc' works, but the first controller that should allow
'Supervisor' to access it is not? If that is the case make sure to
check the group membership for the account and make sure that you are
specifying the group name correctly. I didn't really see anything wrong
with the code you posted.
-Adam
Petry wrote:
> Hi, I've a SubController with four methods, three of these, in your
> decorator Identity I have many roles, including a administrator role
> and another method with only a administrator Role. When i access
> these method with a administrator user, everything works right, but
> when I access the methods with for example, with a Supervisor role, I
> receive the "Please login" message!
>
> Above, my subcontroller class:
>
> import logging
>
> import cherrypy
>
> import time
>
> import turbogears
> from turbogears import controllers, expose, validate, redirect
> from turbogears import identity
> from turbogears.database import session
>
> from turbogears import widgets
> from turbogears.widgets import DataGrid
> from turbogears.widgets import PaginateDataGrid
> from turbogears.widgets import
> RemoteForm,TextField,CheckBox,RadioButtonList,PasswordField
> from turbogears.widgets.base import WidgetsList
>
> from elementtree import ElementTree as ET
> from tgorcamentos import json
>
> from Orcamentos.Despesas.CentroCustoDespesa import CentroCustoDespesa
> from Orcamentos.Despesas.Despesas import Despesas as DespesasOrcamentos
> from Orcamentos.Despesas.ContaContabil import ContaContabil
>
>
> log = logging.getLogger("tgorcamentos.Orcamentos.Despesas.controllers")
>
>
>
> def getString(fieldname):
> return lambda x: unicode(x.get(fieldname),'utf-8')
> def getValor(fieldname):
> return lambda x: x.get(fieldname)
>
>
> # Gera um Link dentro do DataGrid.
> class geraLink:
> def __init__(self, baseurl, id, title, action):
> self.baseurl=baseurl
> self.id=id
> self.title=title
> self.action=action
>
> def __call__(self, obj):
> url=controllers.url(self.baseurl,
> dict(id=obj[self.id],action=self.action))
> link = ET.Element('a', href=url, id='gridLink' )
> link.text = obj[self.title]
> return link
>
>
>
>
> class ContasContabeis:
>
> #Datagrid (Lista Contas Contabeis Cadastradas)
>
> @expose(template="tgorcamentos.templates.contascontabeis")
>
> @identity.require(identity.in_any_group('Administrador_orc','ChefeDepartamento','ChefeGabinete',\
>
> 'Coordenador','CoordenadorCurso','DiretorCampus','DiretorCentro',\
>
> 'DiretorInstituto','DiretorMantida','DiretorNucleo','ProReitor',\
> 'Reitor','Supervisor'))
> @turbogears.paginate('contascontabeis', default_order='codigo',
> limit=25)
> def index(self):
> cadastro = self.cadastro()
>
> mylink=geraLink('contascontabeis_cadastro',
> 'COD_CONTA_CONTABIL', 'COD_CONTA_CONTABIL', 'edit')
>
> self.ccustoDespesa=CentroCustoDespesa()
> contas=self.ccustoDespesa.carregarContasContabeis()
>
> lista_contas = PaginateDataGrid(
> fields=[
> PaginateDataGrid.Column(name='codigo', getter=mylink,
> title=unicode('Código','utf-8'),
> options=dict(sortable=True)),
>
> PaginateDataGrid.Column(name=unicode('descrição','utf-8'),
> getter=getString('DESCRICAO'),
> options=dict(sortable=True))
> ])
>
> return dict(contascontabeis=contas , list=lista_contas)
>
>
> @expose(template="tgorcamentos.templates.contascontabeis_cadastro")
> @identity.require(identity.in_group('Administrador_orc'))
> def cadastro(self):
> item_searchform = RemoteForm(
> name="FormCtaContabil",
> fields=[TextField("codigo"),
> TextField ("descricao")],
> submit_text="Enviar")
> return dict(item_searchform=item_searchform)
>
>
> @turbogears.expose(format = "json")
> @identity.require(identity.in_group('Administrador_orc'))
> def cadastrar(self, **kw):
> self.ccontabil = ContaContabil()
> self.ccontabil.descricao=str(kw['descricao'])
> self.ccontabil.codigo=str(kw['codigo'])
> if self.ccontabil.gravar():
> return "Item cadastrado com sucesso."
> else:
> return "Erro ao gravar!"
> cadastrar = expose()(cadastrar)
>
>
> class Orcamentos:
> contascontabeis = ContasContabeis()
>
>
> PS.: Sorry about my english, it's not so good! :P
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"TurboGears" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/turbogears?hl=en
-~----------~----~----~----~------~----~------~--~---