author | sylvain.thenault@logilab.fr |
Tue, 07 Apr 2009 19:54:10 +0200 | |
branch | tls-sprint |
changeset 1275 | 441201a5c13f |
parent 1263 | 01152fffd593 |
child 1553 | 3f91ef2397d0 |
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""" |
|
14 |
||
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. |
|
31 |
|
|
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 |
""" |
|
48 |
||
49 |
def can_pass_transition(self, trname): |
|
50 |
"""return true if the current user can pass the transition with the |
|
51 |
given name |
|
52 |
""" |
|
53 |
||
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""" |
|
76 |
||
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""" |
|
96 |
||
97 |
||
98 |
class IMileStone(IProgress): |
|
99 |
"""represents an ITask's item""" |
|
100 |
||
101 |
parent_type = None # specify main task's type |
|
102 |
||
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""" |
|
108 |
||
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""" |
|
131 |
||
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 |
""" |
|
149 |
||
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""" |
|
158 |
||
159 |
def breadcrumbs(self, view, recurs=False): |
|
160 |
"""return a list containing some: |
|
161 |
|
|
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""" |
|
176 |
||
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""" |
|
191 |
||
192 |
def embeded_url(self): |
|
193 |
"""embed action interface""" |
|
194 |
||
195 |
class ICalendarable(Interface): |
|
767 | 196 |
"""interface for items that do have a begin date 'start' and an end date 'stop' |
197 |
""" |
|
0 | 198 |
|
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`) |
|
205 |
|
|
206 |
:return: |
|
207 |
a list of dates (`DateTime`) in the range [`begin`, `end`] on which |
|
208 |
this entity apply |
|
209 |
""" |
|
210 |
||
211 |
class ITimetableViews(Interface): |
|
212 |
"""timetable views interface""" |
|
213 |
def timetable_date(self): |
|
214 |
"""XXX explain |
|
215 |
|
|
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 |
""" |
|
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""" |
979dbe0cade3
views with rss feed
Laure Bourgois <Laure.Bourgois@logilab.fr>
parents:
0
diff
changeset
|
237 |
|
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 |
""" |
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
|
241 |
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
|
242 |
"""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
|
243 |
in sioc specification) with sioc views""" |
993
c1ce4c3a7c8f
removing useless method for interfaces ISiocItem and ISiocContainer.
Laure Bourgois <Laure.Bourgois@logilab.fr>
parents:
990
diff
changeset
|
244 |
|
c1ce4c3a7c8f
removing useless method for interfaces ISiocItem and ISiocContainer.
Laure Bourgois <Laure.Bourgois@logilab.fr>
parents:
990
diff
changeset
|
245 |
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
|
246 |
"""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
|
247 |
|
993
c1ce4c3a7c8f
removing useless method for interfaces ISiocItem and ISiocContainer.
Laure Bourgois <Laure.Bourgois@logilab.fr>
parents:
990
diff
changeset
|
248 |
def isioc_container(self): |
1199
7fa66717175b
fixing isioc_type comment
Laure Bourgois <Laure.Bourgois@logilab.fr>
parents:
994
diff
changeset
|
249 |
"""return container entity""" |
7fa66717175b
fixing isioc_type comment
Laure Bourgois <Laure.Bourgois@logilab.fr>
parents:
994
diff
changeset
|
250 |
|
7fa66717175b
fixing isioc_type comment
Laure Bourgois <Laure.Bourgois@logilab.fr>
parents:
994
diff
changeset
|
251 |
def isioc_type(self): |
7fa66717175b
fixing isioc_type comment
Laure Bourgois <Laure.Bourgois@logilab.fr>
parents:
994
diff
changeset
|
252 |
"""return container type (post, BlogPost, MailMessage)""" |
7fa66717175b
fixing isioc_type comment
Laure Bourgois <Laure.Bourgois@logilab.fr>
parents:
994
diff
changeset
|
253 |
|
7fa66717175b
fixing isioc_type comment
Laure Bourgois <Laure.Bourgois@logilab.fr>
parents:
994
diff
changeset
|
254 |
def isioc_replies(self): |
7fa66717175b
fixing isioc_type comment
Laure Bourgois <Laure.Bourgois@logilab.fr>
parents:
994
diff
changeset
|
255 |
"""return replies items""" |
7fa66717175b
fixing isioc_type comment
Laure Bourgois <Laure.Bourgois@logilab.fr>
parents:
994
diff
changeset
|
256 |
|
7fa66717175b
fixing isioc_type comment
Laure Bourgois <Laure.Bourgois@logilab.fr>
parents:
994
diff
changeset
|
257 |
def isioc_topics(self): |
7fa66717175b
fixing isioc_type comment
Laure Bourgois <Laure.Bourgois@logilab.fr>
parents:
994
diff
changeset
|
258 |
"""return topics items""" |
994
98f19cf755a1
removing useless method (bis)
Laure Bourgois <Laure.Bourgois@logilab.fr>
parents:
993
diff
changeset
|
259 |
|
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
|
260 |
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
|
261 |
"""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
|
262 |
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
|
263 |
|
993
c1ce4c3a7c8f
removing useless method for interfaces ISiocItem and ISiocContainer.
Laure Bourgois <Laure.Bourgois@logilab.fr>
parents:
990
diff
changeset
|
264 |
def isioc_type(self): |
1199
7fa66717175b
fixing isioc_type comment
Laure Bourgois <Laure.Bourgois@logilab.fr>
parents:
994
diff
changeset
|
265 |
"""return container type (forum, Weblog, MailingList)""" |
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_items(self): |
7fa66717175b
fixing isioc_type comment
Laure Bourgois <Laure.Bourgois@logilab.fr>
parents:
994
diff
changeset
|
268 |
"""return contained items""" |
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 |
|
993
c1ce4c3a7c8f
removing useless method for interfaces ISiocItem and ISiocContainer.
Laure Bourgois <Laure.Bourgois@logilab.fr>
parents:
990
diff
changeset
|
271 |