12221.2.3
by Tim Penhey
Wire up the person formatter for the webservice, and have it in the registry/browser area. |
1 |
# Copyright 2011 Canonical Ltd. This software is licensed under the
|
2 |
# GNU Affero General Public License version 3 (see the file LICENSE).
|
|
3 |
||
4 |
"""Adapters for registry objects for the webservice."""
|
|
5 |
||
6 |
__metaclass__ = type |
|
7 |
__all__ = [] |
|
8 |
||
9 |
from lazr.restful.interfaces import ( |
|
10 |
IFieldHTMLRenderer, |
|
12221.9.18
by Tim Penhey
Configure the reference xhtml representation with the code again using updated lazr.restful. |
11 |
IReference, |
12221.2.3
by Tim Penhey
Wire up the person formatter for the webservice, and have it in the registry/browser area. |
12 |
IWebServiceClientRequest, |
13 |
)
|
|
14 |
from zope import component |
|
15 |
from zope.interface import ( |
|
16 |
implementer, |
|
17 |
Interface, |
|
18 |
)
|
|
12221.2.7
by Tim Penhey
Unify the text xhtml representations. |
19 |
from zope.schema.interfaces import IText |
12221.2.3
by Tim Penhey
Wire up the person formatter for the webservice, and have it in the registry/browser area. |
20 |
|
13405.9.1
by Henning Eggers
Restored r13373. |
21 |
from lp.app.browser.stringformatter import FormattersAPI |
12221.9.17
by Tim Penhey
Make the xhtml representation even more generic and move to app/browser. |
22 |
from lp.app.browser.tales import format_link |
23 |
||
24 |
||
12221.9.18
by Tim Penhey
Configure the reference xhtml representation with the code again using updated lazr.restful. |
25 |
@component.adapter(Interface, IReference, IWebServiceClientRequest) |
26 |
@implementer(IFieldHTMLRenderer) |
|
12221.9.17
by Tim Penhey
Make the xhtml representation even more generic and move to app/browser. |
27 |
def reference_xhtml_representation(context, field, request): |
28 |
"""Render an object as a link to the object."""
|
|
12221.2.3
by Tim Penhey
Wire up the person formatter for the webservice, and have it in the registry/browser area. |
29 |
|
30 |
def render(value): |
|
12221.9.31
by Tim Penhey
Text updates. |
31 |
# The value is a webservice link to the object, we want field value.
|
12221.9.17
by Tim Penhey
Make the xhtml representation even more generic and move to app/browser. |
32 |
obj = getattr(context, field.__name__, None) |
12397.1.1
by Ian Booth
Initial coding |
33 |
try: |
34 |
return format_link(obj, empty_value='') |
|
35 |
except NotImplementedError: |
|
36 |
return value |
|
12221.2.3
by Tim Penhey
Wire up the person formatter for the webservice, and have it in the registry/browser area. |
37 |
return render |
12221.2.7
by Tim Penhey
Unify the text xhtml representations. |
38 |
|
39 |
||
40 |
@component.adapter(Interface, IText, IWebServiceClientRequest) |
|
41 |
@implementer(IFieldHTMLRenderer) |
|
42 |
def text_xhtml_representation(context, field, request): |
|
43 |
"""Render text as XHTML using the webservice."""
|
|
13405.9.1
by Henning Eggers
Restored r13373. |
44 |
return lambda text: ( |
45 |
'' if text is None |
|
46 |
else FormattersAPI(text).text_to_html(linkify_text=True)) |