Commit fc1aeb7e authored by Rémi Cardona's avatar Rémi Cardona
Browse files

[views] Drop the custom table view for phone/address/… attributes

Let's use uicfg to put relations inside the attribute table instead of
hand rolling <table> tags. Closes #5199316.
parent fbf51ad4986a
......@@ -15,15 +15,22 @@ from cubicweb.web.views import baseviews, primary, uicfg, vcard
from cubicweb.web.facet import AttributeFacet
_pvs =uicfg.primaryview_section
_pvdc = uicfg.primaryview_display_ctrl
for attr in ('civility', 'firstname', 'surname'):
_pvs.tag_attribute(('Person', attr), 'hidden')
for rtype in ('use_email', 'primary_email',
'phone', 'im_address', 'postal_address'):
_pvs.tag_subject_of(('Person', rtype, '*'), 'hidden')
_pvdc.tag_attribute(('Person', 'description'), {'showlabel': False,
'order': 0})
for rtype in ('phone', 'use_email',
'im_address', 'postal_address'):
_pvs.tag_subject_of(('Person', rtype, '*'), 'attributes')
_pvs.tag_subject_of(('Person', 'primary_email', '*'), 'hidden')
_pvdc = uicfg.primaryview_display_ctrl
_pvdc.tag_attribute(('Person', 'description'),
{'showlabel': False, 'order': 0})
_pvdc.tag_attribute(('Person', 'phone'), {'order': 1, 'vid': 'csv'})
_pvdc.tag_attribute(('Person', 'use_email'),
{'order': 2, 'vid': 'csv', 'label': 'use_email'})
_pvdc.tag_attribute(('Person', 'im_address'), {'order': 3, 'vid': 'csv'})
_pvdc.tag_attribute(('Person', 'postal_address'),
{'order': 4, 'vid': 'person.hrs'})
_afs = uicfg.autoform_section
_afs.tag_subject_of(('Person', 'phone', '*'), 'main', 'inlined')
......@@ -31,30 +38,17 @@ _afs.tag_subject_of(('Person', 'postal_address', '*'), 'main', 'inlined')
_afs.tag_subject_of(('Person', 'im_address', '*'), 'main', 'inlined')
class HRSView(baseviews.CSVView):
__regid__ = 'person.hrs'
separator = u'<hr/>'
class PersonPrimaryView(primary.PrimaryView):
__select__ = is_instance('Person')
attr_table_relations = [('phone', ', '.join),
('use_email', ', '.join),
('im_address', ', '.join),
('postal_address', '<hr/>\n'.join),
]
def render_entity_title(self, entity):
self.w(u'<h1>%s</h1>' % xml_escape(entity.name(civility=True)))
def render_entity_attributes(self, entity):
super(PersonPrimaryView, self).render_entity_attributes(entity)
hascontent = False
for rel, join in self.attr_table_relations:
related = getattr(entity, rel, None)
if related:
if not hascontent:
self.w(u"<table>")
hascontent = True
self.field(rel, join(e.view('incontext') for e in related), table=True)
if hascontent:
self.w(u"</table>")
class PersonTextView(baseviews.TextView):
__select__ = is_instance('Person')
......
Markdown is supported
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