def get_contact_details(self, keys=(), fallback=True):
        if not IContactDetails.providedBy(self.context):
            raise TypeError(
                "Your contactable content must provide IContactDetails "
                "if it doesn't have a more specific contactable adapter")

        contact_details = {}
        if keys:
            contact_details_fields = [k for k in keys if k != 'address']
        else:
            contact_details_fields = CONTACT_DETAILS_FIELDS

        context = aq_base(self.context)
        for field in contact_details_fields:
            # search the object that carries the field
            value = getattr(context, field, '') or ''
            contact_details[field] = value

        if (not keys) or ('address' in keys):
            contact_details['address'] = get_address(context)

        if 'website' in contact_details:
            contact_details['website'] = get_valid_url(
                contact_details['website'])

        return contact_details
Esempio n. 2
0
def get_address_from_obj(obj):
    # Event
    loc = getattr(obj, 'location', '')
    if loc:
        return obj.location
    # old card
    if obj.portal_type == 'collective.directory.card':
        street = get_field(obj, 'address')
        zip_code = get_field(obj, 'zip_code')
        city = get_field(obj, 'city')
        address = '{0} {1} {2}'.format(
            street, zip_code, city
        )
        return address

    # collective.contact.core
    dict_address = get_address(obj)
    street = safe_utf8(dict_address.get('street'))
    number = safe_utf8(dict_address.get('number'))
    zip_code = safe_utf8(dict_address.get('zip_code'))
    city = safe_utf8(dict_address.get('city'))
    if street and city:
        address = '{0} {1} {2} {3}'.format(
            number, street, zip_code, city
        )
    else:
        return ''
    return address
    def _get_address(self, contactables):
        for obj in contactables:
            address = get_address(obj)
            if address:
                return address

        return {}
    def _get_address(self, contactables):
        for obj in contactables:
            address = get_address(obj)
            if address:
                return address

        return {}
    def get_contact_details(self, keys=(), fallback=True):
        if not IContactDetails.providedBy(self.context):
            raise TypeError("Your contactable content must provide IContactDetails "
                            "if it doesn't have a more specific contactable adapter")

        contact_details = {}
        if keys:
            contact_details_fields = [k for k in keys if k != 'address']
        else:
            contact_details_fields = CONTACT_DETAILS_FIELDS

        context = aq_base(self.context)
        for field in contact_details_fields:
            # search the object that carries the field
            value = getattr(context, field, '') or ''
            contact_details[field] = value

        if (not keys) or ('address' in keys):
            contact_details['address'] = get_address(context)

        if 'website' in contact_details:
            contact_details['website'] = get_valid_url(
                contact_details['website'])

        return contact_details
    def _get_address(self, contactables):
        for obj in contactables:
            obj = aq_base(obj)
            if obj.use_parent_address is True:
                continue
            else:
                address = get_address(obj)
                if address:
                    return address

        return {}
    def _get_address(self, contactables):
        for obj in contactables:
            obj = aq_base(obj)
            if obj.use_parent_address is True:
                continue
            else:
                address = get_address(obj)
                if address:
                    return address

        return {}
Esempio n. 8
0
 def __call__(self):
     value = self.get_value()
     if getattr(value, 'to_object', False):
         obj = value.to_object
         result = {
             'title': obj.title,
             'path': '/'.join(obj.getPhysicalPath()),
             'phone': obj.phone,
             'cell_phone': obj.cell_phone,
         }
         result.update(get_address(obj))
         return json_compatible(result)
     return json_compatible(value, self.context)
Esempio n. 9
0
 def __call__(self):
     value = self.get_value()
     if getattr(value, 'to_object', False):
         obj = value.to_object
         result = {
             'title': obj.title,
             'path': '/'.join(obj.getPhysicalPath()),
             'phone': obj.phone,
             'cell_phone': obj.cell_phone,
         }
         result.update(get_address(obj))
         return json_compatible(result)
     return json_compatible(value, self.context)
    def get_contact_details(self):
        if not IContactDetails.providedBy(self.context):
            raise TypeError("Your contactable content must provide IContactDetails "
                            "if it doesn't have a more specific contactable adapter")
        contact_details = {}
        contact_details_fields = ['email', 'phone', 'cell_phone', 'fax', 'website', 'im_handle']
        context = aq_base(self.context)
        for field in contact_details_fields:
            # search the object that carries the field
            value = getattr(context, field, '') or ''
            contact_details[field] = value

        contact_details['address'] = get_address(context)
        return contact_details
