def render_collection_entry(self, obj, value):
     rel_obj = value and value.to_object
     if not rel_obj:
         return u""
     if IHeldPosition.providedBy(rel_obj):
         return rel_obj.get_full_title() or u""
     else:
         return rel_obj.Title()
 def render_collection_entry(self, obj, value):
     rel_obj = value and value.to_object
     if not rel_obj:
         return u""
     if IHeldPosition.providedBy(rel_obj):
         return rel_obj.get_full_title() or u""
     else:
         return rel_obj.Title()
Beispiel #3
0
 def get_full_title(self, contact, **kwargs):
     if IPerson.providedBy(contact):
         return contact.get_title()
     elif IOrganization.providedBy(contact):
         return contact.get_full_title(**kwargs)
     elif IHeldPosition.providedBy(contact):
         return contact.get_full_title()
     else:
         return ''
Beispiel #4
0
 def get_separate_titles(self, contact, **kwargs):
     """ Return a list with separate title for organization and person """
     ret = [u'', u'']  # org, pers
     if IPerson.providedBy(contact):
         ret[1] = contact.get_title()
     elif IOrganization.providedBy(contact):
         ret[0] = contact.get_full_title(**kwargs)  # separator=u' / ', first_index=0
     elif IHeldPosition.providedBy(contact):
         ret[1] = contact.get_person_title()
         org = contact.get_organization()
         if org:
             ret[0] = org.get_full_title(**kwargs)
     return ret
    def update(self):
        self.contents = self.get_contents()
        first = self.contents[0]['obj']
        self.portal_type = first.portal_type
        self.fieldsets = get_fieldsets(self.portal_type)
        # check if this is contacts from different persons,
        # then we can also merge the persons
        self.merge_hp_persons = False
        if IHeldPosition.providedBy(first):
            person_uids = []
            for hp in self.contents:
                if hp['uid'] != 'TEMP':
                    person_uids.append(IUUID(hp['obj'].get_person()))

            if len(set(person_uids)) > 1:
                self.merge_hp_persons = True
                self.merge_person_url = "%s/merge-contacts?%s" % (
                    self.context.absolute_url(),
                    '&'.join(['uids:list=%s' % uid for uid in person_uids]))
Beispiel #6
0
 def get_separate_contacts(self, contact, **kwargs):
     """ Return a list with separate organization and person """
     ret = {'pers': None, 'org': None, 'root': None, 'chain': None, 'levels': False}
     if IPerson.providedBy(contact):
         ret['pers'] = contact
     elif IOrganization.providedBy(contact):
         ret['org'] = contact
     elif IHeldPosition.providedBy(contact):
         if contact.label:
             ret['label'] = contact.label
         ret['pers'] = contact.get_person()
         org = contact.get_organization()
         if org:
             ret['org'] = org
     if ret['org']:
         ret['chain'] = ret['org'].get_organizations_chain()
         ret['root'] = ret['chain'][0]
         ret['levels'] = len(ret['chain']) > 1 and True
     return ret
