예제 #1
0
def fetch_organisation(organization, level=0):
    """ Returns the export data of an organisation with all its
    sub-organizations.

    """
    data = {
        'title': organization.title if level else '',
        'portrait': '',
        'memberships': [],
        'children': [],
        'context': organization
    }

    if organization.portrait:
        data['portrait'] = organization.portal_transforms.convertTo(
            'text/x-html-safe',
            organization.portrait,
            context=organization,
            encoding='utf8'
        ).getData()

    memberships = []
    for brain in organization.memberships():
        membership = brain.getObject()
        person = membership.person.to_object
        fields = organization.export_fields

        role = membership.role if 'role' in fields else ''
        text = ''
        name = ''

        if person:
            name = person.title
            text_fields = []
            for field in fields:
                if getattr(person, field, None):
                    text_fields.append(getattr(person, field, ''))
                if getattr(membership, field, None):
                    if field == 'role' or field == 'title':
                        continue
                    text_fields.append(getattr(membership, field, ''))
            text = ', '.join(text_fields)

        memberships.append((role, membership.prefix, text, name))

    if organization.display_alphabetically:
        sortkey = lambda m: tools.unicode_collate_sortkey()(m[3])
        memberships = sorted(memberships, key=sortkey)

    for membership in memberships:
        data['memberships'].append(membership[:3])

    children = [o.getObject() for o in organization.suborganizations()]

    for idx, child in enumerate(children):
        data['children'].append(
            fetch_organisation(child, level + 1)
        )

    return data
예제 #2
0
def fetch_organisation(organization, level=0):
    """ Returns the export data of an organisation with all its
    sub-organizations.

    """
    data = {
        'title': organization.title if level else '',
        'portrait': '',
        'memberships': [],
        'children': [],
        'context': organization
    }

    if organization.portrait:
        data['portrait'] = organization.portal_transforms.convertTo(
            'text/x-html-safe',
            organization.portrait,
            context=organization,
            encoding='utf8').getData()

    memberships = []
    for brain in organization.memberships():
        membership = brain.getObject()
        person = membership.person.to_object
        fields = organization.export_fields

        role = membership.role if 'role' in fields else ''
        text = ''
        name = ''

        if person:
            name = person.title
            text_fields = []
            for field in fields:
                if getattr(person, field, None):
                    text_fields.append(getattr(person, field, ''))
                if getattr(membership, field, None):
                    if field == 'role' or field == 'title':
                        continue
                    text_fields.append(getattr(membership, field, ''))
            text = ', '.join(text_fields)

        memberships.append((role, membership.prefix, text, name))

    if organization.display_alphabetically:
        sortkey = lambda m: tools.unicode_collate_sortkey()(m[3])
        memberships = sorted(memberships, key=sortkey)

    for membership in memberships:
        data['memberships'].append(membership[:3])

    children = [o.getObject() for o in organization.suborganizations()]

    for idx, child in enumerate(children):
        data['children'].append(fetch_organisation(child, level + 1))

    return data
예제 #3
0
    def letters(self):
        catalog = api.portal.get_tool(catalog_id)
        index = catalog._catalog.getIndex('first_letter')

        letters = set()

        for person in self.people():
            letter = index.getEntryForObject(person.getRID())

            if letter:
                letters.add(letter)

        return sorted(letters, key=tools.unicode_collate_sortkey())
예제 #4
0
    def memberships(self):
        memberships = []
        for brain in self.context.memberships():
            obj = brain.getObject()
            person = obj.person.to_object
            name = person.title if person else u''
            memberships.append((obj.role, name, obj.prefix, brain.getURL()))

        if self.context.display_alphabetically:
            sortkey = lambda m: tools.unicode_collate_sortkey()(m[1])
            memberships = sorted(memberships, key=sortkey)

        return memberships
예제 #5
0
    def organizations(self, person, method):
        Organization = namedtuple("Organization", ["title", "url", "role"])
        catalog = api.portal.get_tool("portal_catalog")

        organizations = []

        for uuid, memberships in getattr(person, method).items():
            current_role = IPerson(person).current_role(memberships)

            brain = catalog(UID=uuid)[0]
            organizations.append(Organization(brain.Title, brain.getURL(), current_role))

        sortkey = lambda org: tools.unicode_collate_sortkey()(org.title)
        return sorted(organizations, key=sortkey)
예제 #6
0
    def __call__(self, context, field, options):
        uuids = getattr(context, field, None)

        if not uuids:
            return u''

        unicode_sortkey = tools.unicode_collate_sortkey()

        brains = (b for b in (uuidToCatalogBrain(uid) for uid in uuids) if b)
        items = sorted(
            ((b.getURL(), b.Title) for b in brains),
            key=lambda i: unicode_sortkey(i[1])
        )

        return ', '.join(
            self.template.substitute(url=url, title=title.decode('utf-8'))
            for url, title in items
        )
