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