5 :contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr |
5 :contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr |
6 """ |
6 """ |
7 __docformat__ = "restructuredtext en" |
7 __docformat__ = "restructuredtext en" |
8 |
8 |
9 from urlparse import urlsplit, urlunsplit |
9 from urlparse import urlsplit, urlunsplit |
10 from mx.DateTime import now |
10 from datetime import datetime |
11 |
11 |
12 from logilab.common.decorators import cached |
12 from logilab.common.decorators import cached |
13 |
13 |
14 from cubicweb.common.entity import _marker |
14 from cubicweb import UnknownProperty |
|
15 from cubicweb.entity import _marker |
15 from cubicweb.entities import AnyEntity, fetch_config |
16 from cubicweb.entities import AnyEntity, fetch_config |
16 |
17 |
17 def mangle_email(address): |
18 def mangle_email(address): |
18 try: |
19 try: |
19 name, host = address.split('@', 1) |
20 name, host = address.split('@', 1) |
23 |
24 |
24 class EmailAddress(AnyEntity): |
25 class EmailAddress(AnyEntity): |
25 id = 'EmailAddress' |
26 id = 'EmailAddress' |
26 fetch_attrs, fetch_order = fetch_config(['address', 'alias', 'canonical']) |
27 fetch_attrs, fetch_order = fetch_config(['address', 'alias', 'canonical']) |
27 |
28 |
28 widgets = { |
|
29 'address' : "EmailWidget", |
|
30 } |
|
31 |
|
32 def dc_title(self): |
29 def dc_title(self): |
33 if self.alias: |
30 if self.alias: |
34 return '%s <%s>' % (self.alias, self.display_address()) |
31 return '%s <%s>' % (self.alias, self.display_address()) |
35 return self.display_address() |
32 return self.display_address() |
36 |
33 |
37 @property |
34 @property |
38 def email_of(self): |
35 def email_of(self): |
39 return self.reverse_use_email and self.reverse_use_email[0] |
36 return self.reverse_use_email and self.reverse_use_email[0] |
40 |
37 |
41 @cached |
38 @cached |
42 def canonical_form(self): |
39 def canonical_form(self): |
43 if self.canonical: |
40 if self.canonical: |
44 return self |
41 return self |
45 rql = 'EmailAddress X WHERE X identical_to Y, X canonical TRUE, Y eid %(y)s' |
42 rql = 'EmailAddress X WHERE X identical_to Y, X canonical TRUE, Y eid %(y)s' |
89 from logilab.common.deprecation import class_renamed |
86 from logilab.common.deprecation import class_renamed |
90 Emailaddress = class_renamed('Emailaddress', EmailAddress) |
87 Emailaddress = class_renamed('Emailaddress', EmailAddress) |
91 Emailaddress.id = 'Emailaddress' |
88 Emailaddress.id = 'Emailaddress' |
92 |
89 |
93 |
90 |
94 class EProperty(AnyEntity): |
91 class CWProperty(AnyEntity): |
95 id = 'EProperty' |
92 id = 'CWProperty' |
96 |
93 |
97 fetch_attrs, fetch_order = fetch_config(['pkey', 'value']) |
94 fetch_attrs, fetch_order = fetch_config(['pkey', 'value']) |
98 |
|
99 widgets = { |
|
100 'pkey' : "PropertyKeyWidget", |
|
101 'value' : "PropertyValueWidget", |
|
102 } |
|
103 |
|
104 rest_attr = 'pkey' |
95 rest_attr = 'pkey' |
105 |
96 |
106 def typed_value(self): |
97 def typed_value(self): |
107 return self.vreg.typed_value(self.pkey, self.value) |
98 return self.vreg.typed_value(self.pkey, self.value) |
108 |
99 |
109 def dc_description(self): |
100 def dc_description(self, format='text/plain'): |
110 return self.req._(self.vreg.property_info(self.pkey)['help']) |
101 try: |
|
102 return self.req._(self.vreg.property_info(self.pkey)['help']) |
|
103 except UnknownProperty: |
|
104 return u'' |
111 |
105 |
112 def after_deletion_path(self): |
106 def after_deletion_path(self): |
113 """return (path, parameters) which should be used as redirect |
107 """return (path, parameters) which should be used as redirect |
114 information when this entity is being deleted |
108 information when this entity is being deleted |
115 """ |
109 """ |
116 return 'view', {} |
110 return 'view', {} |
117 |
111 |
118 |
112 |
119 class Bookmark(AnyEntity): |
113 class Bookmark(AnyEntity): |
120 """customized class for Bookmark entities""" |
114 """customized class for Bookmark entities""" |
121 id = 'Bookmark' |
115 id = 'Bookmark' |
122 fetch_attrs, fetch_order = fetch_config(['title', 'path']) |
116 fetch_attrs, fetch_order = fetch_config(['title', 'path']) |
123 widgets = { |
|
124 'path' : "StringWidget", |
|
125 } |
|
126 __rtags__ = {'path': 'primary'} |
|
127 |
117 |
128 def actual_url(self): |
118 def actual_url(self): |
129 url = self.req.build_url(self.path) |
119 url = self.req.build_url(self.path) |
130 if self.title: |
120 if self.title: |
131 urlparts = list(urlsplit(url)) |
121 urlparts = list(urlsplit(url)) |
137 return url |
127 return url |
138 |
128 |
139 def action_url(self): |
129 def action_url(self): |
140 return self.absolute_url() + '/follow' |
130 return self.absolute_url() + '/follow' |
141 |
131 |
142 class ECache(AnyEntity): |
132 |
|
133 class CWCache(AnyEntity): |
143 """Cache""" |
134 """Cache""" |
144 id = 'ECache' |
135 id = 'CWCache' |
145 |
|
146 fetch_attrs, fetch_order = fetch_config(['name']) |
136 fetch_attrs, fetch_order = fetch_config(['name']) |
147 |
137 |
148 def touch(self): |
138 def touch(self): |
149 self.req.execute('SET X timestamp %(t)s WHERE X eid %(x)s', {'t': now(), 'x': self.eid}, 'x') |
139 self.req.execute('SET X timestamp %(t)s WHERE X eid %(x)s', |
|
140 {'t': datetime.now(), 'x': self.eid}, 'x') |
150 |
141 |
151 def valid(self, date): |
142 def valid(self, date): |
152 return date < self.timestamp |
143 return date < self.timestamp |