Esempio n. 11
0
    def getAllMessages(self):
        """ Check if an address field is empty """
        if IContactContent.providedBy(self.context):
            contacts = [self.context]
        elif IImioDmsOutgoingMail.providedBy(self.context):
            contacts = []
            for rv in (self.context.recipients or []):
                if not rv.isBroken() and rv.to_path:
                    contacts.append(self.context.restrictedTraverse(
                        rv.to_path))
        if not contacts:
            return []
        errors = []
        for contact in contacts:
            address = get_address(contact)
            empty_keys = []
            for key in (
                    'street',
                    'number',
                    'zip_code',
                    'city',
            ):
                if not address.get(key, ''):
                    empty_keys.append(
                        translate(key,
                                  domain='imio.dms.mail',
                                  context=self.request))
            if empty_keys:
                errors.append((contact, empty_keys))

        ret = []
        for (contact, keys) in errors:
            msg = translate(
                u"This contact '${title}' has missing address fields: ${keys}",
                domain='imio.dms.mail',
                context=self.request,
                mapping={
                    'title':
                    object_link(contact,
                                view='edit',
                                attribute='get_full_title'),
                    'keys':
                    ', '.join(keys)
                })
            ret.append(
                PseudoMessage(msg_type='significant',
                              text=richtextval(msg),
                              hidden_uid=generate_uid(),
                              can_hide=False))
        return ret
Esempio n. 12
0
    def get_field(self, field_name):
        if field_name in ['contact_email', 'contact_name', 'contact_phone']:
            sub = field_name.replace('contact_', '')
            field = getattr(aq_base(self.context), 'contact', '')
        else:
            field = getattr(aq_base(self.context), field_name, '')
        if not field:
            return ''
        if isinstance(field, RelationValue):
            if field.isBroken():
                return ''
            obj = field.to_object
            if field_name == 'location':
                address = get_address(obj)
                if not address:
                    return '{0}'.format(safe_utf8(obj.title))
                number = ''
                if address.get('number', None):
                    number = ', {0}'.format(address['number'])
                return '{0}<br />{1}{2}<br />{3} {4}'.format(
                    safe_utf8(obj.title),
                    safe_utf8(address.get('street') or ''), number,
                    address.get('zip_code') or '',
                    safe_utf8(address.get('city') or ''))
            else:
                if sub == 'name':
                    return getattr(obj, 'title', '')
                if sub == 'phone':
                    phones = getattr(obj, 'phone', '')
                    if not phones:
                        return ''
                    if not isinstance(phones, list):
                        phones = [phones]
                    return ', '.join([
                        format_phone(phone)['formated'] for phone in phones
                    ])  # noqa

                return getattr(obj, sub, '')
        else:
            return field
Esempio n. 13
0
    def get_field(self, field_name):
        if field_name in ['contact_email', 'contact_name', 'contact_phone']:
            sub = field_name.replace('contact_', '')
            field = getattr(aq_base(self.context), 'contact', '')
        else:
            field = getattr(aq_base(self.context), field_name, '')
        if not field:
            return ''
        if isinstance(field, RelationValue):
            if field.isBroken():
                return ''
            obj = field.to_object
            if field_name == 'location':
                address = get_address(obj)
                if not address:
                    return '{0}'.format(safe_utf8(obj.title))
                number = ''
                if address.get('number', None):
                    number = ', {0}'.format(address['number'])
                return '{0}<br />{1}{2}<br />{3} {4}'.format(
                    safe_utf8(obj.title),
                    safe_utf8(address.get('street') or ''),
                    number,
                    address.get('zip_code') or '',
                    safe_utf8(address.get('city') or '')
                )
            else:
                if sub == 'name':
                    return getattr(obj, 'title', '')
                if sub == 'phone':
                    phones = getattr(obj, 'phone', '')
                    if not phones:
                        return ''
                    if not isinstance(phones, list):
                        phones = [phones]
                    return ', '.join([format_phone(phone)['formated'] for phone in phones])  # noqa

                return getattr(obj, sub, '')
        else:
            return field
Esempio n. 14
0
def get_address_from_obj(obj):
    # Event
    loc = getattr(obj, 'location', '')
    if loc:
        return obj.location
    # old card
    if obj.portal_type == 'collective.directory.card':
        street = get_field(obj, 'address')
        zip_code = get_field(obj, 'zip_code')
        city = get_field(obj, 'city')
        address = '{0} {1} {2}'.format(street, zip_code, city)
        return address

    # collective.contact.core
    dict_address = get_address(obj)
    street = safe_utf8(dict_address.get('street'))
    number = safe_utf8(dict_address.get('number'))
    zip_code = safe_utf8(dict_address.get('zip_code'))
    city = safe_utf8(dict_address.get('city'))
    if street and city:
        address = '{0} {1} {2} {3}'.format(number, street, zip_code, city)
    else:
        return ''
    return address
Esempio n. 15
0
 def city(self):
     dict_address = get_address(self.context)
     city = dict_address.get('city')
     return city
