Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
erp5_fork
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Eteri
erp5_fork
Commits
a59731a0
Commit
a59731a0
authored
Apr 23, 2015
by
Cédric Le Ninivin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Preference: optimize preference access (Thanks Julien M.)
parent
ba498122
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
21 additions
and
24 deletions
+21
-24
product/ERP5Form/Document/Preference.py
product/ERP5Form/Document/Preference.py
+1
-0
product/ERP5Form/PreferenceTool.py
product/ERP5Form/PreferenceTool.py
+20
-24
No files found.
product/ERP5Form/Document/Preference.py
View file @
a59731a0
...
...
@@ -60,6 +60,7 @@ class Preference( Folder ):
,
PropertySheet
.
XMLObject
,
PropertySheet
.
DublinCore
,
PropertySheet
.
Preference
,
PropertySheet
.
SortIndex
)
# Declarative security
...
...
product/ERP5Form/PreferenceTool.py
View file @
a59731a0
...
...
@@ -42,6 +42,7 @@ from Products.ERP5Type.Cache import CachingMethod
from
Products.ERP5Type.Utils
import
convertToUpperCase
from
Products.ERP5Type.TransactionalVariable
import
getTransactionalVariable
from
Products.ERP5Form
import
_dtmldir
from
Products.ZSQLCatalog.SQLCatalog
import
SimpleQuery
,
ComplexQuery
_marker
=
object
()
...
...
@@ -159,31 +160,26 @@ class PreferenceTool(BaseTool):
newSecurityManager
(
None
,
actual_user
.
__of__
(
acl_users
))
tv_key
=
'PreferenceTool._getSortedPreferenceList/%s/%s'
%
(
user
,
sql_catalog_id
)
if
tv
.
get
(
tv_key
,
None
)
is
None
:
prefs
=
[]
# XXX will also cause problems with Manager (too long)
# XXX For manager, create a manager specific preference
# or better solution
user_is_manager
=
'Manager'
in
user
.
getRolesInContext
(
self
)
for
pref
in
self
.
searchFolder
(
portal_type
=
'Preference'
,
sql_catalog_id
=
sql_catalog_id
):
try
:
return
tv
[
tv_key
]
except
KeyError
:
kw
=
{
'validation_state'
:
(
'enabled'
,
'global'
),
# system preferences before user preferences
'sort_on'
:
((
'portal_type'
,
'DESC'
),
(
'int_index'
,
'DESC'
))}
if
'Manager'
in
user
.
getRolesInContext
(
self
):
kw
[
'query'
]
=
ComplexQuery
(
SimpleQuery
(
portal_type
=
'System Preference'
),
SimpleQuery
(
int_index
=
Priority
.
USER
,
comparison_operator
=
'!='
),
SimpleQuery
(
owner
=
user
.
getId
()),
operator
=
'OR'
)
tv
[
tv_key
]
=
preference_list
=
[]
for
pref
in
self
.
searchFolder
(
sql_catalog_id
=
sql_catalog_id
,
**
kw
):
pref
=
pref
.
getObject
()
if
pref
is
not
None
and
pref
.
getProperty
(
'preference_state'
,
'broken'
)
in
(
'enabled'
,
'global'
):
# XXX quick workaround so that manager only see user preference
# they actually own.
if
user_is_manager
and
pref
.
getPriority
()
==
Priority
.
USER
:
if
pref
.
getOwnerTuple
()[
1
]
==
user
.
getId
():
prefs
.
append
(
pref
)
else
:
prefs
.
append
(
pref
)
prefs
.
sort
(
key
=
lambda
x
:
x
.
getPriority
(),
reverse
=
True
)
# add system preferences before user preferences
sys_prefs
=
[
x
.
getObject
()
for
x
in
self
.
searchFolder
(
portal_type
=
'System Preference'
,
sql_catalog_id
=
sql_catalog_id
)
\
if
x
.
getObject
().
getProperty
(
'preference_state'
,
'broken'
)
in
(
'enabled'
,
'global'
)]
sys_prefs
.
sort
(
key
=
lambda
x
:
x
.
getPriority
(),
reverse
=
True
)
preference_list
=
sys_prefs
+
prefs
tv
[
tv_key
]
=
preference_list
return
tv
[
tv_key
]
if
pref
is
not
None
:
preference_list
.
append
(
pref
)
if
not
preference_list
:
# BBB maybe not migrated yet
pass
return
preference_list
finally
:
setSecurityManager
(
security_manager
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment