diff --git a/CHANGES.rst b/CHANGES.rst index 18c5732..20457dc 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -4,7 +4,7 @@ Changelog 1.1 (unreleased) ---------------- -- Nothing changed yet. +- Fixed use parent address if we set Contact Details behaviour on held positions. 1.0 (2013-09-13) diff --git a/src/collective/contact/core/behaviors.py b/src/collective/contact/core/behaviors.py index 0f5b55c..467a423 100644 --- a/src/collective/contact/core/behaviors.py +++ b/src/collective/contact/core/behaviors.py @@ -226,8 +226,20 @@ class IContactDetails(model.Schema): alsoProvides(IContactDetails, IFormFieldProvider) +def default_use_parent_address(adapter): + """We don't use parent address by default for contacts and level-0 organizations + """ + from collective.contact.core.content.directory import IDirectory + if adapter.view._parent.portal_type == 'person': + return False + if adapter.view._parent.portal_type == 'organization' \ + and IDirectory.providedBy(adapter.context): + return False + else: + return True + DefaultUseParentAddress = ComputedWidgetAttribute( - get_parent_address, + default_use_parent_address, field=IContactDetails['use_parent_address'], view=Interface) diff --git a/src/collective/contact/core/browser/contactable.py b/src/collective/contact/core/browser/contactable.py index 165f023..2c854f0 100644 --- a/src/collective/contact/core/browser/contactable.py +++ b/src/collective/contact/core/browser/contactable.py @@ -40,12 +40,13 @@ class Contactable(grok.Adapter): we use the one of the first object in this list which have this information """ contactables = [] - if self.person is not None: - contactables.append(self.person) - if self.position is not None: - contactables.append(self.position) - if self.organizations: - contactables.extend(reversed(self.organizations)) + related_items = [self.context, self.person, self.position] + list(reversed(self.organizations)) + for related_item in related_items: + if related_item is not None \ + and IContactDetails.providedBy(related_item) \ + and related_item not in contactables: + contactables.append(related_item) + return contactables def _get_address(self, contactables): @@ -70,6 +71,7 @@ class Contactable(grok.Adapter): break else: contact_details[field] = '' + contactables = self._get_contactables() contact_details['address'] = self._get_address(contactables) return contact_details diff --git a/src/collective/contact/core/browser/static/forms.js b/src/collective/contact/core/browser/static/forms.js index 072b49e..4781660 100644 --- a/src/collective/contact/core/browser/static/forms.js +++ b/src/collective/contact/core/browser/static/forms.js @@ -65,5 +65,5 @@ manage_hide_use_parent_address = function(){ $(document).ready(function(){ $(document).delegate('#formfield-form-widgets-gender input', 'change', update_person_title); manage_directory(); - manage_hide_use_parent_address(); + //manage_hide_use_parent_address(); });