author | Denis Laxalde <denis.laxalde@logilab.fr> |
Fri, 22 Apr 2016 16:16:09 +0200 | |
changeset 11261 | 9e926f2dc84d |
parent 10666 | 7f6b5f023884 |
permissions | -rw-r--r-- |
7153
7df83a6d17c0
[entity vocabulary] fix unrelated rql generation to skip rql constraints that don't make sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6919
diff
changeset
|
1 |
# copyright 2003-2011 LOGILAB S.A. (Paris, FRANCE), all rights reserved. |
5421
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4467
diff
changeset
|
2 |
# contact http://www.logilab.fr/ -- mailto:contact@logilab.fr |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4467
diff
changeset
|
3 |
# |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4467
diff
changeset
|
4 |
# This file is part of CubicWeb. |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4467
diff
changeset
|
5 |
# |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4467
diff
changeset
|
6 |
# CubicWeb is free software: you can redistribute it and/or modify it under the |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4467
diff
changeset
|
7 |
# terms of the GNU Lesser General Public License as published by the Free |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4467
diff
changeset
|
8 |
# Software Foundation, either version 2.1 of the License, or (at your option) |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4467
diff
changeset
|
9 |
# any later version. |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4467
diff
changeset
|
10 |
# |
5424
8ecbcbff9777
replace logilab-common by CubicWeb in disclaimer
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5421
diff
changeset
|
11 |
# CubicWeb is distributed in the hope that it will be useful, but WITHOUT |
5421
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4467
diff
changeset
|
12 |
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4467
diff
changeset
|
13 |
# FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4467
diff
changeset
|
14 |
# details. |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4467
diff
changeset
|
15 |
# |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4467
diff
changeset
|
16 |
# You should have received a copy of the GNU Lesser General Public License along |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4467
diff
changeset
|
17 |
# with CubicWeb. If not, see <http://www.gnu.org/licenses/>. |
2615
1ea41b7c0836
F [dialog] offer to create backup. refactor to use l.c.shellutils.ASK
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
1977
diff
changeset
|
18 |
|
10529
747eded13c68
[test] use FakeFile instead of File in test_fulltextindex
Julien Cristau <julien.cristau@logilab.fr>
parents:
9978
diff
changeset
|
19 |
from yams.buildobjs import (EntityType, String, RichString, Bytes, |
11261
9e926f2dc84d
[entity] Exclude computed relations from Entity.copy_relations
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
10666
diff
changeset
|
20 |
ComputedRelation, SubjectRelation, RelationDefinition) |
7425
7e9d1d6fcba7
[entity fetch_attrs] remove ambiguous relations on different etypes from fetched attrs or it may produce wrong related results; closes #1700896
Florent Cayré <florent.cayre@gmail.com>
parents:
7154
diff
changeset
|
21 |
|
7153
7df83a6d17c0
[entity vocabulary] fix unrelated rql generation to skip rql constraints that don't make sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6919
diff
changeset
|
22 |
from cubicweb.schema import (WorkflowableEntityType, |
7df83a6d17c0
[entity vocabulary] fix unrelated rql generation to skip rql constraints that don't make sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6919
diff
changeset
|
23 |
RQLConstraint, RQLVocabularyConstraint) |
2615
1ea41b7c0836
F [dialog] offer to create backup. refactor to use l.c.shellutils.ASK
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
1977
diff
changeset
|
24 |
|
7425
7e9d1d6fcba7
[entity fetch_attrs] remove ambiguous relations on different etypes from fetched attrs or it may produce wrong related results; closes #1700896
Florent Cayré <florent.cayre@gmail.com>
parents:
7154
diff
changeset
|
25 |
|
10666
7f6b5f023884
[py3k] replace '_ = unicode' in global scope (closes #7589459)
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10529
diff
changeset
|
26 |
from cubicweb import _ |
10529
747eded13c68
[test] use FakeFile instead of File in test_fulltextindex
Julien Cristau <julien.cristau@logilab.fr>
parents:
9978
diff
changeset
|
27 |
|
747eded13c68
[test] use FakeFile instead of File in test_fulltextindex
Julien Cristau <julien.cristau@logilab.fr>
parents:
9978
diff
changeset
|
28 |
|
11261
9e926f2dc84d
[entity] Exclude computed relations from Entity.copy_relations
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
10666
diff
changeset
|
29 |
class buddies(ComputedRelation): |
9e926f2dc84d
[entity] Exclude computed relations from Entity.copy_relations
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
10666
diff
changeset
|
30 |
rule = 'S in_group G, O in_group G' |
9e926f2dc84d
[entity] Exclude computed relations from Entity.copy_relations
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
10666
diff
changeset
|
31 |
|
9e926f2dc84d
[entity] Exclude computed relations from Entity.copy_relations
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
10666
diff
changeset
|
32 |
|
744 | 33 |
class Personne(EntityType): |
748 | 34 |
nom = String(required=True) |
744 | 35 |
prenom = String() |
36 |
type = String() |
|
37 |
travaille = SubjectRelation('Societe') |
|
38 |
evaluee = SubjectRelation(('Note', 'Personne')) |
|
7153
7df83a6d17c0
[entity vocabulary] fix unrelated rql generation to skip rql constraints that don't make sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6919
diff
changeset
|
39 |
connait = SubjectRelation( |
7df83a6d17c0
[entity vocabulary] fix unrelated rql generation to skip rql constraints that don't make sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6919
diff
changeset
|
40 |
'Personne', symmetric=True, |
7df83a6d17c0
[entity vocabulary] fix unrelated rql generation to skip rql constraints that don't make sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6919
diff
changeset
|
41 |
constraints=[ |
7df83a6d17c0
[entity vocabulary] fix unrelated rql generation to skip rql constraints that don't make sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6919
diff
changeset
|
42 |
RQLConstraint('NOT S identity O'), |
7154
5e2f93b88d86
[entity vocabulary] refactor unrelated rql to allow usage of RQLRewriter to insert schema constraints. Closes #1561806
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7153
diff
changeset
|
43 |
# conflicting constraints, see cw_unrelated_rql tests in |
5e2f93b88d86
[entity vocabulary] refactor unrelated rql to allow usage of RQLRewriter to insert schema constraints. Closes #1561806
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7153
diff
changeset
|
44 |
# unittest_entity.py |
5e2f93b88d86
[entity vocabulary] refactor unrelated rql to allow usage of RQLRewriter to insert schema constraints. Closes #1561806
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7153
diff
changeset
|
45 |
RQLVocabularyConstraint('NOT (S connait P, P nom "toto")'), |
5e2f93b88d86
[entity vocabulary] refactor unrelated rql to allow usage of RQLRewriter to insert schema constraints. Closes #1561806
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7153
diff
changeset
|
46 |
RQLVocabularyConstraint('S travaille P, P nom "tutu"')]) |
7973
64639bc94e25
[entity] restrict creation form field vocabulary using __linkto information (closes #1799997)
Florent Cayré <florent.cayre@gmail.com>
parents:
7425
diff
changeset
|
47 |
actionnaire = SubjectRelation('Societe', cardinality='??', |
64639bc94e25
[entity] restrict creation form field vocabulary using __linkto information (closes #1799997)
Florent Cayré <florent.cayre@gmail.com>
parents:
7425
diff
changeset
|
48 |
constraints=[RQLConstraint('NOT EXISTS(O contrat_exclusif S)')]) |
64639bc94e25
[entity] restrict creation form field vocabulary using __linkto information (closes #1799997)
Florent Cayré <florent.cayre@gmail.com>
parents:
7425
diff
changeset
|
49 |
dirige = SubjectRelation('Societe', cardinality='??', |
64639bc94e25
[entity] restrict creation form field vocabulary using __linkto information (closes #1799997)
Florent Cayré <florent.cayre@gmail.com>
parents:
7425
diff
changeset
|
50 |
constraints=[RQLConstraint('S actionnaire O')]) |
9293
723e2c586ea3
[entity] Entity.related(): add a targettypes argument (closes #2957313)
Aurelien Campeas
parents:
9214
diff
changeset
|
51 |
associe = SubjectRelation('Personne', cardinality='?*', |
7973
64639bc94e25
[entity] restrict creation form field vocabulary using __linkto information (closes #1799997)
Florent Cayré <florent.cayre@gmail.com>
parents:
7425
diff
changeset
|
52 |
constraints=[RQLConstraint('S actionnaire SOC, O actionnaire SOC')]) |
1476 | 53 |
|
9214
be05b42b4825
Do not use cubicweb-card in rest_path tests
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
7973
diff
changeset
|
54 |
class Ami(EntityType): |
be05b42b4825
Do not use cubicweb-card in rest_path tests
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
7973
diff
changeset
|
55 |
"""A Person, for which surname is not required""" |
be05b42b4825
Do not use cubicweb-card in rest_path tests
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
7973
diff
changeset
|
56 |
prenom = String() |
be05b42b4825
Do not use cubicweb-card in rest_path tests
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
7973
diff
changeset
|
57 |
nom = String() |
7425
7e9d1d6fcba7
[entity fetch_attrs] remove ambiguous relations on different etypes from fetched attrs or it may produce wrong related results; closes #1700896
Florent Cayré <florent.cayre@gmail.com>
parents:
7154
diff
changeset
|
58 |
|
744 | 59 |
class Societe(EntityType): |
60 |
nom = String() |
|
61 |
evaluee = SubjectRelation('Note') |
|
7425
7e9d1d6fcba7
[entity fetch_attrs] remove ambiguous relations on different etypes from fetched attrs or it may produce wrong related results; closes #1700896
Florent Cayré <florent.cayre@gmail.com>
parents:
7154
diff
changeset
|
62 |
fournit = SubjectRelation(('Service', 'Produit'), cardinality='1*') |
7973
64639bc94e25
[entity] restrict creation form field vocabulary using __linkto information (closes #1799997)
Florent Cayré <florent.cayre@gmail.com>
parents:
7425
diff
changeset
|
63 |
contrat_exclusif = SubjectRelation('Personne', cardinality='??') |
7425
7e9d1d6fcba7
[entity fetch_attrs] remove ambiguous relations on different etypes from fetched attrs or it may produce wrong related results; closes #1700896
Florent Cayré <florent.cayre@gmail.com>
parents:
7154
diff
changeset
|
64 |
|
7e9d1d6fcba7
[entity fetch_attrs] remove ambiguous relations on different etypes from fetched attrs or it may produce wrong related results; closes #1700896
Florent Cayré <florent.cayre@gmail.com>
parents:
7154
diff
changeset
|
65 |
class Service(EntityType): |
7e9d1d6fcba7
[entity fetch_attrs] remove ambiguous relations on different etypes from fetched attrs or it may produce wrong related results; closes #1700896
Florent Cayré <florent.cayre@gmail.com>
parents:
7154
diff
changeset
|
66 |
fabrique_par = SubjectRelation('Personne', cardinality='1*') |
7e9d1d6fcba7
[entity fetch_attrs] remove ambiguous relations on different etypes from fetched attrs or it may produce wrong related results; closes #1700896
Florent Cayré <florent.cayre@gmail.com>
parents:
7154
diff
changeset
|
67 |
|
7e9d1d6fcba7
[entity fetch_attrs] remove ambiguous relations on different etypes from fetched attrs or it may produce wrong related results; closes #1700896
Florent Cayré <florent.cayre@gmail.com>
parents:
7154
diff
changeset
|
68 |
|
7e9d1d6fcba7
[entity fetch_attrs] remove ambiguous relations on different etypes from fetched attrs or it may produce wrong related results; closes #1700896
Florent Cayré <florent.cayre@gmail.com>
parents:
7154
diff
changeset
|
69 |
class Produit(EntityType): |
9731
027bfc467a46
[cache] fix a cache issue with an entity created without relation cache prefill
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9214
diff
changeset
|
70 |
fabrique_par = SubjectRelation('Usine', cardinality='1*', inlined=True) |
7425
7e9d1d6fcba7
[entity fetch_attrs] remove ambiguous relations on different etypes from fetched attrs or it may produce wrong related results; closes #1700896
Florent Cayré <florent.cayre@gmail.com>
parents:
7154
diff
changeset
|
71 |
|
7e9d1d6fcba7
[entity fetch_attrs] remove ambiguous relations on different etypes from fetched attrs or it may produce wrong related results; closes #1700896
Florent Cayré <florent.cayre@gmail.com>
parents:
7154
diff
changeset
|
72 |
|
7e9d1d6fcba7
[entity fetch_attrs] remove ambiguous relations on different etypes from fetched attrs or it may produce wrong related results; closes #1700896
Florent Cayré <florent.cayre@gmail.com>
parents:
7154
diff
changeset
|
73 |
class Usine(EntityType): |
7e9d1d6fcba7
[entity fetch_attrs] remove ambiguous relations on different etypes from fetched attrs or it may produce wrong related results; closes #1700896
Florent Cayré <florent.cayre@gmail.com>
parents:
7154
diff
changeset
|
74 |
lieu = String(required=True) |
7e9d1d6fcba7
[entity fetch_attrs] remove ambiguous relations on different etypes from fetched attrs or it may produce wrong related results; closes #1700896
Florent Cayré <florent.cayre@gmail.com>
parents:
7154
diff
changeset
|
75 |
|
1476 | 76 |
|
744 | 77 |
class Note(EntityType): |
78 |
type = String() |
|
79 |
ecrit_par = SubjectRelation('Personne') |
|
80 |
||
7425
7e9d1d6fcba7
[entity fetch_attrs] remove ambiguous relations on different etypes from fetched attrs or it may produce wrong related results; closes #1700896
Florent Cayré <florent.cayre@gmail.com>
parents:
7154
diff
changeset
|
81 |
|
744 | 82 |
class SubNote(Note): |
83 |
__specializes_schema__ = True |
|
750
89e997bc2bf1
update test for new test schema
sylvain.thenault@logilab.fr
parents:
748
diff
changeset
|
84 |
description = String() |
744 | 85 |
|
7425
7e9d1d6fcba7
[entity fetch_attrs] remove ambiguous relations on different etypes from fetched attrs or it may produce wrong related results; closes #1700896
Florent Cayré <florent.cayre@gmail.com>
parents:
7154
diff
changeset
|
86 |
|
744 | 87 |
class tags(RelationDefinition): |
88 |
subject = 'Tag' |
|
89 |
object = ('Personne', 'Note') |
|
90 |
||
7425
7e9d1d6fcba7
[entity fetch_attrs] remove ambiguous relations on different etypes from fetched attrs or it may produce wrong related results; closes #1700896
Florent Cayré <florent.cayre@gmail.com>
parents:
7154
diff
changeset
|
91 |
|
744 | 92 |
class evaluee(RelationDefinition): |
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
750
diff
changeset
|
93 |
subject = 'CWUser' |
744 | 94 |
object = 'Note' |
6908
f07dc0e8948d
fix #1452413 : is_in_state selector does not match initial state of an entity
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
5424
diff
changeset
|
95 |
|
6919
8fd6921f3e7c
[selectors] modify workflow selectors: is_in_state, on_transition
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6908
diff
changeset
|
96 |
|
6908
f07dc0e8948d
fix #1452413 : is_in_state selector does not match initial state of an entity
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
5424
diff
changeset
|
97 |
class StateFull(WorkflowableEntityType): |
f07dc0e8948d
fix #1452413 : is_in_state selector does not match initial state of an entity
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
5424
diff
changeset
|
98 |
name = String() |
9978
8f4b15e5b300
[entities] cw_rest_attr_info() should only consider required attributes (closes #3766717)
Rémi Cardona <remi.cardona@logilab.fr>
parents:
9769
diff
changeset
|
99 |
|
8f4b15e5b300
[entities] cw_rest_attr_info() should only consider required attributes (closes #3766717)
Rémi Cardona <remi.cardona@logilab.fr>
parents:
9769
diff
changeset
|
100 |
|
8f4b15e5b300
[entities] cw_rest_attr_info() should only consider required attributes (closes #3766717)
Rémi Cardona <remi.cardona@logilab.fr>
parents:
9769
diff
changeset
|
101 |
class Reference(EntityType): |
8f4b15e5b300
[entities] cw_rest_attr_info() should only consider required attributes (closes #3766717)
Rémi Cardona <remi.cardona@logilab.fr>
parents:
9769
diff
changeset
|
102 |
nom = String(unique=True) |
8f4b15e5b300
[entities] cw_rest_attr_info() should only consider required attributes (closes #3766717)
Rémi Cardona <remi.cardona@logilab.fr>
parents:
9769
diff
changeset
|
103 |
ean = String(unique=True, required=True) |
10529
747eded13c68
[test] use FakeFile instead of File in test_fulltextindex
Julien Cristau <julien.cristau@logilab.fr>
parents:
9978
diff
changeset
|
104 |
|
747eded13c68
[test] use FakeFile instead of File in test_fulltextindex
Julien Cristau <julien.cristau@logilab.fr>
parents:
9978
diff
changeset
|
105 |
|
747eded13c68
[test] use FakeFile instead of File in test_fulltextindex
Julien Cristau <julien.cristau@logilab.fr>
parents:
9978
diff
changeset
|
106 |
class FakeFile(EntityType): |
747eded13c68
[test] use FakeFile instead of File in test_fulltextindex
Julien Cristau <julien.cristau@logilab.fr>
parents:
9978
diff
changeset
|
107 |
title = String(fulltextindexed=True, maxsize=256) |
747eded13c68
[test] use FakeFile instead of File in test_fulltextindex
Julien Cristau <julien.cristau@logilab.fr>
parents:
9978
diff
changeset
|
108 |
data = Bytes(required=True, fulltextindexed=True, description=_('file to upload')) |
747eded13c68
[test] use FakeFile instead of File in test_fulltextindex
Julien Cristau <julien.cristau@logilab.fr>
parents:
9978
diff
changeset
|
109 |
data_format = String(required=True, maxsize=128, |
747eded13c68
[test] use FakeFile instead of File in test_fulltextindex
Julien Cristau <julien.cristau@logilab.fr>
parents:
9978
diff
changeset
|
110 |
description=_('MIME type of the file. Should be dynamically set at upload time.')) |
747eded13c68
[test] use FakeFile instead of File in test_fulltextindex
Julien Cristau <julien.cristau@logilab.fr>
parents:
9978
diff
changeset
|
111 |
data_encoding = String(maxsize=32, |
747eded13c68
[test] use FakeFile instead of File in test_fulltextindex
Julien Cristau <julien.cristau@logilab.fr>
parents:
9978
diff
changeset
|
112 |
description=_('encoding of the file when it applies (e.g. text). ' |
747eded13c68
[test] use FakeFile instead of File in test_fulltextindex
Julien Cristau <julien.cristau@logilab.fr>
parents:
9978
diff
changeset
|
113 |
'Should be dynamically set at upload time.')) |
747eded13c68
[test] use FakeFile instead of File in test_fulltextindex
Julien Cristau <julien.cristau@logilab.fr>
parents:
9978
diff
changeset
|
114 |
data_name = String(required=True, fulltextindexed=True, |
747eded13c68
[test] use FakeFile instead of File in test_fulltextindex
Julien Cristau <julien.cristau@logilab.fr>
parents:
9978
diff
changeset
|
115 |
description=_('name of the file. Should be dynamically set at upload time.')) |
747eded13c68
[test] use FakeFile instead of File in test_fulltextindex
Julien Cristau <julien.cristau@logilab.fr>
parents:
9978
diff
changeset
|
116 |
description = RichString(fulltextindexed=True, internationalizable=True, |
747eded13c68
[test] use FakeFile instead of File in test_fulltextindex
Julien Cristau <julien.cristau@logilab.fr>
parents:
9978
diff
changeset
|
117 |
default_format='text/rest') |