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
982e8616d9a2
Commit
9ae1be0f
authored
Apr 23, 2009
by
sylvain.thenault@logilab.fr
Browse files
delete-trailing-whitespaces
--HG-- branch : tls-sprint
parent
8edb0806dde4
Changes
8
Hide whitespace changes
Inline
Side-by-side
common/mixins.py
View file @
982e8616
...
...
@@ -26,10 +26,10 @@ class TreeMixIn(object):
# XXX misnamed
parent_target
=
'subject'
children_target
=
'object'
def
different_type_children
(
self
,
entities
=
True
):
"""return children entities of different type as this entity.
according to the `entities` parameter, return entity objects or the
equivalent result set
"""
...
...
@@ -41,7 +41,7 @@ class TreeMixIn(object):
def
same_type_children
(
self
,
entities
=
True
):
"""return children entities of the same type as this entity.
according to the `entities` parameter, return entity objects or the
equivalent result set
"""
...
...
@@ -50,7 +50,7 @@ class TreeMixIn(object):
if
entities
:
return
[
e
for
e
in
res
if
e
.
e_schema
==
self
.
e_schema
]
return
res
.
filtered_rset
(
lambda
x
:
x
.
e_schema
==
self
.
e_schema
,
self
.
col
)
def
iterchildren
(
self
,
_done
=
None
):
if
_done
is
None
:
_done
=
set
()
...
...
@@ -74,7 +74,7 @@ class TreeMixIn(object):
yield
entity
except
AttributeError
:
pass
@
cached
def
path
(
self
):
"""returns the list of eids from the root object to this object"""
...
...
@@ -96,7 +96,7 @@ class TreeMixIn(object):
path
.
reverse
()
return
path
def
iterparents
(
self
):
def
_uptoroot
(
self
):
curr
=
self
...
...
@@ -110,7 +110,7 @@ class TreeMixIn(object):
def
notification_references
(
self
,
view
):
"""used to control References field of email send on notification
for this entity. `view` is the notification view.
Should return a list of eids which can be used to generate message ids
of previously sent email
"""
...
...
@@ -142,7 +142,7 @@ class TreeMixIn(object):
def
children_rql
(
self
):
return
self
.
related_rql
(
self
.
tree_attribute
,
self
.
children_target
)
def
__iter__
(
self
):
return
self
.
iterchildren
()
...
...
@@ -163,7 +163,7 @@ class WorkflowableMixIn(object):
relation (which implies supporting 'wf_info_for' as well)
"""
__implements__
=
(
IWorkflowable
,)
@
property
def
state
(
self
):
try
:
...
...
@@ -171,7 +171,7 @@ class WorkflowableMixIn(object):
except
IndexError
:
self
.
warning
(
'entity %s has no state'
,
self
)
return
None
@
property
def
displayable_state
(
self
):
return
self
.
req
.
_
(
self
.
state
)
...
...
@@ -182,7 +182,7 @@ class WorkflowableMixIn(object):
if
rset
:
return
rset
.
get_entity
(
0
,
0
)
return
None
def
wf_transition
(
self
,
trname
):
rset
=
self
.
req
.
execute
(
'Any T, TN WHERE T name TN, T name %(n)s, T transition_of E, E name %(e)s'
,
{
'n'
:
trname
,
'e'
:
str
(
self
.
e_schema
)})
...
...
@@ -201,7 +201,7 @@ class WorkflowableMixIn(object):
self
.
req
.
set_shared_data
(
'trcommentformat'
,
trcommentformat
)
self
.
req
.
execute
(
'SET X in_state S WHERE X eid %(x)s, S eid %(s)s'
,
{
'x'
:
self
.
eid
,
's'
:
stateeid
},
'x'
)
def
can_pass_transition
(
self
,
trname
):
"""return the Transition instance if the current user can pass the
transition with the given name, else None
...
...
@@ -215,13 +215,13 @@ class WorkflowableMixIn(object):
for
tr
in
rset
.
entities
():
if
tr
.
may_be_passed
(
self
.
eid
,
stateeid
):
return
tr
def
latest_trinfo
(
self
):
"""return the latest transition information for this entity"""
return
self
.
reverse_wf_info_for
[
-
1
]
# __method methods ########################################################
def
set_state
(
self
,
params
=
None
):
"""change the entity's state according to a state defined in given
parameters, used to be called using __method controler facility
...
...
@@ -231,9 +231,9 @@ class WorkflowableMixIn(object):
params
.
get
(
'trcomment'
),
params
.
get
(
'trcommentformat'
))
self
.
req
.
set_message
(
self
.
req
.
_
(
'__msg state changed'
))
# specific vocabulary methods #############################################
@
obsolete
(
'use EntityFieldsForm.subject_in_state_vocabulary'
)
def
subject_in_state_vocabulary
(
self
,
rschema
,
limit
=
None
):
from
cubicweb.web.form
import
EntityFieldsForm
...
...
@@ -249,7 +249,7 @@ class EmailableMixIn(object):
primary_email / use_email scheme
"""
__implements__
=
(
IEmailable
,)
def
get_email
(
self
):
if
getattr
(
self
,
'primary_email'
,
None
):
return
self
.
primary_email
[
0
].
address
...
...
@@ -271,14 +271,14 @@ class EmailableMixIn(object):
def
as_email_context
(
self
):
"""returns the dictionary as used by the sendmail controller to
build email bodies.
NOTE: the dictionary keys should match the list returned by the
`allowed_massmail_keys` method.
"""
return
dict
(
(
attr
,
getattr
(
self
,
attr
))
for
attr
in
self
.
allowed_massmail_keys
()
)
MI_REL_TRIGGERS
=
{
(
'in_state'
,
'subject'
):
WorkflowableMixIn
,
(
'primary_email'
,
'subject'
):
EmailableMixIn
,
...
...
@@ -312,7 +312,7 @@ class TreeViewMixIn(object):
if
done
is
None
:
done
=
set
()
super
(
TreeViewMixIn
,
self
).
call
(
done
=
done
,
**
kwargs
)
def
cell_call
(
self
,
row
,
col
=
0
,
vid
=
None
,
done
=
None
,
**
kwargs
):
done
,
entity
=
_done_init
(
done
,
self
,
row
,
col
)
if
done
is
None
:
...
...
@@ -341,7 +341,7 @@ class TreePathMixIn(object):
self
.
w
(
u
'<div class="pathbar">'
)
super
(
TreePathMixIn
,
self
).
call
(
**
kwargs
)
self
.
w
(
u
'</div>'
)
def
cell_call
(
self
,
row
,
col
=
0
,
vid
=
None
,
done
=
None
,
**
kwargs
):
done
,
entity
=
_done_init
(
done
,
self
,
row
,
col
)
if
done
is
None
:
...
...
@@ -383,7 +383,7 @@ class ProgressMixIn(object):
def
in_progress
(
self
):
raise
NotImplementedError
()
def
progress
(
self
):
try
:
return
100.
*
self
.
done
/
self
.
revised_cost
...
...
devtools/devctl.py
View file @
982e8616
...
...
@@ -40,7 +40,7 @@ class DevCubeConfiguration(ServerConfiguration, WebConfiguration):
def
my_cubes
(
self
,
cube
):
return
(
cube
,)
+
self
.
cube_dependencies
(
cube
)
+
self
.
cube_recommends
(
cube
)
@
property
def
apphome
(
self
):
return
None
...
...
@@ -77,7 +77,7 @@ def cleanup_sys_modules(config):
if
mod
.
__file__
.
startswith
(
path
):
del
sys
.
modules
[
name
]
break
def
generate_schema_pot
(
w
,
cubedir
=
None
):
"""generate a pot file with schema specific i18n messages
...
...
@@ -101,7 +101,8 @@ def generate_schema_pot(w, cubedir=None):
vreg
.
set_schema
(
schema
)
w
(
DEFAULT_POT_HEAD
)
_generate_schema_pot
(
w
,
vreg
,
schema
,
libschema
=
libschema
,
cube
=
cube
)
def
_generate_schema_pot
(
w
,
vreg
,
schema
,
libschema
=
None
,
cube
=
None
):
from
cubicweb.common.i18n
import
add_msg
w
(
'# schema pot file, generated on %s
\n
'
%
datetime
.
now
().
strftime
(
'%Y-%m-%d %H:%M:%S'
))
...
...
@@ -147,21 +148,26 @@ def _generate_schema_pot(w, vreg, schema, libschema=None, cube=None):
for
eschema
in
schema
.
entities
():
if
eschema
.
is_final
():
continue
for
x
,
rschemas
in
((
'subject'
,
eschema
.
subject_relations
()),
for
role
,
rschemas
in
((
'subject'
,
eschema
.
subject_relations
()),
(
'object'
,
eschema
.
object_relations
())):
for
rschema
in
rschemas
:
if
rschema
.
is_final
():
continue
for
teschema
in
rschema
.
targets
(
eschema
,
x
):
if
defined_in_library
(
libschema
,
eschema
,
rschema
,
teschema
,
x
):
for
teschema
in
rschema
.
targets
(
eschema
,
role
):
if
defined_in_library
(
libschema
,
eschema
,
rschema
,
teschema
,
role
):
continue
if
actionbox
.
relation_mode
(
rschema
.
type
,
teschema
.
type
,
x
)
==
'create'
:
if
x
==
'subject'
:
label
=
'add %s %s %s %s'
%
(
eschema
,
rschema
,
teschema
,
x
)
label2
=
"creating %s (%s %%(linkto)s %s %s)"
%
(
teschema
,
eschema
,
rschema
,
teschema
)
if
actionbox
.
relation_mode
(
rschema
,
eschema
,
teschema
,
role
)
==
'create'
:
if
role
==
'subject'
:
label
=
'add %s %s %s %s'
%
(
eschema
,
rschema
,
teschema
,
role
)
label2
=
"creating %s (%s %%(linkto)s %s %s)"
%
(
teschema
,
eschema
,
rschema
,
teschema
)
else
:
label
=
'add %s %s %s %s'
%
(
teschema
,
rschema
,
eschema
,
x
)
label2
=
"creating %s (%s %s %s %%(linkto)s)"
%
(
teschema
,
teschema
,
rschema
,
eschema
)
label
=
'add %s %s %s %s'
%
(
teschema
,
rschema
,
eschema
,
role
)
label2
=
"creating %s (%s %s %s %%(linkto)s)"
%
(
teschema
,
teschema
,
rschema
,
eschema
)
add_msg
(
w
,
label
)
add_msg
(
w
,
label2
)
cube
=
(
cube
and
'cubes.%s.'
%
cube
or
'cubicweb.'
)
...
...
@@ -177,12 +183,13 @@ def _generate_schema_pot(w, vreg, schema, libschema=None, cube=None):
add_msg
(
w
,
objid
)
done
.
add
(
objid
)
def
defined_in_library
(
libschema
,
etype
,
rtype
,
tetype
,
x
):
"""return true if the given relation definition exists in cubicweb's library"""
def
defined_in_library
(
libschema
,
etype
,
rtype
,
tetype
,
role
):
"""return true if the given relation definition exists in cubicweb's library
"""
if
libschema
is
None
:
return
False
if
x
==
'subject'
:
if
role
==
'subject'
:
subjtype
,
objtype
=
etype
,
tetype
else
:
subjtype
,
objtype
=
tetype
,
etype
...
...
@@ -211,7 +218,7 @@ msgstr ""
class
UpdateCubicWebCatalogCommand
(
Command
):
"""Update i18n catalogs for cubicweb library.
It will regenerate cubicweb/i18n/xx.po files. You'll have then to edit those
files to add translations of newly added messages.
"""
...
...
@@ -281,7 +288,7 @@ class UpdateTemplateCatalogCommand(Command):
"""
name
=
'i18nupdate'
arguments
=
'[<cube>...]'
def
run
(
self
,
args
):
"""run the command with its specific arguments"""
if
args
:
...
...
@@ -328,7 +335,7 @@ def update_cubes_catalogs(cubes):
execute
(
'xgettext --no-location --omit-header -k_ -L java --from-code=utf-8 -o %s %s'
%
(
tmppotfile
,
' '
.
join
(
jsfiles
)))
# no pot file created if there are no string to translate
if
exists
(
tmppotfile
):
if
exists
(
tmppotfile
):
potfiles
.
append
(
tmppotfile
)
print
'******** create cube specific catalog'
tmppotfile
=
join
(
tempdir
,
'generated.pot'
)
...
...
@@ -367,7 +374,7 @@ class LiveServerCommand(Command):
name
=
'live-server'
arguments
=
''
options
=
()
def
run
(
self
,
args
):
"""run the command with its specific arguments"""
from
cubicweb.devtools.livetest
import
runserver
...
...
@@ -415,7 +422,7 @@ class NewCubeCommand(Command):
),
)
def
run
(
self
,
args
):
if
len
(
args
)
!=
1
:
raise
BadCommandUsage
(
"exactly one argument (cube name) is expected"
)
...
...
@@ -449,7 +456,7 @@ class NewCubeCommand(Command):
distname
=
'cubicweb-'
+
distname
else
:
distname
=
'cubicweb-%s'
%
cubename
.
lower
()
longdesc
=
shortdesc
=
raw_input
(
'Enter a short description for your cube: '
)
if
verbose
:
longdesc
=
raw_input
(
'Enter a long description (or nothing if you want to reuse the short one): '
)
...
...
@@ -487,7 +494,7 @@ class NewCubeCommand(Command):
elif
ans
==
's'
:
break
return
includes
class
ExamineLogCommand
(
Command
):
"""Examine a rql log file.
...
...
@@ -506,7 +513,7 @@ class ExamineLogCommand(Command):
name
=
'exlog'
options
=
(
)
def
run
(
self
,
args
):
if
args
:
raise
BadCommandUsage
(
"no argument expected"
)
...
...
@@ -540,7 +547,7 @@ class ExamineLogCommand(Command):
print
'Percentage;Cumulative Time;Occurences;Query'
for
time
,
occ
,
rql
in
stat
:
print
'%.2f;%.2f;%s;%s'
%
(
time
/
total_time
,
time
,
occ
,
rql
)
register_commands
((
UpdateCubicWebCatalogCommand
,
UpdateTemplateCatalogCommand
,
LiveServerCommand
,
...
...
rtags.py
View file @
982e8616
...
...
@@ -17,21 +17,21 @@ class RelationTags(object):
should use rtags / etype_rtags / add_rtag api. Otherwise, a single tag is
associated to each key, and you should use rtag / etype_rtag / set_rtag api.
"""
def
__init__
(
self
,
use_set
=
False
):
self
.
use_set
=
use_set
self
.
_tagdefs
=
{}
def
set_rtag
(
self
,
tag
,
rtype
,
role
,
stype
=
'*'
,
otype
=
'*'
):
assert
not
self
.
use_set
assert
role
in
(
'subject'
,
'object'
),
role
self
.
_tagdefs
[(
str
(
rtype
),
role
,
str
(
stype
),
str
(
otype
))]
=
tag
def
del_rtag
(
self
,
rtype
,
role
,
stype
=
'*'
,
otype
=
'*'
):
assert
not
self
.
use_set
assert
role
in
(
'subject'
,
'object'
),
role
del
self
.
_tagdefs
[(
str
(
rtype
),
role
,
str
(
stype
),
str
(
otype
))]
def
rtag
(
self
,
rtype
,
role
,
stype
=
'*'
,
otype
=
'*'
):
assert
not
self
.
use_set
for
key
in
reversed
(
self
.
_get_keys
(
rtype
,
role
,
stype
,
otype
)):
...
...
@@ -40,18 +40,18 @@ class RelationTags(object):
except
KeyError
:
continue
return
None
def
etype_rtag
(
self
,
etype
,
rtype
,
role
,
ttype
=
'*'
):
if
role
==
'subject'
:
return
self
.
rtag
(
rtype
,
role
,
etype
,
ttype
)
return
self
.
rtag
(
rtype
,
role
,
ttype
,
etype
)
def
add_rtag
(
self
,
tag
,
rtype
,
role
,
stype
=
'*'
,
otype
=
'*'
):
assert
self
.
use_set
assert
role
in
(
'subject'
,
'object'
),
role
rtags
=
self
.
_tagdefs
.
setdefault
((
rtype
,
role
,
stype
,
otype
),
set
())
rtags
.
add
(
tag
)
def
rtags
(
self
,
rtype
,
role
,
stype
=
'*'
,
otype
=
'*'
):
assert
self
.
use_set
rtags
=
set
()
...
...
@@ -61,13 +61,13 @@ class RelationTags(object):
except
KeyError
:
continue
return
rtags
def
etype_rtags
(
self
,
etype
,
rtype
,
role
,
ttype
=
'*'
):
if
role
==
'subject'
:
return
self
.
rtags
(
rtype
,
role
,
etype
,
ttype
)
return
self
.
rtags
(
rtype
,
role
,
ttype
,
etype
)
def
_get_keys
(
self
,
rtype
,
role
,
stype
,
otype
):
def
_get_keys
(
self
,
rtype
,
role
,
stype
,
otype
):
assert
role
in
(
'subject'
,
'object'
),
role
keys
=
[(
rtype
,
role
,
'*'
,
'*'
),
(
rtype
,
role
,
'*'
,
otype
),
...
...
@@ -78,9 +78,9 @@ class RelationTags(object):
if
stype
==
'*'
:
keys
.
remove
((
rtype
,
role
,
'*'
,
otype
))
if
otype
==
'*'
:
keys
.
remove
((
rtype
,
role
,
stype
,
'*'
))
keys
.
remove
((
rtype
,
role
,
stype
,
'*'
))
return
keys
# dict compat
def
__getitem__
(
self
,
key
):
if
isinstance
(
key
,
basestring
):
...
...
schema.py
View file @
982e8616
...
...
@@ -27,7 +27,7 @@ from cubicweb import set_log_methods
# XXX <3.2 bw compat
from
yams
import
schema
schema
.
use_py_datetime
()
nodes
.
use_py_datetime
()
nodes
.
use_py_datetime
()
_
=
unicode
...
...
@@ -43,7 +43,7 @@ ybo.RDEF_PROPERTIES += ('eid',)
def
bw_normalize_etype
(
etype
):
if
etype
in
ETYPE_NAME_MAP
:
msg
=
'%s has been renamed to %s, please update your code'
%
(
etype
,
ETYPE_NAME_MAP
[
etype
])
etype
,
ETYPE_NAME_MAP
[
etype
])
warn
(
msg
,
DeprecationWarning
,
stacklevel
=
4
)
etype
=
ETYPE_NAME_MAP
[
etype
]
return
etype
...
...
@@ -78,12 +78,12 @@ ybo.RelationDefinition._actual_types = _actual_types
class
RichString
(
ybo
.
String
):
"""Convenience RichString attribute type
The follwing declaration::
class Card(EntityType):
content = RichString(fulltextindexed=True, default_format='text/rest')
is equivalent to::
class Card(EntityType):
content_format = String(meta=True, internationalizable=True,
default='text/rest', constraints=[format_constraint])
...
...
@@ -106,7 +106,7 @@ def _add_relation(relations, rdef, name=None, insertidx=None):
constraints
=
rdef
.
format_constraints
)
yams_add_relation
(
relations
,
format_attrdef
,
name
+
'_format'
,
insertidx
)
yams_add_relation
(
relations
,
rdef
,
name
,
insertidx
)
def
display_name
(
req
,
key
,
form
=
''
):
"""return a internationalized string for the key (schema entity or relation
name) in a given form
...
...
@@ -258,19 +258,19 @@ class CubicWebEntitySchema(EntitySchema):
eid
=
getattr
(
edef
,
'eid'
,
None
)
self
.
eid
=
eid
# take care: no _groups attribute when deep-copying
if
getattr
(
self
,
'_groups'
,
None
):
if
getattr
(
self
,
'_groups'
,
None
):
for
groups
in
self
.
_groups
.
itervalues
():
for
group_or_rqlexpr
in
groups
:
if
isinstance
(
group_or_rqlexpr
,
RRQLExpression
):
msg
=
"can't use RRQLExpression on an entity type, use an ERQLExpression (%s)"
raise
BadSchemaDefinition
(
msg
%
self
.
type
)
def
attribute_definitions
(
self
):
"""return an iterator on attribute definitions
attribute relations are a subset of subject relations where the
object's type is a final entity
an attribute definition is a 2-uple :
* name of the relation
* schema of the destination entity type
...
...
@@ -280,7 +280,7 @@ class CubicWebEntitySchema(EntitySchema):
if
rschema
.
type
==
'has_text'
:
continue
yield
rschema
,
attrschema
def
add_subject_relation
(
self
,
rschema
):
"""register the relation schema as possible subject relation"""
super
(
CubicWebEntitySchema
,
self
).
add_subject_relation
(
rschema
)
...
...
@@ -289,7 +289,7 @@ class CubicWebEntitySchema(EntitySchema):
def
del_subject_relation
(
self
,
rtype
):
super
(
CubicWebEntitySchema
,
self
).
del_subject_relation
(
rtype
)
self
.
_update_has_text
(
False
)
def
_update_has_text
(
self
,
need_has_text
=
None
):
may_need_has_text
,
has_has_text
=
False
,
False
for
rschema
in
self
.
subject_relations
():
...
...
@@ -317,11 +317,11 @@ class CubicWebEntitySchema(EntitySchema):
self
.
schema
.
add_relation_def
(
rdef
)
elif
not
need_has_text
and
has_has_text
:
self
.
schema
.
del_relation_def
(
self
.
type
,
'has_text'
,
'String'
)
def
schema_entity
(
self
):
"""return True if this entity type is used to build the schema"""
return
self
.
type
in
self
.
schema
.
schema_entity_types
()
def
check_perm
(
self
,
session
,
action
,
eid
=
None
):
# NB: session may be a server session or a request object
user
=
session
.
user
...
...
@@ -337,17 +337,17 @@ class CubicWebEntitySchema(EntitySchema):
# else if there is some rql expressions, check them
if
any
(
rqlexpr
.
check
(
session
,
eid
)
for
rqlexpr
in
self
.
get_rqlexprs
(
action
)):
return
return
raise
Unauthorized
(
action
,
str
(
self
))
def
rql_expression
(
self
,
expression
,
mainvars
=
None
,
eid
=
None
):
"""rql expression factory"""
return
ERQLExpression
(
expression
,
mainvars
,
eid
)
class
CubicWebRelationSchema
(
RelationSchema
):
RelationSchema
.
_RPROPERTIES
[
'eid'
]
=
None
_perms_checked
=
False
def
__init__
(
self
,
schema
=
None
,
rdef
=
None
,
eid
=
None
,
**
kwargs
):
if
rdef
is
not
None
:
# if this relation is inlined
...
...
@@ -356,8 +356,8 @@ class CubicWebRelationSchema(RelationSchema):
if
eid
is
None
and
rdef
is
not
None
:
eid
=
getattr
(
rdef
,
'eid'
,
None
)
self
.
eid
=
eid
def
update
(
self
,
subjschema
,
objschema
,
rdef
):
super
(
CubicWebRelationSchema
,
self
).
update
(
subjschema
,
objschema
,
rdef
)
if
not
self
.
_perms_checked
and
self
.
_groups
:
...
...
@@ -377,7 +377,7 @@ class CubicWebRelationSchema(RelationSchema):
newrqlexprs
.
append
(
ERQLExpression
(
rqlexpr
.
expression
,
rqlexpr
.
mainvars
,
rqlexpr
.
eid
))
self
.
set_rqlexprs
(
action
,
newrqlexprs
)
self
.
set_rqlexprs
(
action
,
newrqlexprs
)
else
:
msg
=
"can't use RRQLExpression on a final relation "
\
"type (eg attribute relation), use an ERQLExpression (%s)"
...
...
@@ -388,16 +388,16 @@ class CubicWebRelationSchema(RelationSchema):
"a RRQLExpression (%s)"
raise
BadSchemaDefinition
(
msg
%
self
.
type
)
self
.
_perms_checked
=
True
def
cardinality
(
self
,
subjtype
,
objtype
,
target
):
card
=
self
.
rproperty
(
subjtype
,
objtype
,
'cardinality'
)
return
(
target
==
'subject'
and
card
[
0
])
or
\
(
target
==
'object'
and
card
[
1
])
def
schema_relation
(
self
):
return
self
.
type
in
(
'relation_type'
,
'from_entity'
,
'to_entity'
,
'constrained_by'
,
'cstrtype'
)
def
physical_mode
(
self
):
"""return an appropriate mode for physical storage of this relation type:
* 'subjectinline' if every possible subject cardinalities are 1 or ?
...
...
@@ -413,7 +413,7 @@ class CubicWebRelationSchema(RelationSchema):
# in an allowed group, if so that's enough internal sessions should
# always stop there
if
session
.
user
.
matching_groups
(
self
.
get_groups
(
action
)):
return
return
# else if there is some rql expressions, check them
if
any
(
rqlexpr
.
check
(
session
,
*
args
,
**
kwargs
)
for
rqlexpr
in
self
.
get_rqlexprs
(
action
)):
...
...
@@ -426,7 +426,7 @@ class CubicWebRelationSchema(RelationSchema):
return
ERQLExpression
(
expression
,
mainvars
,
eid
)
return
RRQLExpression
(
expression
,
mainvars
,
eid
)
class
CubicWebSchema
(
Schema
):
"""set of entities and relations schema defining the possible data sets
used in an application
...
...
@@ -434,11 +434,11 @@ class CubicWebSchema(Schema):
:type name: str
:ivar name: name of the schema, usually the application identifier
:type base: str
:ivar base: path of the directory where the schema is defined
"""
reading_from_database
=
False
reading_from_database
=
False
entity_class
=
CubicWebEntitySchema
relation_class
=
CubicWebRelationSchema
...
...
@@ -455,7 +455,7 @@ class CubicWebSchema(Schema):
rschema
=
self
.
add_relation_type
(
ybo
.
RelationType
(
'identity'
,
meta
=
True
))
rschema
.
final
=
False
rschema
.
set_default_groups
()
def
schema_entity_types
(
self
):
"""return the list of entity types used to build the schema"""
return
frozenset
((
'CWEType'
,
'CWRType'
,
'CWAttribute'
,
'CWRelation'
,
...
...
@@ -463,7 +463,7 @@ class CubicWebSchema(Schema):
# XXX those are not really "schema" entity types
# but we usually don't want them as @* targets
'CWProperty'
,
'CWPermission'
,
'State'
,
'Transition'
))
def
add_entity_type
(
self
,
edef
):
edef
.
name
=
edef
.
name
.
encode
()
edef
.
name
=
bw_normalize_etype
(
edef
.
name
)
...
...
@@ -478,13 +478,13 @@ class CubicWebSchema(Schema):
self
.
add_relation_def
(
rdef
)
self
.
_eid_index
[
eschema
.
eid
]
=
eschema
return
eschema
def
add_relation_type
(
self
,
rdef
):
rdef
.
name
=
rdef
.
name
.
lower
().
encode
()
rschema
=
super
(
CubicWebSchema
,
self
).
add_relation_type
(
rdef
)
self
.
_eid_index
[
rschema
.
eid
]
=
rschema
return
rschema
def
add_relation_def
(
self
,
rdef
):
"""build a part of a relation schema
(i.e. add a relation between two specific entity's types)
...
...
@@ -511,18 +511,18 @@ class CubicWebSchema(Schema):
self
.
eschema
(
rdef
.
object
))
except
AttributeError
:
pass
# not a serialized schema
def
del_relation_type
(
self
,
rtype
):
rschema
=
self
.
rschema
(
rtype
)
self
.
_eid_index
.
pop
(
rschema
.
eid
,
None
)
super
(
CubicWebSchema
,
self
).
del_relation_type
(
rtype
)
def
del_relation_def
(
self
,
subjtype
,
rtype
,
objtype
):
for
k
,
v
in
self
.
_eid_index
.
items
():