Better Security Rules

bzr revid: fp@tinyerp.com-20080904002248-vh8kpyyckkdszttn
This commit is contained in:
Fabien Pinckaers 2008-09-04 02:22:48 +02:00
parent 90b59fe85a
commit c65d70e168
7 changed files with 29 additions and 14 deletions

View File

@ -211,6 +211,7 @@
<field name="usage"/>
<field name="header"/>
<field name="report_type"/>
<field name="attachment"/>
<field colspan="4" name="groups_id"/>
</form>
</field>
@ -224,6 +225,8 @@
<field name="name"/>
<field name="type"/>
<field name="report_name"/>
<field name="report_type"/>
<field name="attachment"/>
</tree>
</field>
</record>

View File

@ -128,8 +128,8 @@ class report_xml(osv.osv):
('raw', 'raw'),
('sxw', 'sxw'),
], string='Type', required=True),
'groups_id': fields.many2many('res.groups', 'res_groups_report_rel', 'uid', 'gid', 'Groups')
'groups_id': fields.many2many('res.groups', 'res_groups_report_rel', 'uid', 'gid', 'Groups'),
'attachment': fields.char('Save As Attachment Prefix', size=32, help='This is the prefix of the file name the print will be saved as attachement. Keep empty to not save the printed reports')
}
_defaults = {
'type': lambda *a: 'ir.actions.report.xml',
@ -138,6 +138,7 @@ class report_xml(osv.osv):
'header': lambda *a: True,
'report_sxw_content': lambda *a: False,
'report_type': lambda *a: 'pdf',
'attachment': lambda *a: False,
}
report_xml()
@ -560,7 +561,3 @@ class act_window_close(osv.osv):
'type': lambda *a: 'ir.actions.act_window_close',
}
act_window_close()
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:

View File

@ -365,7 +365,7 @@ class ir_model_data(osv.osv):
def _get_id(self,cr, uid, module, xml_id):
ids = self.search(cr, uid, [('module','=',module),('name','=', xml_id)])
assert len(ids)==1, '%d reference(s) to %s. You should have only one !' % (len(ids),xml_id)
assert len(ids)==1, '%d reference(s) to %s. You should have one and only one !' % (len(ids),xml_id)
return ids[0]
_get_id = tools.cache()(_get_id)

View File

@ -103,6 +103,7 @@
<rng:optional><rng:attribute name="xsl"/></rng:optional>
<rng:optional> <rng:attribute name="auto" /> </rng:optional>
<rng:optional> <rng:attribute name="header" /> </rng:optional>
<rng:optional> <rng:attribute name="attachment" /> </rng:optional>
<rng:empty />
</rng:element>
</rng:define>

View File

@ -493,6 +493,8 @@ class orm_template(object):
(prefix == field[0:len(prefix)]):
if fields_def[field[len(prefix)]]['type'] == 'integer':
res = line[i] and int(line[i])
elif fields_def[field[len(prefix)]]['type'] == 'boolean':
res = line[i] and eval(line[i])
elif fields_def[field[len(prefix)]]['type'] == 'float':
res = line[i] and float(line[i])
elif fields_def[field[len(prefix)]]['type'] == 'selection':

View File

@ -550,11 +550,12 @@ class rml_parse(object):
return res
class report_sxw(report_rml):
def __init__(self, name, table, rml, parser=rml_parse, header=True):
def __init__(self, name, table, rml, parser=rml_parse, header=True, store=False):
report_rml.__init__(self, name, table, rml, '')
self.name = name
self.parser = parser
self.header = header
self.store = store
def getObjects(self, cr, uid, ids, context):
table_obj = pooler.get_pool(cr.dbname).get(self.table)
@ -572,10 +573,12 @@ class report_sxw(report_rml):
report_type = 'pdf'
report_xml = None
title=''
attach = False
if report_xml_ids:
title = ir_actions_report_xml_obj.browse(cr,uid,report_xml_ids)[0].name
report_xml = ir_actions_report_xml_obj.browse(cr, uid, report_xml_ids[0],
context=context)
title = report_xml.name
attach = report_xml.attachment
rml = report_xml.report_rml_content
report_type = report_xml.report_type
else:
@ -654,15 +657,24 @@ class report_sxw(report_rml):
rml_parser.preprocess(objs, data, ids)
rml_dom = xml.dom.minidom.parseString(rml)
rml2 = rml_parser._parse(rml_dom, objs, data, header=self.header)
#if os.name != "nt":
# f = file("/tmp/debug.rml", "w")
# f.write(rml2)
# f.close()
if rml_parser.logo:
logo = base64.decodestring(rml_parser.logo)
create_doc = self.generators[report_type]
pdf = create_doc(rml2, logo,title)
if attach:
# TODO: save multiple print with symbolic links in attach
pool.get('ir.attachment').create(cr, uid, {
'name': title or _('print'),
'datas': pdf,
'datas_fname': attach+time.strftime('%Y-%m-%d')+'.'+report_type,
'res_model': self.table,
'res_id': ids[0]
}, context=context
)
cr.commit()
return (pdf, report_type)

View File

@ -256,7 +256,7 @@ form: module.record_id""" % (xml_id,)
for dest,f in (('name','string'),('model','model'),('report_name','name')):
res[dest] = rec.getAttribute(f).encode('utf8')
assert res[dest], "Attribute %s of report is empty !" % (f,)
for field,dest in (('rml','report_rml'),('xml','report_xml'),('xsl','report_xsl')):
for field,dest in (('rml','report_rml'),('xml','report_xml'),('xsl','report_xsl'),('attachment','attachment')):
if rec.hasAttribute(field):
res[dest] = rec.getAttribute(field).encode('utf8')
if rec.hasAttribute('auto'):