Beispiel #7
0
    def person_title(self, contact, pers_dft=u'Monsieur', org_dft=u'Madame, Monsieur', with_name=False,
                     upper_name=False):

        def pers_title(pers):
            title = contact.person_title
            if not title:
                title = pers_dft
            if with_name and pers.lastname:
                return u'{} {}'.format(title, upper_name and pers.lastname.upper() or pers.lastname)
            else:
                return title

        if IPerson.providedBy(contact):
            return pers_title(contact)
        elif IOrganization.providedBy(contact):
            return org_dft
        elif IHeldPosition.providedBy(contact):
            return pers_title(contact.get_person())
        else:
            return u''
    def handleSave(self, action):
        statusmessages = IStatusMessage(self.request)

        PostOnly(self.request)
        data, errors = self.extractData()
        if errors:
            statusmessages.add(_(u"status_parse_error",
                                 default="Failed to parse the Form."),
                               type="error")
            return False

        portal_transforms = api.portal.get_tool(name='portal_transforms')
        transformed = portal_transforms.convertTo(
            'text/html',
            data['text'],
            mimetype='text/restructured',
        )

        portal = api.portal.get()
        vars = {
            'subject': data['subject'],
            'body': transformed.getData(),
            'site_url': portal.absolute_url(),
            'site_title': portal.Title(),
        }

        html = Composer().render_template(
            data["template"],
            {},
            vars,
        )

        portal = api.portal.get()
        sender_mail = formataddr((
            portal.email_from_name,
            portal.email_from_address,
        ))

        mailSVocab = MailSenderVocabulary(self.context)
        msg = create_email_body(
            html,
            headers={"Reply-To": mailSVocab.getTerm(data['reply_to']).title})

        if not self.uids:
            self.uids = data['uids_input'].split(',')

        mailcount = 0
        failed = []
        for uid in self.uids:
            obj = api.content.get(UID=uid)

            if obj:
                if IHeldPosition.providedBy(obj):
                    obj = IHeldPosition(obj).get_person()

                recipient = IRecipientProvider(obj)()
                if recipient is None:
                    failed.append(safe_unicode(obj.Title()))
                    continue

                api.portal.send_email(recipient=recipient,
                                      sender=sender_mail,
                                      subject=data['subject'],
                                      body=msg)
                mailcount += 1

        statusmessages.add(_(u"status_mail_send",
                             default="Sent ${number} E-Mails.",
                             mapping={"number": mailcount}),
                           type="info")

        if failed:
            statusmessages.add(_(
                u"status_mails_failed",
                default="${num} contacts without email-address: ${names}",
                mapping={
                    'num': len(failed),
                    'names': u','.join(failed)
                }),
                               type="warning")

        self.request.response.redirect(self.context.absolute_url())
Beispiel #9
0
 def get_held_positions(self):
     return [obj for obj in self.values() if IHeldPosition.providedBy(obj)]
    def handleSave(self, action):
        statusmessages = IStatusMessage(self.request)

        PostOnly(self.request)
        data, errors = self.extractData()
        if errors:
            statusmessages.add(
                _(u"status_parse_error", default="Failed to parse the Form."),
                type="error"
            )
            return False

        portal_transforms = api.portal.get_tool(name='portal_transforms')
        transformed = portal_transforms.convertTo(
            'text/html',
            data['text'],
            mimetype='text/restructured',
        )

        portal = api.portal.get()
        vars = {
            'subject': data['subject'],
            'body': transformed.getData(),
            'site_url': portal.absolute_url(),
            'site_title': portal.Title(),
        }

        html = Composer().render_template(
            data["template"],
            {},
            vars,
        )

        portal = api.portal.get()
        sender_mail = formataddr((
            portal.email_from_name,
            portal.email_from_address,
        ))

        mailSVocab = MailSenderVocabulary(self.context)
        msg = create_email_body(html, headers={"Reply-To": mailSVocab.getTerm(data['reply_to']).title})

        if not self.uids:
            self.uids = data['uids_input'].split(',')

        mailcount = 0
        failed = []
        for uid in self.uids:
            obj = api.content.get(UID=uid)

            if obj:
                if IHeldPosition.providedBy(obj):
                    obj = IHeldPosition(obj).get_person()

                recipient = IRecipientProvider(obj)()
                if recipient is None:
                    failed.append(safe_unicode(obj.Title()))
                    continue

                api.portal.send_email(
                    recipient=recipient,
                    sender=sender_mail,
                    subject=data['subject'],
                    body=msg
                )
                mailcount += 1

        statusmessages.add(
            _(u"status_mail_send",
                default="Sent ${number} E-Mails.",
                mapping={"number": mailcount}),
            type="info"
        )

        if failed:
            statusmessages.add(
                _(u"status_mails_failed",
                    default="${num} contacts without email-address: ${names}",
                    mapping={'num': len(failed),
                             'names': u','.join(failed)}),
                type="warning"
            )

        self.request.response.redirect(self.context.absolute_url())