Esempio n. 16
0
 def data_geojson(self):
     style = {}
     global_style = utils.get_feature_styles(self.context)
     style["fill"] = global_style["polygoncolor"]
     style["stroke"] = global_style["linecolor"]
     style["width"] = global_style["linewidth"]
     if global_style.get("marker_image", None):
         img = get_marker_image(self.context, global_style["marker_image"])
         style["image"] = img
     else:
         style["image"] = None
     json_result = []
     self.pc = api.portal.get_tool("portal_catalog")
     for contact in self.get_contacts():
         brain = self.pc.unrestrictedSearchResults(UID=contact.UID())[0]
         if contact.use_parent_address:
             brain = self.pc.unrestrictedSearchResults(UID=contact.aq_parent.UID())[
                 0
             ]
         if brain.zgeo_geometry == Missing.Value:
             continue
         if brain.collective_geo_styles == Missing.Value:
             continue
         if brain.collective_geo_styles.get(
             "use_custom_styles", False
         ) and brain.collective_geo_styles.get("marker_image", None):
             img = get_marker_image(
                 self.context, brain.collective_geo_styles["marker_image"]
             )
             style["image"] = img
         geom = {
             "type": brain.zgeo_geometry["type"],
             "coordinates": brain.zgeo_geometry["coordinates"],
         }
         if geom["coordinates"]:
             if geom["type"]:
                 classes = geom["type"].lower() + " "
             else:
                 classes = ""
             address = get_address(contact)
             number = ""
             if address.get("number", None):
                 number = ", {0}".format(address["number"])
             formated_address = "{0}{1}<br />{2} {3}".format(
                 safe_utf8(address.get("street") or ""),
                 number,
                 address.get("zip_code") or "",
                 safe_utf8(address.get("city") or ""),
             )
             img = ""
             if self.context.see_logo_in_popup:
                 acc = getattr(contact, "logo", None)
                 if acc and acc.filename:
                     img = "{0}/@@images/logo/thumb".format(contact.absolute_url())
             classes += brain.getPath().split("/")[-2].replace(".", "-")
             json_result.append(
                 geojson.Feature(
                     id=contact.id.replace(".", "-"),
                     geometry=as_shape(geom),
                     style=style,
                     properties={
                         "title": brain.Title,
                         "description": brain.Description,
                         "style": style,
                         "url": brain.getURL(),
                         "classes": classes,
                         "image": img,
                         "address": formated_address,
                     },
                 )
             )
     feature_collection = geojson.FeatureCollection(json_result)
     feature_collection.update({"title": self.context.title})
     return geojson.dumps(feature_collection)
Esempio n. 17
0
 def city(self):
     dict_address = get_address(self.context)
     city = dict_address.get('city')
     return city
Esempio n. 18
0
 def address(self):
     dict_address = get_address(self.context)
     template_path = 'address.pt'
     template = ViewPageTemplateFile(template_path)
     return template(self, dict_address)
Esempio n. 19
0
 def address(self):
     dict_address = get_address(self.context)
     template_path = 'address.pt'
     template = ViewPageTemplateFile(template_path)
     return template(self, dict_address)
Esempio n. 20
0
 def data_geojson(self):
     style = {}
     global_style = utils.get_feature_styles(self.context)
     style['fill'] = global_style['polygoncolor']
     style['stroke'] = global_style['linecolor']
     style['width'] = global_style['linewidth']
     if global_style.get('marker_image', None):
         img = get_marker_image(self.context, global_style['marker_image'])
         style['image'] = img
     else:
         style['image'] = None
     json_result = []
     self.pc = api.portal.get_tool('portal_catalog')
     for contact in self.get_contacts():
         brain = self.pc.unrestrictedSearchResults(UID=contact.UID())[0]
         if contact.use_parent_address:
             brain = self.pc.unrestrictedSearchResults(
                 UID=contact.aq_parent.UID())[0]
         if brain.zgeo_geometry == Missing.Value:
             continue
         if brain.collective_geo_styles == Missing.Value:
             continue
         if brain.collective_geo_styles.get('use_custom_styles', False) and \
                brain.collective_geo_styles.get('marker_image', None):
             img = get_marker_image(self.context, brain.collective_geo_styles['marker_image'])
             style['image'] = img
         geom = {'type': brain.zgeo_geometry['type'],
                 'coordinates': brain.zgeo_geometry['coordinates']}
         if geom['coordinates']:
             if geom['type']:
                 classes = geom['type'].lower() + ' '
             else:
                 classes = ''
             address = get_address(contact)
             number = ''
             if address.get('number', None):
                 number = ', {0}'.format(address['number'])
             formated_address = '{0}{1}<br />{2} {3}'.format(
                 safe_utf8(address.get('street') or ''),
                 number,
                 address.get('zip_code') or '',
                 safe_utf8(address.get('city') or '')
             )
             img = ''
             if self.context.see_logo_in_popup:
                 acc = getattr(contact, 'logo', None)
                 if acc and acc.filename:
                     img = '{0}/@@images/logo/thumb'.format(
                         contact.absolute_url()
                     )
             classes += brain.getPath().split('/')[-2].replace('.', '-')
             json_result.append(
                 geojson.Feature(
                     id=contact.id.replace('.', '-'),
                     geometry=as_shape(geom),
                     style=style,
                     properties={
                         'title': brain.Title,
                         'description': brain.Description,
                         'style': style,
                         'url': brain.getURL(),
                         'classes': classes,
                         'image': img,
                         'address': formated_address
                     }))
     feature_collection = geojson.FeatureCollection(json_result)
     feature_collection.update({'title': self.context.title})
     return geojson.dumps(feature_collection)