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
cubes
seda
Commits
aebba811c46a
Commit
e3277814
authored
Jul 21, 2016
by
Sylvain Thénault
Browse files
[ui] Move parent_and_container function from views to entities
We'll need that here soon!
parent
9a2147273199
Changes
4
Hide whitespace changes
Inline
Side-by-side
entities/__init__.py
View file @
aebba811
...
...
@@ -15,6 +15,8 @@
# with this program. If not, see <http://www.gnu.org/licenses/>.
"""Custom logic (eg entities and adapters) for cubicweb-seda."""
import
json
from
cubes.compound.entities
import
IContainer
,
IContained
from
cubes.seda
import
seda_profile_container_def
...
...
@@ -24,6 +26,36 @@ from cubes.seda.xsd import XSDMMapping
XSDM_MAPPING
=
XSDMMapping
(
'ArchiveTransfer'
)
def
parent_and_container
(
entity
):
"""Attempt to return the direct parent and container from the entity, handling case where entity
is being created and container information will be found through linkto or parent form
(partially supported)
"""
if
entity
.
has_eid
():
# entity is expected to be a contained entity, not the container itself
container
=
entity
.
cw_adapt_to
(
'IContained'
).
container
parent
=
entity
.
cw_adapt_to
(
'IContained'
).
parent
else
:
# but parent entity, retrieved through linkto, may be the container itself or a
# contained entity
try
:
parent_eid
=
int
(
entity
.
_cw
.
form
[
'__linkto'
].
split
(
':'
)[
1
])
except
KeyError
:
# ajax created form
try
:
parent_eid
=
int
(
json
.
loads
(
entity
.
_cw
.
form
[
'arg'
][
0
]))
except
ValueError
:
# unable to get parent eid for now :()
return
None
,
None
parent
=
entity
.
_cw
.
entity_from_eid
(
parent_eid
)
icontainer
=
parent
.
cw_adapt_to
(
'IContainer'
)
if
icontainer
is
None
:
container
=
parent
.
cw_adapt_to
(
'IContained'
).
container
else
:
container
=
icontainer
.
container
return
parent
,
container
def
rule_type_from_etype
(
etype
):
"""Return the rule type from an etype like SEDAAccessRule or SEDAAltAccessRulePreventInheritance
"""
...
...
views/__init__.py
View file @
aebba811
...
...
@@ -14,8 +14,6 @@
# You should have received a copy of the GNU Lesser General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import
json
from
yams
import
BASE_TYPES
from
cubicweb
import
tags
,
neg_role
...
...
@@ -180,33 +178,3 @@ def dropdown_button(text, links):
w
(
u
'</ul>'
)
w
(
u
'</div>'
)
return
data
.
getvalue
()
def
parent_and_container
(
entity
):
"""Attempt to return the direct parent and container from the entity, handling case where entity
is being created and container information will be found through linkto or parent form
(partially supported)
"""
if
entity
.
has_eid
():
# entity is expected to be a contained entity, not the container itself
container
=
entity
.
cw_adapt_to
(
'IContained'
).
container
parent
=
entity
.
cw_adapt_to
(
'IContained'
).
parent
else
:
# but parent entity, retrieved through linkto, may be the container itself or a
# contained entity
try
:
parent_eid
=
int
(
entity
.
_cw
.
form
[
'__linkto'
].
split
(
':'
)[
1
])
except
KeyError
:
# ajax created form
try
:
parent_eid
=
int
(
json
.
loads
(
entity
.
_cw
.
form
[
'arg'
][
0
]))
except
ValueError
:
# unable to get parent eid for now :()
return
None
,
None
parent
=
entity
.
_cw
.
entity_from_eid
(
parent_eid
)
icontainer
=
parent
.
cw_adapt_to
(
'IContainer'
)
if
icontainer
is
None
:
container
=
parent
.
cw_adapt_to
(
'IContained'
).
container
else
:
container
=
icontainer
.
container
return
parent
,
container
views/dataobject.py
View file @
aebba811
...
...
@@ -27,7 +27,8 @@ from cubes.relationwidget import views as rwdg
from
cubes.skos.views
import
widgets
as
skos
from
cubes.seda.xsd2yams
import
RDEF_CONSTRAINTS
from
cubes.seda.views
import
rtags_from_xsd_element
,
add_subobject_link
,
parent_and_container
from
cubes.seda.entities
import
parent_and_container
from
cubes.seda.views
import
rtags_from_xsd_element
,
add_subobject_link
from
cubes.seda.views
import
viewlib
from
cubes.seda.views
import
uicfg
as
sedauicfg
# noqa - ensure those rules are defined first
...
...
views/mgmt_rules.py
View file @
aebba811
...
...
@@ -21,8 +21,8 @@ from cubicweb.predicates import is_instance
from
cubicweb.web
import
INTERNAL_FIELD_VALUE
from
cubicweb.web.views
import
uicfg
from
cubes.seda.entities
import
rule_type_from_etype
from
cubes.seda.views
import
parent_and_container
,
viewlib
from
cubes.seda.entities
import
parent_and_container
,
rule_type_from_etype
from
cubes.seda.views
import
viewlib
from
cubes.seda.views
import
uicfg
as
sedauicfg
# noqa - ensure those rules are defined first
...
...
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