order polgroups in commission by their order
This commit is contained in:
parent
1a74db36bb
commit
0443d9a78c
|
@ -1,8 +1,12 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
from zope import component
|
||||
from Products.Five import BrowserView
|
||||
from Products.CMFCore.utils import getToolByName
|
||||
from plone.registry.interfaces import IRegistry
|
||||
|
||||
from themis.fields.vocabs import cmp_person
|
||||
from tabellio.config.interfaces import ITabellioSettings
|
||||
|
||||
class View(BrowserView):
|
||||
def presidence_polgroups(self):
|
||||
|
@ -12,19 +16,21 @@ class View(BrowserView):
|
|||
return [self.context.president.to_object]
|
||||
|
||||
def list_polgroups(self, list):
|
||||
d = {}
|
||||
polgroups = {}
|
||||
settings = component.getUtility(IRegistry).forInterface(ITabellioSettings, False)
|
||||
current = getToolByName(self.context, 'portal_url').getPortalObject()
|
||||
for part in settings.polgroupsPath.split('/'):
|
||||
if not part:
|
||||
continue
|
||||
current = getattr(current, part)
|
||||
polgroup_ids = current.objectIds()
|
||||
|
||||
items = []
|
||||
for member in list:
|
||||
polgroup = member.to_object.polgroup.to_object
|
||||
polgroup_id = polgroup.id
|
||||
polgroups[polgroup.id] = polgroup
|
||||
if not polgroup_id in d:
|
||||
d[polgroup_id] = 0
|
||||
d[polgroup_id] = d[polgroup_id] + 1
|
||||
items = d.items()
|
||||
items.sort(lambda x,y: cmp(x[1], y[1]))
|
||||
items.reverse()
|
||||
return [polgroups.get(x[0]) for x in items]
|
||||
items.append(polgroup_id)
|
||||
|
||||
return [getattr(current, x) for x in polgroup_ids if x in items]
|
||||
|
||||
def vicepresidence_polgroups(self):
|
||||
return self.list_polgroups(self.context.vicepresidents)
|
||||
|
|
Reference in New Issue