4
4
5
5
import hashlib
6
6
7
- from openerp import models , fields , api
7
+ from openerp import api , fields , models
8
8
9
- CUSTOM_CSS_ARCH = ''' <?xml version="1.0"?>
9
+ CUSTOM_CSS_ARCH = """ <?xml version="1.0"?>
10
10
<t t-name="theme_kit.custom_css">
11
11
%s
12
12
</t>
13
- '''
13
+ """
14
14
15
15
16
16
class Config (models .TransientModel ):
17
17
18
- _name = ' theme_kit.config'
19
- _inherit = ' res.config.settings'
18
+ _name = " theme_kit.config"
19
+ _inherit = " res.config.settings"
20
20
21
- theme_id = fields .Many2one (' theme_kit.theme' , string = "Color Scheme" )
22
- favicon_id = fields .Many2one (' ir.attachment' , string = "Favicon" )
21
+ theme_id = fields .Many2one (" theme_kit.theme" , string = "Color Scheme" )
22
+ favicon_id = fields .Many2one (" ir.attachment" , string = "Favicon" )
23
23
24
- page_title = fields .Char ('Page Title' , help = '''Anything you want to see in page title, e.g.
24
+ page_title = fields .Char (
25
+ "Page Title" ,
26
+ help = """Anything you want to see in page title, e.g.
25
27
* CompanyName
26
28
* CompanyName's Portal
27
29
* CompanyName's Operation System
28
30
* etc.
29
- ''' )
30
- system_name = fields .Char ('System Name' , help = '''e.g.
31
+ """ ,
32
+ )
33
+ system_name = fields .Char (
34
+ "System Name" ,
35
+ help = """e.g.
31
36
* CompanyName's Portal
32
37
* CompanyName's Operation System
33
38
* etc.
34
- ''' )
35
- company_logo = fields .Binary ('Company Logo' , help = "Due to browser cache, old logo may be still shown. To fix that, clear browser cache" )
36
-
37
- wallpapers_count = fields .Integer ('Wallpapers' , readonly = True )
38
-
39
- new_documentation_website = fields .Char ('Documentation Website' , help = '''Replaces links to documentation to custom website e.g.
39
+ """ ,
40
+ )
41
+ company_logo = fields .Binary (
42
+ "Company Logo" ,
43
+ help = "Due to browser cache, old logo may be still shown. To fix that, clear browser cache" ,
44
+ )
45
+
46
+ wallpapers_count = fields .Integer ("Wallpapers" , readonly = True )
47
+
48
+ new_documentation_website = fields .Char (
49
+ "Documentation Website" ,
50
+ help = """Replaces links to documentation to custom website e.g.
40
51
* "Help" in Import tool
41
52
* "How-to" in paypal
42
53
* etc.
43
- ''' )
54
+ """ ,
55
+ )
44
56
45
57
@api .model
46
58
def get_values (self ):
47
59
res = super (Config , self ).get_values ()
48
- ICPSudo = self .env [' ir.config_parameter' ].sudo ()
60
+ ICPSudo = self .env [" ir.config_parameter" ].sudo ()
49
61
50
62
theme_id = ICPSudo .get_param ("theme_kit.current_theme_id" , default = False )
51
63
if theme_id :
@@ -55,9 +67,13 @@ def get_values(self):
55
67
favicon_id = int (favicon_id )
56
68
page_title = ICPSudo .get_param ("web_debranding.new_title" , default = False )
57
69
system_name = ICPSudo .get_param ("web_debranding.new_name" , default = False )
58
- new_documentation_website = ICPSudo .get_param ("web_debranding.new_documentation_website" , default = False )
70
+ new_documentation_website = ICPSudo .get_param (
71
+ "web_debranding.new_documentation_website" , default = False
72
+ )
59
73
company_logo = self .env .user .company_id .logo
60
- wallpapers_count = self .env ['ir.attachment' ].search_count ([('use_as_background' , '=' , True )])
74
+ wallpapers_count = self .env ["ir.attachment" ].search_count (
75
+ [("use_as_background" , "=" , True )]
76
+ )
61
77
62
78
res .update (
63
79
company_logo = company_logo ,
@@ -66,37 +82,46 @@ def get_values(self):
66
82
page_title = page_title ,
67
83
system_name = system_name ,
68
84
new_documentation_website = new_documentation_website ,
69
- wallpapers_count = wallpapers_count
85
+ wallpapers_count = wallpapers_count ,
70
86
)
71
87
return res
72
88
73
89
@api .multi
74
90
def set_values (self ):
75
91
super (Config , self ).set_values ()
76
- ICPSudo = self .env ['ir.config_parameter' ].sudo ()
77
- ICPSudo .set_param ('theme_kit.current_theme_id' , getattr (self , 'theme_id' ).id or '' )
78
- ICPSudo .set_param ('theme_kit.current_favicon_id' , getattr (self , 'favicon_id' ).id or '' )
79
- ICPSudo .set_param ('web_debranding.new_title' , getattr (self , 'page_title' ) or '' )
80
- ICPSudo .set_param ('web_debranding.new_name' , getattr (self , 'system_name' ) or '' )
81
- ICPSudo .set_param ('web_debranding.new_documentation_website' , getattr (self , 'new_documentation_website' ) or '' )
92
+ ICPSudo = self .env ["ir.config_parameter" ].sudo ()
93
+ ICPSudo .set_param (
94
+ "theme_kit.current_theme_id" , getattr (self , "theme_id" ).id or ""
95
+ )
96
+ ICPSudo .set_param (
97
+ "theme_kit.current_favicon_id" , getattr (self , "favicon_id" ).id or ""
98
+ )
99
+ ICPSudo .set_param ("web_debranding.new_title" , self .page_title or "" )
100
+ ICPSudo .set_param ("web_debranding.new_name" , self .system_name or "" )
101
+ ICPSudo .set_param (
102
+ "web_debranding.new_documentation_website" ,
103
+ self .new_documentation_website or "" ,
104
+ )
82
105
83
106
# set company logo
84
107
self .env .user .company_id .logo = self .company_logo
85
108
86
109
# set theme
87
- custom_css = self .env .ref (' theme_kit.custom_css' )
88
- code = ''
110
+ custom_css = self .env .ref (" theme_kit.custom_css" )
111
+ code = ""
89
112
if self .theme_id :
90
113
code = self .theme_id .code
91
114
arch = CUSTOM_CSS_ARCH % code
92
- custom_css .write ({' arch' : arch })
115
+ custom_css .write ({" arch" : arch })
93
116
94
117
# set favicon
95
- url = ''
118
+ url = ""
96
119
if self .favicon_id :
97
120
url = self .favicon_id .url or self ._attachment2url (self .favicon_id )
98
- ICPSudo .set_param (' web_debranding.favicon_url' , url )
121
+ ICPSudo .set_param (" web_debranding.favicon_url" , url )
99
122
100
123
def _attachment2url (self , att ):
101
- sha = hashlib .sha1 (getattr (att , '__last_update' ).encode ('utf-8' )).hexdigest ()[0 :7 ]
102
- return '/web/image/%s-%s' % (att .id , sha )
124
+ sha = hashlib .sha1 (getattr (att , "__last_update" ).encode ("utf-8" )).hexdigest ()[
125
+ 0 :7
126
+ ]
127
+ return "/web/image/{}-{}" .format (att .id , sha )
0 commit comments