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
skos
Commits
2b4d0044cccb
Commit
c02f3fa7
authored
Feb 19, 2018
by
Denis Laxalde
Browse files
Get rid of monkeypatches and workaround imports for cubicweb < 3.21
Related to #17133718.
parent
948c0c93f806
Changes
3
Hide whitespace changes
Inline
Side-by-side
__init__.py
View file @
2b4d0044
...
...
@@ -22,7 +22,6 @@ from six import text_type, binary_type
import
cubicweb
CW_VERSION
=
tuple
(
map
(
int
,
cubicweb
.
__version__
.
split
(
'.'
)[:
2
]))
POST_321
=
CW_VERSION
>=
(
3
,
21
)
POST_323
=
CW_VERSION
>=
(
3
,
23
)
...
...
rdfio.py
View file @
2b4d0044
...
...
@@ -20,12 +20,7 @@ from urlparse import urlparse
from
six
import
PY2
,
text_type
,
string_types
from
cubes.skos
import
POST_321
if
POST_321
:
# use new CW 3.21 dataimport API
from
cubicweb.dataimport.importer
import
ExtEntity
else
:
from
cubes.skos
import
ExtEntity
from
cubicweb.dataimport.importer
import
ExtEntity
TYPE_PREDICATE_URI
=
'http://www.w3.org/1999/02/22-rdf-syntax-ns#type'
...
...
site_cubicweb.py
View file @
2b4d0044
...
...
@@ -19,92 +19,9 @@
from
datetime
import
datetime
from
six
import
text_type
from
logilab.common.decorators
import
monkeypatch
from
cubes.skos
import
POST_321
,
POST_323
if
not
POST_321
:
from
copy
import
copy
import
inspect
from
cubicweb.dataimport
import
MetaGenerator
,
NoHookRQLObjectStore
@
monkeypatch
(
MetaGenerator
)
def
__init__
(
self
,
cnx
,
baseurl
=
None
,
source
=
None
):
self
.
_cnx
=
cnx
if
baseurl
is
None
:
config
=
cnx
.
vreg
.
config
baseurl
=
config
[
'base-url'
]
or
config
.
default_base_url
()
if
not
baseurl
[
-
1
]
==
'/'
:
baseurl
+=
'/'
self
.
baseurl
=
baseurl
if
source
is
None
:
source
=
cnx
.
repo
.
system_source
self
.
source
=
source
self
.
create_eid
=
cnx
.
repo
.
system_source
.
create_eid
self
.
time
=
datetime
.
now
()
# attributes/relations shared by all entities of the same type
self
.
etype_attrs
=
[]
self
.
etype_rels
=
[]
# attributes/relations specific to each entity
self
.
entity_attrs
=
[
'cwuri'
]
schema
=
cnx
.
vreg
.
schema
rschema
=
schema
.
rschema
for
rtype
in
self
.
META_RELATIONS
:
# skip owned_by / created_by if user is the internal manager
if
cnx
.
user
.
eid
==
-
1
and
rtype
in
(
'owned_by'
,
'created_by'
):
continue
if
rschema
(
rtype
).
final
:
self
.
etype_attrs
.
append
(
rtype
)
else
:
self
.
etype_rels
.
append
(
rtype
)
@
monkeypatch
(
MetaGenerator
)
def
init_entity
(
self
,
entity
):
entity
.
eid
=
self
.
create_eid
(
self
.
_cnx
)
extid
=
entity
.
cw_edited
.
get
(
'cwuri'
)
for
attr
in
self
.
entity_attrs
:
if
attr
in
entity
.
cw_edited
:
# already set, skip this attribute
continue
genfunc
=
self
.
generate
(
attr
)
if
genfunc
:
entity
.
cw_edited
.
edited_attribute
(
attr
,
genfunc
(
entity
))
if
isinstance
(
extid
,
text_type
):
extid
=
extid
.
encode
(
'utf-8'
)
return
self
.
source
,
extid
@
monkeypatch
(
NoHookRQLObjectStore
)
def
create_entity
(
self
,
etype
,
**
kwargs
):
for
key
,
value
in
kwargs
.
iteritems
():
kwargs
[
key
]
=
getattr
(
value
,
'eid'
,
value
)
entity
,
rels
=
self
.
metagen
.
base_etype_dicts
(
etype
)
# make a copy to keep cached entity pristine
entity
=
copy
(
entity
)
entity
.
cw_edited
=
copy
(
entity
.
cw_edited
)
entity
.
cw_clear_relation_cache
()
entity
.
cw_edited
.
update
(
kwargs
,
skipsec
=
False
)
entity_source
,
extid
=
self
.
metagen
.
init_entity
(
entity
)
cnx
=
self
.
_cnx
self
.
source
.
add_info
(
cnx
,
entity
,
entity_source
,
extid
)
self
.
source
.
add_entity
(
cnx
,
entity
)
kwargs
=
dict
()
if
inspect
.
getargspec
(
self
.
add_relation
).
keywords
:
kwargs
[
'subjtype'
]
=
entity
.
cw_etype
for
rtype
,
targeteids
in
rels
.
iteritems
():
# targeteids may be a single eid or a list of eids
inlined
=
self
.
rschema
(
rtype
).
inlined
try
:
for
targeteid
in
targeteids
:
self
.
add_relation
(
cnx
,
entity
.
eid
,
rtype
,
targeteid
,
inlined
,
**
kwargs
)
except
TypeError
:
self
.
add_relation
(
cnx
,
entity
.
eid
,
rtype
,
targeteids
,
inlined
,
**
kwargs
)
self
.
_nb_inserted_entities
+=
1
return
entity
from
cubes.skos
import
POST_323
if
not
POST_323
:
...
...
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