Commit f3ad409e authored by Sylvain Thénault's avatar Sylvain Thénault
Browse files

[ui] Refactor business views for easier overriding

By clearling separating value retrieval / text generation from its injection in
the HTML layout, things are clearer and easier to override.
parent ba471bdc74b5
......@@ -149,16 +149,11 @@ class TitleBusinessValueEntityView(BusinessValueLinkEntityView):
element.
"""
__select__ = BusinessValueLinkEntityView.__select__ & is_instance('SEDAContent')
no_value_msg = _('<no title specified>')
def entity_call(self, entity):
def entity_value(self, entity):
seda_title = entity.related('seda_title', role='object').one()
title = seda_title.printable_value('title') or None
if title:
self.w(u'<span class="value">')
self.wvalue(entity, title)
self.w(u'</span>')
else:
self.wvalue(entity, self._cw._('<no title specified>'))
return seda_title.printable_value('title') or None
class ArchiveUnitManagementTab(tabs.PrimaryTab):
......
......@@ -22,6 +22,8 @@ from cubicweb.web.views import tabs
from cubes.seda.views import add_subobjects_button
_ = unicode
class XSDMetaEntityView(EntityView):
__regid__ = 'seda.xsdmeta'
......@@ -101,29 +103,34 @@ class BusinessValueEntityView(EntityView):
entity's class
"""
__regid__ = 'seda.business'
no_value_msg = _('<no value specified>')
def entity_call(self, entity):
if entity.value_attr:
value = entity.printable_value(entity.value_attr)
else:
value = None
value = self.entity_value(entity)
if value:
self.w(u'<span class="value">')
self.wvalue(entity, value)
self.w(value)
self.w(u'</span>')
else:
self.wdata(self._cw._('<no value specified>'))
self.wdata(self._cw._(self.no_value_msg))
def wvalue(self, entity, value):
self.w(value)
def entity_value(self, entity):
if entity.value_attr:
value = entity.printable_value(entity.value_attr)
else:
value = None
return value
class BusinessValueLinkEntityView(BusinessValueEntityView):
"""Similar to seda.business but value is enclosed in a link if specified"""
__regid__ = 'seda.business.link'
def wvalue(self, entity, value):
self.w(tags.a(value, href=entity.absolute_url()))
def entity_value(self, entity):
value = super(BusinessValueLinkEntityView, self).entity_value(entity)
if value:
value = tags.a(value, href=entity.absolute_url())
return value
class LinkMetaEntityView(EntityView):
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment