Esempio n. 1
0
    def get_birthdays_from_persons(self):
        """Return next birthdays considering the interval defined in the
        portlet configuration.

        Birthday items include the following information:
        - birthday: day and month
        - fullname: full name of the person
        - description: description of the person
        - url: absolute url of the Person object
        - portrait: absolute url of the person portrait

        :returns: list of persons information
        :rtype: list of dict
        """
        catalog = api.portal.get_tool('portal_personcatalog')
        query = dict(
            review_state=('published', 'internally_published'),
            sort_on='cooked_birthday',
        )
        birthdays = []
        for range in self.get_search_range():
            query['cooked_birthday'] = {'query': range, 'range': 'minmax'}
            birthdays.extend(catalog.searchResults(**query))

        results = []
        for brain in birthdays:
            person = brain.getObject()
            results.append(dict(
                birthday=person.birthday.strftime('%d/%m'),  # remove the year
                fullname=person.title,
                description=person.description,
                url=person.absolute_url(),
                portrait=get_portrait_url(person),
            ))
        return results
Esempio n. 2
0
    def get_birthdays_from_users(self):
        """Return next user birthdays considering the interval defined in
        the portlet configuration. Birthday information is taken from
        `portal_memberdata` and we need to add a field called `birthday`.
        This is the preferred method if `s17.person` is not installed.

        Birthday items include the following information:
        - birthday: day and month
        - fullname: full name of the user
        - description: description of the user
        - url: absolute url of the author's page
        - portrait: absolute url of the user portrait

        :returns: list of users information
        :rtype: list of dict
        """
        results = []
        memberdata = api.portal.get_tool('portal_memberdata')
        if not memberdata.hasProperty('birthday'):
            return results

        portal_url = api.portal.get().absolute_url()
        users = api.user.get_users()
        users = [u for u in users if self.in_range(u.getProperty('birthday'))]
        for u in users:
            results.append(dict(
                birthday=u.getProperty('birthday')[:-5],  # remove the year
                fullname=u.getProperty('fullname') or u.getId(),
                description=u.getProperty('description'),
                url=portal_url + '/author/' + u.getId(),
                portrait=get_portrait_url(u.getId()),
            ))
        return results
Esempio n. 3
0
    def test_get_portrait_url_for_person(self):
        with api.env.adopt_roles(['Manager']):
            person = api.content.create(self.portal, 'Person', 'person')

        self.assertEqual(
            get_portrait_url(person),
            'http://nohost/plone/defaultUser.png',
        )
Esempio n. 4
0
 def portrait_url(self):
     """Return the URL of the portrait of the current user."""
     # XXX: This will return always the image of the Plone user and not
     #      the image of the Person object. We should fix s17.person to
     #      synchronize those images.
     return get_portrait_url(self.current_user_id)
Esempio n. 5
0
 def test_get_portrait_url_for_user(self):
     self.assertEqual(
         get_portrait_url(TEST_USER_ID),
         'http://nohost/plone/defaultUser.png',
     )