Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
cubicweb
cubicweb
Commits
73cadb5d0097
Commit
dcf682e8
authored
Jul 26, 2011
by
Adrien Di Mascio
Browse files
[entities] skip_copy_for should be considered for object relations too (closes #1857474)
parent
1541d9e6b242
Changes
2
Hide whitespace changes
Inline
Side-by-side
entity.py
View file @
73cadb5d
...
...
@@ -96,11 +96,12 @@ class Entity(AppObject):
If None is specified, the first non-meta attribute will
be used
:type skip_copy_for: list
:cvar skip_copy_for: a list of relations that should be skipped when copying
this kind of entity. Note that some relations such
as composite relations or relations that have '?1' as object
cardinality are always skipped.
:type cw_skip_copy_for: list
:cvar cw_skip_copy_for: a list of couples (rtype, role) for each relation
that should be skipped when copying
this kind of entity. Note that some relations such
as composite relations or relations that have '?1' as object
cardinality are always skipped.
"""
__registry__
=
'etypes'
__select__
=
yes
()
...
...
@@ -108,7 +109,8 @@ class Entity(AppObject):
# class attributes that must be set in class definition
rest_attr
=
None
fetch_attrs
=
None
skip_copy_for
=
(
'in_state'
,)
# XXX turn into a set
skip_copy_for
=
()
# bw compat (< 3.14), use cw_skip_copy_for instead
cw_skip_copy_for
=
[(
'in_state'
,
'subject'
)]
# class attributes set automatically at registration time
e_schema
=
None
...
...
@@ -542,13 +544,22 @@ class Entity(AppObject):
"""
assert
self
.
has_eid
()
execute
=
self
.
_cw
.
execute
skip_copy_for
=
{
'subject'
:
set
(),
'object'
:
set
()}
for
rtype
in
self
.
skip_copy_for
:
skip_copy_for
[
'subject'
].
add
(
rtype
)
warn
(
'[3.14] skip_copy_for on entity classes (%s) is deprecated, '
'use cw_skip_for instead with list of couples (rtype, role)'
%
self
.
__regid__
,
DeprecationWarning
)
for
rtype
,
role
in
self
.
cw_skip_copy_for
:
assert
role
in
(
'subject'
,
'object'
),
role
skip_copy_for
[
role
].
add
(
rtype
)
for
rschema
in
self
.
e_schema
.
subject_relations
():
if
rschema
.
final
or
rschema
.
meta
:
continue
# skip already defined relations
if
getattr
(
self
,
rschema
.
type
):
continue
if
rschema
.
type
in
self
.
skip_copy_for
:
if
rschema
.
type
in
skip_copy_for
[
'subject'
]
:
continue
# skip composite relation
rdef
=
self
.
e_schema
.
rdef
(
rschema
)
...
...
@@ -568,6 +579,8 @@ class Entity(AppObject):
# skip already defined relations
if
self
.
related
(
rschema
.
type
,
'object'
):
continue
if
rschema
.
type
in
skip_copy_for
[
'object'
]:
continue
rdef
=
self
.
e_schema
.
rdef
(
rschema
,
'object'
)
# skip composite relation
if
rdef
.
composite
:
...
...
web/test/unittest_views_basecontrollers.py
View file @
73cadb5d
...
...
@@ -365,6 +365,43 @@ class EditControllerTC(CubicWebTC):
self
.
assertEqual
(
path
,
'view'
)
self
.
assertIn
(
'_cwmsgid'
,
params
)
def
test_simple_copy
(
self
):
req
=
self
.
request
()
blog
=
req
.
create_entity
(
'Blog'
,
title
=
u
'my-blog'
)
blogentry
=
req
.
create_entity
(
'BlogEntry'
,
title
=
u
'entry1'
,
content
=
u
'content1'
,
entry_of
=
blog
)
req
=
self
.
request
()
req
.
form
=
{
'__maineid'
:
'X'
,
'eid'
:
'X'
,
'__cloned_eid:X'
:
blogentry
.
eid
,
'__type:X'
:
'BlogEntry'
,
'_cw_entity_fields:X'
:
'title-subject,content-subject'
,
'title-subject:X'
:
u
'entry1-copy'
,
'content-subject:X'
:
u
'content1'
,
}
self
.
expect_redirect_publish
(
req
,
'edit'
)
blogentry2
=
req
.
find_one_entity
(
'BlogEntry'
,
title
=
u
'entry1-copy'
)
self
.
assertEqual
(
blogentry2
.
entry_of
[
0
].
eid
,
blog
.
eid
)
def
test_skip_copy_for
(
self
):
req
=
self
.
request
()
blog
=
req
.
create_entity
(
'Blog'
,
title
=
u
'my-blog'
)
blogentry
=
req
.
create_entity
(
'BlogEntry'
,
title
=
u
'entry1'
,
content
=
u
'content1'
,
entry_of
=
blog
)
blogentry
.
__class__
.
cw_skip_copy_for
=
[(
'entry_of'
,
'subject'
)]
try
:
req
=
self
.
request
()
req
.
form
=
{
'__maineid'
:
'X'
,
'eid'
:
'X'
,
'__cloned_eid:X'
:
blogentry
.
eid
,
'__type:X'
:
'BlogEntry'
,
'_cw_entity_fields:X'
:
'title-subject,content-subject'
,
'title-subject:X'
:
u
'entry1-copy'
,
'content-subject:X'
:
u
'content1'
,
}
self
.
expect_redirect_publish
(
req
,
'edit'
)
blogentry2
=
req
.
find_one_entity
(
'BlogEntry'
,
title
=
u
'entry1-copy'
)
# entry_of should not be copied
self
.
assertEqual
(
len
(
blogentry2
.
entry_of
),
0
)
finally
:
blogentry
.
__class__
.
cw_skip_copy_for
=
[]
def
test_nonregr_eetype_etype_editing
(
self
):
"""non-regression test checking that a manager user can edit a CWEType entity
"""
...
...
Write
Preview
Supports
Markdown
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