author | Nicolas Chauvat <nicolas.chauvat@logilab.fr> |
Tue, 20 Apr 2010 15:33:09 +0200 | |
branch | stable |
changeset 5350 | 49c065ae225e |
parent 5309 | e8567135a927 |
child 5421 | 8167de96c523 |
permissions | -rw-r--r-- |
5309
e8567135a927
[doc/book] fix docstrings, add notes
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
4936
diff
changeset
|
1 |
# organization: Logilab |
e8567135a927
[doc/book] fix docstrings, add notes
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
4936
diff
changeset
|
2 |
# copyright: 2001-2010 LOGILAB S.A. (Paris, FRANCE), license is LGPL v2. |
e8567135a927
[doc/book] fix docstrings, add notes
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
4936
diff
changeset
|
3 |
# contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr |
e8567135a927
[doc/book] fix docstrings, add notes
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
4936
diff
changeset
|
4 |
# license: GNU Lesser General Public License, v2.1 - http://www.gnu.org/licenses |
e8567135a927
[doc/book] fix docstrings, add notes
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
4936
diff
changeset
|
5 |
""" |
e8567135a927
[doc/book] fix docstrings, add notes
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
4936
diff
changeset
|
6 |
Standard interfaces. |
0 | 7 |
|
5309
e8567135a927
[doc/book] fix docstrings, add notes
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
4936
diff
changeset
|
8 |
.. note:: |
e8567135a927
[doc/book] fix docstrings, add notes
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
4936
diff
changeset
|
9 |
|
e8567135a927
[doc/book] fix docstrings, add notes
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
4936
diff
changeset
|
10 |
The `implements` selector matches not only entity classes but also |
e8567135a927
[doc/book] fix docstrings, add notes
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
4936
diff
changeset
|
11 |
their interfaces. Writing __select__ = implements('IGeocodable') is |
e8567135a927
[doc/book] fix docstrings, add notes
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
4936
diff
changeset
|
12 |
a perfectly fine thing to do. |
0 | 13 |
""" |
14 |
__docformat__ = "restructuredtext en" |
|
15 |
||
16 |
from logilab.common.interface import Interface |
|
17 |
||
18 |
class IEmailable(Interface): |
|
19 |
"""interface for emailable entities""" |
|
1553 | 20 |
|
0 | 21 |
def get_email(self): |
22 |
"""return email address""" |
|
23 |
||
24 |
@classmethod |
|
25 |
def allowed_massmail_keys(cls): |
|
26 |
"""returns a set of allowed email substitution keys |
|
27 |
||
28 |
The default is to return the entity's attribute list but an |
|
29 |
entity class might override this method to allow extra keys. |
|
30 |
For instance, the Person class might want to return a `companyname` |
|
31 |
key. |
|
32 |
""" |
|
33 |
||
34 |
def as_email_context(self): |
|
35 |
"""returns the dictionary as used by the sendmail controller to |
|
36 |
build email bodies. |
|
1553 | 37 |
|
0 | 38 |
NOTE: the dictionary keys should match the list returned by the |
39 |
`allowed_massmail_keys` method. |
|
40 |
""" |
|
41 |
||
42 |
||
43 |
class IWorkflowable(Interface): |
|
44 |
"""interface for entities dealing with a specific workflow""" |
|
2920
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2747
diff
changeset
|
45 |
# XXX to be completed, see cw.entities.wfobjs.WorkflowableMixIn |
0 | 46 |
|
47 |
@property |
|
48 |
def state(self): |
|
2920
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2747
diff
changeset
|
49 |
"""return current state name""" |
0 | 50 |
|
51 |
def change_state(self, stateeid, trcomment=None, trcommentformat=None): |
|
2920
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2747
diff
changeset
|
52 |
"""change the entity's state to the state of the given name in entity's |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2747
diff
changeset
|
53 |
workflow |
0 | 54 |
""" |
1553 | 55 |
|
0 | 56 |
def latest_trinfo(self): |
57 |
"""return the latest transition information for this entity |
|
58 |
""" |
|
59 |
||
2920
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2747
diff
changeset
|
60 |
|
0 | 61 |
class IProgress(Interface): |
62 |
"""something that has a cost, a state and a progression |
|
63 |
||
4023
eae23c40627a
drop common subpackage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3635
diff
changeset
|
64 |
Take a look at cubicweb.mixins.ProgressMixIn for some |
0 | 65 |
default implementations |
66 |
""" |
|
67 |
||
68 |
@property |
|
69 |
def cost(self): |
|
70 |
"""the total cost""" |
|
71 |
||
72 |
@property |
|
73 |
def done(self): |
|
74 |
"""what is already done""" |
|
75 |
||
76 |
@property |
|
77 |
def todo(self): |
|
78 |
"""what remains to be done""" |
|
1553 | 79 |
|
0 | 80 |
def progress_info(self): |
81 |
"""returns a dictionary describing progress/estimated cost of the |
|
82 |
version. |
|
83 |
||
4936
a4b772a0d801
Fixed some of the documentation warnings when building the book with sphinx.
Adrien Chauve <adrien.chauve@logilab.fr>
parents:
4252
diff
changeset
|
84 |
- mandatory keys are (''estimated', 'done', 'todo') |
a4b772a0d801
Fixed some of the documentation warnings when building the book with sphinx.
Adrien Chauve <adrien.chauve@logilab.fr>
parents:
4252
diff
changeset
|
85 |
|
a4b772a0d801
Fixed some of the documentation warnings when building the book with sphinx.
Adrien Chauve <adrien.chauve@logilab.fr>
parents:
4252
diff
changeset
|
86 |
- optional keys are ('notestimated', 'notestimatedcorrected', |
a4b772a0d801
Fixed some of the documentation warnings when building the book with sphinx.
Adrien Chauve <adrien.chauve@logilab.fr>
parents:
4252
diff
changeset
|
87 |
'estimatedcorrected') |
a4b772a0d801
Fixed some of the documentation warnings when building the book with sphinx.
Adrien Chauve <adrien.chauve@logilab.fr>
parents:
4252
diff
changeset
|
88 |
|
a4b772a0d801
Fixed some of the documentation warnings when building the book with sphinx.
Adrien Chauve <adrien.chauve@logilab.fr>
parents:
4252
diff
changeset
|
89 |
'noestimated' and 'notestimatedcorrected' should default to 0 |
a4b772a0d801
Fixed some of the documentation warnings when building the book with sphinx.
Adrien Chauve <adrien.chauve@logilab.fr>
parents:
4252
diff
changeset
|
90 |
'estimatedcorrected' should default to 'estimated' |
a4b772a0d801
Fixed some of the documentation warnings when building the book with sphinx.
Adrien Chauve <adrien.chauve@logilab.fr>
parents:
4252
diff
changeset
|
91 |
""" |
0 | 92 |
|
93 |
def finished(self): |
|
94 |
"""returns True if status is finished""" |
|
95 |
||
96 |
def in_progress(self): |
|
97 |
"""returns True if status is not finished""" |
|
98 |
||
99 |
def progress(self): |
|
100 |
"""returns the % progress of the task item""" |
|
1553 | 101 |
|
102 |
||
0 | 103 |
class IMileStone(IProgress): |
104 |
"""represents an ITask's item""" |
|
1553 | 105 |
|
0 | 106 |
parent_type = None # specify main task's type |
1553 | 107 |
|
0 | 108 |
def get_main_task(self): |
109 |
"""returns the main ITask entity""" |
|
110 |
||
111 |
def initial_prevision_date(self): |
|
112 |
"""returns the initial expected end of the milestone""" |
|
1553 | 113 |
|
0 | 114 |
def eta_date(self): |
115 |
"""returns expected date of completion based on what remains |
|
116 |
to be done |
|
117 |
""" |
|
118 |
||
119 |
def completion_date(self): |
|
120 |
"""returns date on which the subtask has been completed""" |
|
121 |
||
122 |
def contractors(self): |
|
123 |
"""returns the list of persons supposed to work on this task""" |
|
124 |
||
125 |
||
126 |
class ITree(Interface): |
|
127 |
||
128 |
def parent(self): |
|
129 |
"""returns the parent entity""" |
|
130 |
||
131 |
def children(self): |
|
132 |
"""returns the item's children""" |
|
133 |
||
2747
4f9ffcd8d5a2
cleanup docstring, add actually used method to the ITree interface
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2135
diff
changeset
|
134 |
def children_rql(self): |
4f9ffcd8d5a2
cleanup docstring, add actually used method to the ITree interface
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2135
diff
changeset
|
135 |
"""XXX returns RQL to get children""" |
4f9ffcd8d5a2
cleanup docstring, add actually used method to the ITree interface
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2135
diff
changeset
|
136 |
|
3635
a56759c3c99f
do not override __iter__ on entities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2920
diff
changeset
|
137 |
def iterchildren(self): |
0 | 138 |
"""iterates over the item's children""" |
1553 | 139 |
|
0 | 140 |
def is_leaf(self): |
141 |
"""returns true if this node as no child""" |
|
142 |
||
143 |
def is_root(self): |
|
144 |
"""returns true if this node has no parent""" |
|
145 |
||
146 |
def root(self): |
|
2747
4f9ffcd8d5a2
cleanup docstring, add actually used method to the ITree interface
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2135
diff
changeset
|
147 |
"""returns the root object""" |
0 | 148 |
|
149 |
||
150 |
## web specific interfaces #################################################### |
|
151 |
||
152 |
||
153 |
class IPrevNext(Interface): |
|
154 |
"""interface for entities which can be linked to a previous and/or next |
|
155 |
entity |
|
156 |
""" |
|
1553 | 157 |
|
0 | 158 |
def next_entity(self): |
159 |
"""return the 'next' entity""" |
|
160 |
def previous_entity(self): |
|
161 |
"""return the 'previous' entity""" |
|
162 |
||
163 |
||
164 |
class IBreadCrumbs(Interface): |
|
165 |
"""interface for entities which can be "located" on some path""" |
|
1553 | 166 |
|
5309
e8567135a927
[doc/book] fix docstrings, add notes
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
4936
diff
changeset
|
167 |
# XXX fix recurs ! |
0 | 168 |
def breadcrumbs(self, view, recurs=False): |
169 |
"""return a list containing some: |
|
1553 | 170 |
|
0 | 171 |
* tuple (url, label) |
172 |
* entity |
|
173 |
* simple label string |
|
174 |
||
175 |
defining path from a root to the current view |
|
176 |
||
177 |
the main view is given as argument so breadcrumbs may vary according |
|
178 |
to displayed view (may be None). When recursing on a parent entity, |
|
179 |
the `recurs` argument should be set to True. |
|
180 |
""" |
|
181 |
||
182 |
||
183 |
class IDownloadable(Interface): |
|
184 |
"""interface for downloadable entities""" |
|
1553 | 185 |
|
0 | 186 |
def download_url(self): # XXX not really part of this interface |
187 |
"""return an url to download entity's content""" |
|
188 |
def download_content_type(self): |
|
189 |
"""return MIME type of the downloadable content""" |
|
190 |
def download_encoding(self): |
|
191 |
"""return encoding of the downloadable content""" |
|
192 |
def download_file_name(self): |
|
193 |
"""return file name of the downloadable content""" |
|
194 |
def download_data(self): |
|
195 |
"""return actual data of the downloadable content""" |
|
196 |
||
197 |
||
198 |
class IEmbedable(Interface): |
|
199 |
"""interface for embedable entities""" |
|
1553 | 200 |
|
0 | 201 |
def embeded_url(self): |
202 |
"""embed action interface""" |
|
1553 | 203 |
|
0 | 204 |
class ICalendarable(Interface): |
767 | 205 |
"""interface for items that do have a begin date 'start' and an end date 'stop' |
1553 | 206 |
""" |
207 |
||
2135
55fc8b488907
[interfaces] describe more explicitly what should be implemente in the ICalendarable interface
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1977
diff
changeset
|
208 |
@property |
55fc8b488907
[interfaces] describe more explicitly what should be implemente in the ICalendarable interface
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1977
diff
changeset
|
209 |
def start(self): |
55fc8b488907
[interfaces] describe more explicitly what should be implemente in the ICalendarable interface
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1977
diff
changeset
|
210 |
"""return start date""" |
55fc8b488907
[interfaces] describe more explicitly what should be implemente in the ICalendarable interface
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1977
diff
changeset
|
211 |
|
55fc8b488907
[interfaces] describe more explicitly what should be implemente in the ICalendarable interface
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1977
diff
changeset
|
212 |
@property |
55fc8b488907
[interfaces] describe more explicitly what should be implemente in the ICalendarable interface
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1977
diff
changeset
|
213 |
def stop(self): |
55fc8b488907
[interfaces] describe more explicitly what should be implemente in the ICalendarable interface
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1977
diff
changeset
|
214 |
"""return stop state""" |
55fc8b488907
[interfaces] describe more explicitly what should be implemente in the ICalendarable interface
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1977
diff
changeset
|
215 |
|
0 | 216 |
class ICalendarViews(Interface): |
217 |
"""calendar views interface""" |
|
218 |
def matching_dates(self, begin, end): |
|
219 |
""" |
|
220 |
:param begin: day considered as begin of the range (`DateTime`) |
|
221 |
:param end: day considered as end of the range (`DateTime`) |
|
1553 | 222 |
|
0 | 223 |
:return: |
224 |
a list of dates (`DateTime`) in the range [`begin`, `end`] on which |
|
225 |
this entity apply |
|
226 |
""" |
|
1553 | 227 |
|
0 | 228 |
class ITimetableViews(Interface): |
229 |
"""timetable views interface""" |
|
230 |
def timetable_date(self): |
|
231 |
"""XXX explain |
|
1553 | 232 |
|
0 | 233 |
:return: date (`DateTime`) |
234 |
""" |
|
235 |
||
236 |
class IGeocodable(Interface): |
|
237 |
"""interface required by geocoding views such as gmap-view""" |
|
238 |
||
239 |
@property |
|
240 |
def latitude(self): |
|
241 |
"""returns the latitude of the entity""" |
|
242 |
||
243 |
@property |
|
244 |
def longitude(self): |
|
245 |
"""returns the longitude of the entity""" |
|
246 |
||
247 |
def marker_icon(self): |
|
248 |
"""returns the icon that should be used as the marker |
|
249 |
(returns None for default) |
|
250 |
""" |
|
1553 | 251 |
|
125
979dbe0cade3
views with rss feed
Laure Bourgois <Laure.Bourgois@logilab.fr>
parents:
0
diff
changeset
|
252 |
class IFeed(Interface): |
979dbe0cade3
views with rss feed
Laure Bourgois <Laure.Bourgois@logilab.fr>
parents:
0
diff
changeset
|
253 |
"""interface for entities with rss flux""" |
1553 | 254 |
|
125
979dbe0cade3
views with rss feed
Laure Bourgois <Laure.Bourgois@logilab.fr>
parents:
0
diff
changeset
|
255 |
def rss_feed_url(self): |
979dbe0cade3
views with rss feed
Laure Bourgois <Laure.Bourgois@logilab.fr>
parents:
0
diff
changeset
|
256 |
"""return an url which layout sub-entities item |
979dbe0cade3
views with rss feed
Laure Bourgois <Laure.Bourgois@logilab.fr>
parents:
0
diff
changeset
|
257 |
""" |
1553 | 258 |
|
990
5f1ff5b6907a
ISiocItem is an interface that is implemented by 'post' entities (in sioc specification) i.e blogentry, mail ...
Laure Bourgois <Laure.Bourgois@logilab.fr>
parents:
626
diff
changeset
|
259 |
class ISiocItem(Interface): |
5f1ff5b6907a
ISiocItem is an interface that is implemented by 'post' entities (in sioc specification) i.e blogentry, mail ...
Laure Bourgois <Laure.Bourgois@logilab.fr>
parents:
626
diff
changeset
|
260 |
"""interface for entities (which are item |
5f1ff5b6907a
ISiocItem is an interface that is implemented by 'post' entities (in sioc specification) i.e blogentry, mail ...
Laure Bourgois <Laure.Bourgois@logilab.fr>
parents:
626
diff
changeset
|
261 |
in sioc specification) with sioc views""" |
1553 | 262 |
|
993
c1ce4c3a7c8f
removing useless method for interfaces ISiocItem and ISiocContainer.
Laure Bourgois <Laure.Bourgois@logilab.fr>
parents:
990
diff
changeset
|
263 |
def isioc_content(self): |
990
5f1ff5b6907a
ISiocItem is an interface that is implemented by 'post' entities (in sioc specification) i.e blogentry, mail ...
Laure Bourgois <Laure.Bourgois@logilab.fr>
parents:
626
diff
changeset
|
264 |
"""return content entity""" |
5f1ff5b6907a
ISiocItem is an interface that is implemented by 'post' entities (in sioc specification) i.e blogentry, mail ...
Laure Bourgois <Laure.Bourgois@logilab.fr>
parents:
626
diff
changeset
|
265 |
|
993
c1ce4c3a7c8f
removing useless method for interfaces ISiocItem and ISiocContainer.
Laure Bourgois <Laure.Bourgois@logilab.fr>
parents:
990
diff
changeset
|
266 |
def isioc_container(self): |
1199
7fa66717175b
fixing isioc_type comment
Laure Bourgois <Laure.Bourgois@logilab.fr>
parents:
994
diff
changeset
|
267 |
"""return container entity""" |
7fa66717175b
fixing isioc_type comment
Laure Bourgois <Laure.Bourgois@logilab.fr>
parents:
994
diff
changeset
|
268 |
|
7fa66717175b
fixing isioc_type comment
Laure Bourgois <Laure.Bourgois@logilab.fr>
parents:
994
diff
changeset
|
269 |
def isioc_type(self): |
7fa66717175b
fixing isioc_type comment
Laure Bourgois <Laure.Bourgois@logilab.fr>
parents:
994
diff
changeset
|
270 |
"""return container type (post, BlogPost, MailMessage)""" |
7fa66717175b
fixing isioc_type comment
Laure Bourgois <Laure.Bourgois@logilab.fr>
parents:
994
diff
changeset
|
271 |
|
7fa66717175b
fixing isioc_type comment
Laure Bourgois <Laure.Bourgois@logilab.fr>
parents:
994
diff
changeset
|
272 |
def isioc_replies(self): |
1553 | 273 |
"""return replies items""" |
1199
7fa66717175b
fixing isioc_type comment
Laure Bourgois <Laure.Bourgois@logilab.fr>
parents:
994
diff
changeset
|
274 |
|
7fa66717175b
fixing isioc_type comment
Laure Bourgois <Laure.Bourgois@logilab.fr>
parents:
994
diff
changeset
|
275 |
def isioc_topics(self): |
7fa66717175b
fixing isioc_type comment
Laure Bourgois <Laure.Bourgois@logilab.fr>
parents:
994
diff
changeset
|
276 |
"""return topics items""" |
1553 | 277 |
|
990
5f1ff5b6907a
ISiocItem is an interface that is implemented by 'post' entities (in sioc specification) i.e blogentry, mail ...
Laure Bourgois <Laure.Bourgois@logilab.fr>
parents:
626
diff
changeset
|
278 |
class ISiocContainer(Interface): |
5f1ff5b6907a
ISiocItem is an interface that is implemented by 'post' entities (in sioc specification) i.e blogentry, mail ...
Laure Bourgois <Laure.Bourgois@logilab.fr>
parents:
626
diff
changeset
|
279 |
"""interface for entities (which are container |
5f1ff5b6907a
ISiocItem is an interface that is implemented by 'post' entities (in sioc specification) i.e blogentry, mail ...
Laure Bourgois <Laure.Bourgois@logilab.fr>
parents:
626
diff
changeset
|
280 |
in sioc specification) with sioc views""" |
5f1ff5b6907a
ISiocItem is an interface that is implemented by 'post' entities (in sioc specification) i.e blogentry, mail ...
Laure Bourgois <Laure.Bourgois@logilab.fr>
parents:
626
diff
changeset
|
281 |
|
993
c1ce4c3a7c8f
removing useless method for interfaces ISiocItem and ISiocContainer.
Laure Bourgois <Laure.Bourgois@logilab.fr>
parents:
990
diff
changeset
|
282 |
def isioc_type(self): |
1199
7fa66717175b
fixing isioc_type comment
Laure Bourgois <Laure.Bourgois@logilab.fr>
parents:
994
diff
changeset
|
283 |
"""return container type (forum, Weblog, MailingList)""" |
7fa66717175b
fixing isioc_type comment
Laure Bourgois <Laure.Bourgois@logilab.fr>
parents:
994
diff
changeset
|
284 |
|
7fa66717175b
fixing isioc_type comment
Laure Bourgois <Laure.Bourgois@logilab.fr>
parents:
994
diff
changeset
|
285 |
def isioc_items(self): |
7fa66717175b
fixing isioc_type comment
Laure Bourgois <Laure.Bourgois@logilab.fr>
parents:
994
diff
changeset
|
286 |
"""return contained items""" |