Fixed use parent address if we set Contact Details behaviour on held

positions.
This commit is contained in:
Thomas Desvenain 2013-09-13 12:24:39 +02:00
parent cfcf124ada
commit 08289706a9
4 changed files with 23 additions and 9 deletions

View File

@ -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)

View File

@ -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)

View File

@ -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

View File

@ -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();
});