Skip to content

Commit

Permalink
Related contact below contents title is now a link to related contact.
Browse files Browse the repository at this point in the history
  • Loading branch information
bsuttor committed Aug 3, 2016
1 parent b5b6ffc commit fe2d66a
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 5 deletions.
3 changes: 2 additions & 1 deletion CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ Changelog
0.7.35 (unreleased)
-------------------

- Nothing changed yet.
- Related contact below contents title is now a link to related contact.
[bsuttor]


0.7.34 (2016-08-03)
Expand Down
11 changes: 11 additions & 0 deletions cpskin/core/tests/test_viewlets.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,11 @@ def test_above_related_contacts_viewlet(self):
event.aboveVisbileFields = ('firstname',)
self.assertIn('Foo', above_viewlet.render())

# test get_title method
self.assertFalse(above_viewlet.get_title(person))
event.aboveVisbileFields = ('title')
self.assertEqual(above_viewlet.get_title(person), u'<h4>Foo Bar</h4>')

def test_below_related_contacts_viewlet(self):
add_behavior(
'Event', 'cpskin.core.behaviors.metadata.IRelatedContacts')
Expand Down Expand Up @@ -247,6 +252,12 @@ def test_below_related_contacts_viewlet(self):
self.assertNotIn('5190', below_viewlet.render())
self.assertNotIn('Foo', below_viewlet.render())

# test get_title method
self.assertFalse(below_viewlet.get_title(person))
event.belowVisbileFields = ('title')
self.assertEqual(below_viewlet.get_title(person),
u'<a href="http://nohost/plone/directory/person" target="_blank"><h4>Foo Bar</h4></a>')

def test_use_parent_address(self):
add_behavior(
'Event', 'cpskin.core.behaviors.metadata.IRelatedContacts')
Expand Down
3 changes: 2 additions & 1 deletion cpskin/core/viewlets/related_contacts.pt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
<ul tal:attributes="id string:ul-${view/field}">
<li tal:repeat="contact view/get_contacts" class="related-contact">

<h4 tal:condition="python: view.in_fields('title')" tal:content="contact/title" />

<h4 tal:define="title python: view.get_title(contact)" tal:condition="title" tal:replace="structure title" />
<div class="coordinates"
tal:define="street python: view.get_field(contact, 'street');
number python: view.get_field(contact, 'number');
Expand Down
17 changes: 14 additions & 3 deletions cpskin/core/viewlets/related_contacts.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@ def get_contacts(self):
contacts.append(related_contact.to_object)
return contacts

def get_title(self, contact):
if self.in_fields('title'):
return u'<h4>{0}</h4>'.format(contact.title)
else:
return False

def in_fields(self, field):
return field in self.selected_fields

Expand Down Expand Up @@ -62,9 +68,6 @@ def fields_without_address(self):
fields.append(selected_field)
return fields

def use_parent_address(self):
pass


class AboveRelatedContactsViewlet(RelatedContactsViewlet):

Expand All @@ -76,3 +79,11 @@ class BelowRelatedContactsViewlet(RelatedContactsViewlet):

field = 'belowContentContact'
selected = 'belowVisbileFields'

def get_title(self, contact):
if self.in_fields('title'):
return u'<a href="{0}" target="_blank"><h4>{1}</h4></a>'.format(
contact.absolute_url(),
contact.title)
else:
return False

0 comments on commit fe2d66a

Please sign in to comment.