Ejemplo n.º 1
0
 def activeSchoolyearInfo(self):
     result = {}
     request = self.request
     collator = ICollator(request.locale)
     activeSchoolyear = self.context.getActiveSchoolYear()
     if activeSchoolyear is not None:
         result['title'] = activeSchoolyear.title
         result['hasCourses'] = self.hasCourses(activeSchoolyear)
         result['hasTimetables'] = self.hasTimetableSchemas(
             activeSchoolyear)
         result['groups'] = []
         groups = IGroupContainer(activeSchoolyear)
         for groupId, group in sorted(groups.items(),
                                      cmp=collator.cmp,
                                      key=lambda
                                      (groupId, group): group.title):
             info = {}
             info['id'] = groupId
             info['title'] = group.title
             info['isDefault'] = groupId in defaultGroups
             info['hasMembers'] = bool(list(group.members))
             info['sent'] = groupId in self.customGroupsToImport
             info['membersSent'] = groupId in self.groupsWithMembersToImport
             result['groups'].append(info)
     return result
Ejemplo n.º 2
0
 def persons(self):
     collator = ICollator(self.request.locale)
     factory = getUtility(IPersonFactory)
     sorting_key = lambda x: factory.getSortingKey(x, collator)
     sorted_persons = sorted(self.context.members, key=sorting_key)
     result = [self.getPersonData(person) for person in sorted_persons]
     return result
Ejemplo n.º 3
0
    def update(self):
        self.collator = ICollator(self.request.locale)
        groups = [
            group for group in self.context.groups
            if (canAccess(group, 'title') and not ISection.providedBy(group))
        ]

        schoolyears_data = {}
        for group in groups:
            sy = ISchoolYear(group.__parent__)
            if sy not in schoolyears_data:
                schoolyears_data[sy] = []
            schoolyears_data[sy].append(group)

        self.schoolyears = []
        for sy in sorted(schoolyears_data, key=lambda x: x.first,
                         reverse=True):
            sy_info = {
                'obj':
                sy,
                'groups':
                sorted(schoolyears_data[sy],
                       cmp=self.collator.cmp,
                       key=lambda x: x.title)
            }
            self.schoolyears.append(sy_info)
Ejemplo n.º 4
0
 def groups(self):
     groups = []
     container = self.groupContainer()
     collator = ICollator(self.request.locale)
     group_items = sorted(container.items(),
                          cmp=collator.cmp,
                          key=lambda (gid, g): g.title)
     for id, group in group_items:
         if len(group.members) > 0:
             groups.append({
                 'id':
                 id,
                 'title':
                 "%s (%s)" % (group.title, len(group.members))
             })
     return groups
Ejemplo n.º 5
0
    def rows(self):
        collator = ICollator(self.request.locale)
        utility = getReportRegistrationUtility()
        app = self.context

        rows = []
        for group_key, group_reports in utility.reports_by_group.items():
            reference_url = reportLinksURL(app, self.request, name=group_key)
            for report in group_reports:
                row = {
                    'url': reference_url,
                    'group': report['group'],
                    'title': report['title'],
                    'description': report['description'],
                    }
                rows.append([collator.key(report['group']),
                             collator.key(report['title']),
                             row])

        return [row for group, title, row in sorted(rows)]
Ejemplo n.º 6
0
 def rows(self):
     self.collator = ICollator(self.request.locale)
     utility = getReportRegistrationUtility()
     app = self.context
     rows = {}
     for group_key, group_reports in utility.reports_by_group.items():
         reference_url = reportLinksURL(app, self.request, name=group_key)
         for report in group_reports:
             group = report['group']
             name = report['name']
             row = {
                 'url': reference_url,
                 'group': group,
                 'title': report['title'],
                 'file_type': report['file_type'].upper(),
                 'description': report['description'],
             }
             # XXX: this check is needed to override old skin
             #      report links with flourish ones
             if (group, name) not in rows or \
                report['layer'] is IFlourishLayer:
                 rows[group, name] = row
     return sorted(rows.values(), key=self.sortKey)
Ejemplo n.º 7
0
 def ptos(self):
     collator = ICollator(self.request.locale)
     ptos_dict = {}
     for resource in sorted(self.context.values(),
                            key=lambda x: collator.key(x.title)):
         if ILocation(resource, None) is not None:
             resource_type = _('Location')
         elif IEquipment(resource, None) is not None:
             resource_type = _('Equipment')
         else:
             resource_type = _('Resource')
         pto = ptos_dict.setdefault(resource_type, {
             'type': resource_type,
             'rows': [],
         })
         pto['rows'].append({
             'title': resource.title,
             'description': resource.description,
         })
     return [
         ptos_dict[k]
         for k in sorted(ptos_dict.keys(), key=lambda x: collator.key(x))
     ]
Ejemplo n.º 8
0
 def update(self):
     self.collator = ICollator(self.request.locale)
     relationships = Membership.bind(
         member=self.context).all().relationships
     group_states = self.app_states('group-membership')
     student_states = self.app_states('student-enrollment')
     schoolyears_data = {}
     for link_info in relationships:
         group = removeSecurityProxy(link_info.target)
         if ISection.providedBy(group) or not canAccess(group, 'title'):
             continue
         sy = ISchoolYear(group.__parent__)
         if sy not in schoolyears_data:
             schoolyears_data[sy] = []
         schoolyears_data[sy].append((group, link_info))
     self.schoolyears = []
     for sy in sorted(schoolyears_data, key=lambda x: x.first,
                      reverse=True):
         sy_info = {
             'obj': sy,
             'css_class': 'active' if sy is self.schoolyear else 'inactive',
             'groups': [],
         }
         for group, link_info in sorted(
                 schoolyears_data[sy],
                 key=lambda x: self.collator.key(x[0].title)):
             is_students = group.__name__ == 'students'
             app_states = student_states if is_students else group_states
             states = self.group_current_states(link_info, app_states)
             group_info = {
                 'obj': group,
                 'title': group.title,
                 'states': states,
             }
             sy_info['groups'].append(group_info)
         self.schoolyears.append(sy_info)
Ejemplo n.º 9
0
 def getSortKey(self, item, formatter):
     if not self._cached_collator:
         self._cached_collator = ICollator(formatter.request.locale)
     s = super(IndexedLocaleAwareGetterColumn, self).getSortKey(item, formatter)
     return s and self._cached_collator.key(s)
Ejemplo n.º 10
0
 def getSortKey(self, item, formatter):
     collator = ICollator(formatter.request.locale)
     s = self.getter(item, formatter)
     return s and collator.key(s)
Ejemplo n.º 11
0
 def __init__(self, *args, **kw):
     Viewlet.__init__(self, *args, **kw)
     self.collator = ICollator(self.request.locale)
Ejemplo n.º 12
0
 def __init__(self, *args, **kw):
     super(FlourishCoursesViewlet, self).__init__(*args, **kw)
     self.collator = ICollator(self.request.locale)