[FIX] font: correctly place font_scan call, use superuser_id, restrict rights for general users, invert name and family

bzr revid: mat@openerp.com-20131209125705-gk2sjiwxqyxc702r
This commit is contained in:
Martin Trigaux 2013-12-09 13:57:05 +01:00
parent 87dfe75013
commit 75d92a40bd
5 changed files with 24 additions and 18 deletions

View File

@ -63,9 +63,23 @@ class res_font(osv.Model):
}, context=context)
return True
def font_scan(self, cr, uid, context=None):
self._discover_fonts(cr, uid, context=context)
return self._register_fonts(cr, uid, context=context)
def font_scan(self, cr, uid, lazy=False, context=None):
if lazy:
# lazy loading, scan only if no fonts in db
found_fonts_ids = self.search(cr, uid, [('path', '!=', '/dev/null')], context=context)
if not found_fonts_ids:
# no scan yet or no font found on the system, scan the filesystem
self._discover_fonts(cr, uid, context=context)
self._register_fonts(cr, uid, context=context)
else:
if len(customfonts.CustomTTFonts) == 0:
# CustomTTFonts list is empty
for font in self.browse(cr, uid, found_fonts_ids, context=context):
customfonts.CustomTTFonts.append((font.family, font.name, font.path, font.mode))
else:
self._discover_fonts(cr, uid, context=context)
self._register_fonts(cr, uid, context=context)
return True
def _discover_fonts(self, cr, uid, context=None):
"""Scan fonts on the file system, add them to the list of known fonts

View File

@ -43,7 +43,7 @@
"access_ir_values_group_all","ir_values group_all","model_ir_values",,1,1,1,1
"access_res_company_group_erp_manager","res_company group_erp_manager","model_res_company","group_erp_manager",1,1,1,1
"access_res_company_group_user","res_company group_user","model_res_company",,1,0,0,0
"access_res_font_group_user","res_font group_user","model_res_font","group_user",1,1,1,1
"access_res_font_group_erp_manager","res_font group_erp_manager","model_res_font","group_erp_manager",1,1,1,1
"access_res_font_group_all","res_font group_all","model_res_font",,1,0,0,0
"access_res_country_group_all","res_country group_user_all","model_res_country",,1,0,0,0
"access_res_country_state_group_all","res_country_state group_user_all","model_res_country_state",,1,0,0,0

1 id name model_id:id group_id:id perm_read perm_write perm_create perm_unlink
43 access_ir_values_group_all ir_values group_all model_ir_values 1 1 1 1
44 access_res_company_group_erp_manager res_company group_erp_manager model_res_company group_erp_manager 1 1 1 1
45 access_res_company_group_user res_company group_user model_res_company 1 0 0 0
46 access_res_font_group_user access_res_font_group_erp_manager res_font group_user res_font group_erp_manager model_res_font group_user group_erp_manager 1 1 1 1
47 access_res_font_group_all res_font group_all model_res_font 1 0 0 0
48 access_res_country_group_all res_country group_user_all model_res_country 1 0 0 0
49 access_res_country_state_group_all res_country_state group_user_all model_res_country_state 1 0 0 0

View File

@ -31,6 +31,7 @@ import print_xml
import render
import urllib
from openerp import SUPERUSER_ID
from openerp.report.render.rml2pdf import customfonts
#
@ -98,18 +99,7 @@ class report_rml(report_int):
if report_type == 'raw':
return xml, report_type
font_obj = registry['res.font']
# lazy loading
found_fonts_ids = font_obj.search(cr, uid, [('path', '!=', '/dev/null')], context=context)
if not found_fonts_ids:
# no scan yet or no font found on the system, scan the filesystem
font_obj.font_scan(cr, uid, context=context)
else:
if len(customfonts.CustomTTFonts) == 0:
# CustomTTFonts list is empty
for font in font_obj.browse(cr, uid, found_fonts_ids, context=context):
customfonts.CustomTTFonts.append((font.family, font.name, font.path, font.mode))
registry['res.font'].font_scan(cr, SUPERUSER_ID, lazy=True, context=context)
rml = self.create_rml(cr, xml, uid, context)
ir_actions_report_xml_obj = registry['ir.actions.report.xml']

View File

@ -92,9 +92,9 @@ def SetCustomFonts(rmldoc):
This function is called once per report, so it should
avoid system-wide processing (cache it, instead).
"""
for name, font, filename, mode in CustomTTFonts:
for family, font, filename, mode in CustomTTFonts:
if os.path.isabs(filename) and os.path.exists(filename):
rmldoc.setTTFontMapping(name, font, filename, mode)
rmldoc.setTTFontMapping(font, family, filename, mode)
return True
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:

View File

@ -34,6 +34,7 @@ import zipfile
import common
import openerp
from openerp import SUPERUSER_ID
from openerp.osv.fields import float as float_field, function as function_field, datetime as datetime_field
from openerp.tools.translate import _
from openerp.tools import DEFAULT_SERVER_DATE_FORMAT, DEFAULT_SERVER_DATETIME_FORMAT
@ -424,6 +425,7 @@ class report_sxw(report_rml, preprocess.report):
context.update(bin_raw=True)
registry = openerp.registry(cr.dbname)
ir_obj = registry['ir.actions.report.xml']
registry['res.font'].font_scan(cr, SUPERUSER_ID, lazy=True, context=context)
report_xml_ids = ir_obj.search(cr, uid,
[('report_name', '=', self.name[7:])], context=context)