[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:
parent
87dfe75013
commit
75d92a40bd
|
@ -63,9 +63,23 @@ class res_font(osv.Model):
|
||||||
}, context=context)
|
}, context=context)
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def font_scan(self, cr, uid, context=None):
|
def font_scan(self, cr, uid, lazy=False, context=None):
|
||||||
self._discover_fonts(cr, uid, context=context)
|
if lazy:
|
||||||
return self._register_fonts(cr, uid, context=context)
|
# 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):
|
def _discover_fonts(self, cr, uid, context=None):
|
||||||
"""Scan fonts on the file system, add them to the list of known fonts
|
"""Scan fonts on the file system, add them to the list of known fonts
|
||||||
|
|
|
@ -43,7 +43,7 @@
|
||||||
"access_ir_values_group_all","ir_values group_all","model_ir_values",,1,1,1,1
|
"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_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_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_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_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
|
"access_res_country_state_group_all","res_country_state group_user_all","model_res_country_state",,1,0,0,0
|
||||||
|
|
|
|
@ -31,6 +31,7 @@ import print_xml
|
||||||
import render
|
import render
|
||||||
import urllib
|
import urllib
|
||||||
|
|
||||||
|
from openerp import SUPERUSER_ID
|
||||||
from openerp.report.render.rml2pdf import customfonts
|
from openerp.report.render.rml2pdf import customfonts
|
||||||
|
|
||||||
#
|
#
|
||||||
|
@ -98,18 +99,7 @@ class report_rml(report_int):
|
||||||
if report_type == 'raw':
|
if report_type == 'raw':
|
||||||
return xml, report_type
|
return xml, report_type
|
||||||
|
|
||||||
font_obj = registry['res.font']
|
registry['res.font'].font_scan(cr, SUPERUSER_ID, lazy=True, context=context)
|
||||||
|
|
||||||
# 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))
|
|
||||||
|
|
||||||
rml = self.create_rml(cr, xml, uid, context)
|
rml = self.create_rml(cr, xml, uid, context)
|
||||||
ir_actions_report_xml_obj = registry['ir.actions.report.xml']
|
ir_actions_report_xml_obj = registry['ir.actions.report.xml']
|
||||||
|
|
|
@ -92,9 +92,9 @@ def SetCustomFonts(rmldoc):
|
||||||
This function is called once per report, so it should
|
This function is called once per report, so it should
|
||||||
avoid system-wide processing (cache it, instead).
|
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):
|
if os.path.isabs(filename) and os.path.exists(filename):
|
||||||
rmldoc.setTTFontMapping(name, font, filename, mode)
|
rmldoc.setTTFontMapping(font, family, filename, mode)
|
||||||
return True
|
return True
|
||||||
|
|
||||||
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
||||||
|
|
|
@ -34,6 +34,7 @@ import zipfile
|
||||||
import common
|
import common
|
||||||
|
|
||||||
import openerp
|
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.osv.fields import float as float_field, function as function_field, datetime as datetime_field
|
||||||
from openerp.tools.translate import _
|
from openerp.tools.translate import _
|
||||||
from openerp.tools import DEFAULT_SERVER_DATE_FORMAT, DEFAULT_SERVER_DATETIME_FORMAT
|
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)
|
context.update(bin_raw=True)
|
||||||
registry = openerp.registry(cr.dbname)
|
registry = openerp.registry(cr.dbname)
|
||||||
ir_obj = registry['ir.actions.report.xml']
|
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_xml_ids = ir_obj.search(cr, uid,
|
||||||
[('report_name', '=', self.name[7:])], context=context)
|
[('report_name', '=', self.name[7:])], context=context)
|
||||||
|
|
Loading…
Reference in New Issue