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