예제 #7
0
    def column_values(self, column):
        assert column.selectable

        people = self.context.people()

        unique_values = set()

        for value in (getattr(brain, column.fields[0]) for brain in people):
            if value is None:
                continue

            if isinstance(value, list):
                for item in value:
                    unique_values.add(item.encode("utf-8"))
            else:
                unique_values.add(value.encode("utf-8"))

        return sorted(unique_values, key=tools.unicode_collate_sortkey())
예제 #8
0
    def organizations(self, org_filter=None):
        """ Returns a list of organizations this person is active in. The list
        is sorted by uca collation. This is mainly used for the organizations
        metadata field of all person objects (to show in the list).

        """

        organizations = self.organization_uuids(org_filter)

        # organizations are defined in the general catalog, not the people
        # catalog, which only contains people, therefore use 'portal_catalog'
        titles = []
        catalog = api.portal.get_tool('portal_catalog')
        for uid in organizations:
            title = catalog(UID=uid)[0].Title
            if isinstance(title, str):
                title = title.decode('utf-8')
            titles.append(title)

        return sorted(titles, key=tools.unicode_collate_sortkey())
예제 #9
0
    def __call__(self, context, field, options):

        if not all([field == 'organization_uuids',
                    context.portal_type == 'seantis.agencies.member']):
            return super(UUIDListRenderer, self).__call__(context, field,
                                                          options)

        uuids = getattr(context, field, None)
        if not uuids:
            return u''

        brains = (b for b in (uuidToCatalogBrain(uid) for uid in uuids) if b)
        items = (self.brain_to_link(b) for b in brains)

        unicode_sortkey = tools.unicode_collate_sortkey()
        items = sorted(items, key=lambda i: unicode_sortkey(i[1]))

        return ', '.join(
            self.template.substitute(url=url, title=title)
            for url, title in items
        )
예제 #10
0
    def organizations(self, person, method):
        Organization = namedtuple('Organization', ['title', 'url', 'role'])
        catalog = api.portal.get_tool('portal_catalog')

        organizations = []

        for uuid, memberships in getattr(person, method).items():

            brain = catalog(UID=uuid)[0]
            obj = brain.getObject()
            parent = aq_parent(aq_inner(obj))

            title = u'%s' % obj.title
            if parent:
                title = u'%s (%s)' % (title, parent.title)

            for membership in memberships:
                organizations.append(
                    Organization(title, brain.getURL(), membership.role))

        sortkey = lambda org: tools.unicode_collate_sortkey()(org.title)
        return sorted(organizations, key=sortkey)
예제 #11
0
    def __call__(self, context, field, options):

        if not all([
                field == 'organization_uuids', context.portal_type
                == 'seantis.agencies.member'
        ]):
            return super(UUIDListRenderer,
                         self).__call__(context, field, options)

        uuids = getattr(context, field, None)
        if not uuids:
            return u''

        brains = (b for b in (uuidToCatalogBrain(uid) for uid in uuids) if b)
        items = (self.brain_to_link(b) for b in brains)

        unicode_sortkey = tools.unicode_collate_sortkey()
        items = sorted(items, key=lambda i: unicode_sortkey(i[1]))

        return ', '.join(
            self.template.substitute(url=url, title=title)
            for url, title in items)
예제 #12
0
    def organizations(self, person, method):
        Organization = namedtuple('Organization', ['title', 'url', 'role'])
        catalog = api.portal.get_tool('portal_catalog')

        organizations = []

        for uuid, memberships in getattr(person, method).items():

            brain = catalog(UID=uuid)[0]
            obj = brain.getObject()
            parent = aq_parent(aq_inner(obj))

            title = u'%s' % obj.title
            if parent:
                title = u'%s (%s)' % (title, parent.title)

            for membership in memberships:
                organizations.append(
                    Organization(title, brain.getURL(), membership.role)
                )

        sortkey = lambda org: tools.unicode_collate_sortkey()(org.title)
        return sorted(organizations, key=sortkey)
예제 #13
0
    def test_order(self):
        new_type = self.new_temporary_type(
            behaviors=[IPerson.__identifier__],
            klass='seantis.people.types.base.PersonBase'
        )
        set_order(new_type.lookupSchema(), ['bar', 'foo'])

        with self.user('admin'):
            obj = api.content.create(
                id='123',
                type=new_type.id,
                container=self.new_temporary_folder(),
                foo='stop',
                bar='hammertime!'
            )

        brain = tools.get_brain_by_object(obj, catalog_id)
        catalog = api.portal.get_tool(catalog_id)

        self.assertEqual(
            catalog.getIndexDataForRID(brain.getRID())['sortable_title'],
            tools.unicode_collate_sortkey()('hammertime! stop')
        )
예제 #14
0
def sortable_title(obj):
    return tools.unicode_collate_sortkey()(get_sortable_title_text(obj))
예제 #15
0
 def test_unicode_collate_sortkey(self):
     self.assertEqual(
         sorted(u'AaÄäÖöOo', key=tools.unicode_collate_sortkey()),
         list(u'aAäÄoOöÖ')
     )