[Error]TypeError: format requires a mapping

1,051 views
Skip to first unread message

Dewes

unread,
Nov 6, 2012, 10:51:14 AM11/6/12
to web...@googlegroups.com
Hello, I have the following table that worked in web2py 1.99.7, but now I upgraded to 2.2.1, and I got this error that I don't know how to solve:

Traceback (most recent call last):
File "/home/dewes/Dropbox/desenvolvimento/novo_web2py/web2py/gluon/restricted.py", line 212, in restricted
exec ccode in environment
File "/home/dewes/Dropbox/desenvolvimento/novo_web2py/web2py/applications/normas/models/db.py", line 100, in <module>
Field('grupo', db.auth_group, default=auth.user_group(auth.user_id), format='%(role)'),
File "/home/dewes/Dropbox/desenvolvimento/novo_web2py/web2py/gluon/tools.py", line 2990, in user_group
return self.id_group(self.user_group_role(user_id))
File "/home/dewes/Dropbox/desenvolvimento/novo_web2py/web2py/gluon/tools.py", line 2997, in user_group_role
return self.settings.create_user_groups % user
TypeError: format requires a mapping
db.define_table('normas',
    Field('titulo','string',label=T('Título')),
    Field('ementa','text',label=T('Ementa')),
    Field('tipo_norma',db.tipos,label=T('Tipo Norma')),
    Field('numero_norma','integer',label=T('Número')),
    Field('situacao',db.situacao,label=T('Situação')),
    Field('orgao_emissor','list:reference orgaos',label=T('Órgão Emissor')),
    Field('veiculo','string',label=T('Veículo de Publicação')),
    Field('numero_veiculo','integer',label=T('Número do Veículo')),
    Field('dt_emissao','date',label=T('Data de Emissão')),
    Field('dt_publicacao','date',label=T('Data de Publicação')),
    Field('conteudo','text',label=T('Conteúdo')),
    Field('arquivo1','upload',uploadseparate=True),
    Field('arquivo2','upload',uploadseparate=True),
    Field('arquivo3','upload',uploadseparate=True),
    Field('arquivo4','upload',uploadseparate=True),
    Field('arquivo5','upload',uploadseparate=True),
    Field('created_on', 'datetime', default=request.now),
    Field('created_by', db.auth_user, default=auth.user_id),
    Field('grupo', db.auth_group, default=auth.user_group(auth.user_id)),
    format='%(titulo)s'
)
Deleting the field Field('grupo', db.auth_group, default=auth.user_group(auth.user_id)), the error is gone, but I need this field, as a shortcut to restrict the "normas" (normative documents) to the group of people that created it, without going to the user that created and after the group of that user.
I have already tried to put in the Field something like format='%(role)s' or format='%(description)' but to no avail.
Thanks in advance.
More from error:
def user_group_role(self, user_id=None):
if user_id:
user = self.table_user()[user_id]
else:
user = self.user
return self.settings.create_user_groups % user

Niphlod

unread,
Nov 6, 2012, 11:06:31 AM11/6/12
to web...@googlegroups.com
format = '%(role)' is not valid python. a mapping is something like %(variablename)s . in this case, it gets passed to the "user" dictionary, so you should use a "variablename" that is a key of the user dict.
Reply all
Reply to author
Forward
0 new messages