Beispiel #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
Beispiel #2
0
 def importDefaultGroupsMembers(self):
     oldGroups = IGroupContainer(self.activeSchoolyear)
     newGroups = IGroupContainer(self.newSchoolyear)
     for groupId in defaultGroups:
         if groupId in oldGroups and groupId in self.groupsWithMembersToImport:
             oldGroup = oldGroups[groupId]
             newGroup = newGroups[groupId]
             self.importGroupMembers(oldGroup, newGroup)
Beispiel #3
0
 def getAvailableItems(self):
     result = []
     selected_items = set(self.getSelectedItems())
     for schoolyear in self.schoolyears:
         groups = IGroupContainer(schoolyear)
         result.extend([group for group in groups.values()
                        if group not in selected_items])
     return result
Beispiel #4
0
 def importGroup(self, groupId, shouldImportMembers=False):
     oldGroups = IGroupContainer(self.activeSchoolyear)
     newGroups = IGroupContainer(self.newSchoolyear)
     if groupId in oldGroups:
         oldGroup = oldGroups[groupId]
         newGroup = newGroups[groupId] = Group(oldGroup.title,
                                               oldGroup.description)
         if shouldImportMembers:
             self.importGroupMembers(oldGroup, newGroup)
Beispiel #5
0
 def importDefaultGroups(self, activeSchoolyear):
     oldGroups = IGroupContainer(activeSchoolyear)
     newGroups = IGroupContainer(self.object)
     for groupId in defaultGroups:
         if groupId in oldGroups:
             oldGroup = oldGroups[groupId]
             newGroup = Group(oldGroup.title, oldGroup.description)
             newGroups[groupId] = newGroup
             IDependable(newGroup).addDependent('')
Beispiel #6
0
 def getGroup(self, group_principal_id):
     prefix = PersonContainerAuthenticationPlugin.group_prefix
     if not group_principal_id.startswith(prefix):
         return None
     groups = IGroupContainer(ISchoolToolApplication(None), None)
     if groups is None:
         return None
     group_id = group_principal_id[len(prefix):]
     return groups.get(group_id, None)
Beispiel #7
0
 def getAvailableItems(self):
     result = []
     selected_items = set(self.getSelectedItems())
     for schoolyear in self.schoolyears:
         groups = IGroupContainer(schoolyear)
         result.extend([
             group for group in groups.values()
             if group not in selected_items
         ])
     return result
Beispiel #8
0
def makeManager(app, schoolyear, person):
    groups = IGroupContainer(schoolyear)

    default_admin_names = ('manager', 'clerks')
    admin_groups = [groups.get(name)
                    for name in default_admin_names
                    if name in groups]

    person_groups = [group for group in Membership.query(member=person)
                     if group.__parent__.__name__ == groups.__name__]

    for group in admin_groups:
        if group not in person_groups:
            Membership(group=group, member=person)
Beispiel #9
0
 def export_groups(self, wb):
     self.task_progress.force('export_groups', active=True)
     ws = wb.add_sheet("Groups")
     school_years = sorted(ISchoolYearContainer(self.context).values(),
                           key=lambda s: s.first)
     row = 0
     for ny, school_year in enumerate(sorted(school_years, key=lambda i: i.last)):
         groups = IGroupContainer(school_year)
         for ng, group in enumerate(sorted(groups.values(), key=lambda i: i.__name__)):
             row = self.format_group(group, ws, row) + 1
             self.progress('export_groups', normalized_progress(
                     ny, len(school_years), ng, len(groups)
                     ))
     self.finish('export_groups')
Beispiel #10
0
def evolvePerson(app, schoolyear, person):
    groups = IGroupContainer(schoolyear)
    admin_names = ('manager', 'administrators', 'clerks')
    admin_groups = [groups.get(name)
                    for name in admin_names
                    if name in groups]

    person_groups = [group for group in Membership.query(member=person)
                     if group.__parent__.__name__ == groups.__name__]

    if any([group in admin_groups for group in person_groups]):
        for group in admin_groups:
            if group not in person_groups:
                Membership(group=group, member=person)
Beispiel #11
0
 def __iter__(self):
     gc = IGroupContainer(ISchoolToolApplication(None), None)
     if gc is None:
         return
     persons = gc['teachers'].members
     for person in sorted(persons, key=lambda p: p.__name__):
         yield PersonTerm(person)
Beispiel #12
0
 def getTermByToken(self, token):
     gc = IGroupContainer(ISchoolToolApplication(None))
     if gc is None:
         raise LookupError(token)
     if token not in gc:
         raise LookupError(token)
     return GroupTerm(gc[token])
Beispiel #13
0
 def export_groups(self, wb):
     self.task_progress.force('export_groups', active=True)
     ws = wb.add_sheet("Groups")
     school_years = sorted(ISchoolYearContainer(self.context).values(),
                           key=lambda s: s.first)
     row = 0
     for ny, school_year in enumerate(
             sorted(school_years, key=lambda i: i.last)):
         groups = IGroupContainer(school_year)
         for ng, group in enumerate(
                 sorted(groups.values(), key=lambda i: i.__name__)):
             row = self.format_group(group, ws, row) + 1
             self.progress(
                 'export_groups',
                 normalized_progress(ny, len(school_years), ng,
                                     len(groups)))
     self.finish('export_groups')
Beispiel #14
0
 def generate(self, app, seed=None):
     namegen = NameGenerator(str(seed) + self.name)
     teachers = IGroupContainer(app)['teachers']
     for count in range(self.power):
         person = self.personFactory(namegen, count)
         # Without removeSecurityProxy we can't add members a
         # group.
         app['persons'][person.username] = person
         removeSecurityProxy(teachers.members).add(person)
Beispiel #15
0
 def initializeGroupContainer(self):
     groups = IGroupContainer(self.object)
     for id, title in defaultGroups.items():
         group = groups[id] = Group(title)
         IDependable(group).addDependent('')
     persons = ISchoolToolApplication(None)['persons']
     manager = persons.super_user
     if manager is None:
         return
     for id in defaultManagerGroups:
         if manager not in groups[id].members:
             groups[id].members.add(manager)
Beispiel #16
0
    def generate(self, app, seed=None):
        namegen = NameGenerator(str(seed) + self.name)
        prefixgen = ChoiceGenerator(str(seed), ['Mr', 'Mrs', 'Miss', ''])
        gendergen = ChoiceGenerator(str(seed), ['male', 'female'])

        students = IGroupContainer(app)['students']
        for count in range(self.power):
            person = self.personFactory(namegen, prefixgen, gendergen, count)
            # Without removeSecurityProxy we can't add members a
            # group.
            app['persons'][person.username] = person
            removeSecurityProxy(students.members).add(person)
Beispiel #17
0
    def __iter__(self):
        if IPerson.providedBy(self.context):
            groups = [
                group for group in self.context.groups
                if IGroup.providedBy(group)
            ]
        else:
            groups = list(
                IGroupContainer(ISchoolToolApplication(None), {}).values())

        for group in sorted(groups, key=lambda g: g.__name__):
            yield GroupTerm(group)
 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
Beispiel #19
0
 def getTargets(self, keys):
     if not keys:
         return []
     result = []
     sy_groups = {}
     app = ISchoolToolApplication(None)
     schoolyears = ISchoolYearContainer(app)
     for key in keys:
         for sy_name, schoolyear in schoolyears.items():
             if not key.startswith(sy_name + '.'):
                 continue
             if sy_name not in sy_groups:
                 sy_groups[sy_name] = IGroupContainer(schoolyear)
             group = sy_groups[sy_name].get(key[len(sy_name) + 1:])
             if group is not None:
                 result.append(group)
     return result
Beispiel #20
0
 def __call__(self):
     group_container = IGroupContainer(self.object)
     for group_id, group in list(group_container.items()):
         IDependable(group).removeDependent('')
         del group_container[group_id]
     del group_container.__parent__[group_container.__name__]
Beispiel #21
0
 def getAvailableItemsContainer(self):
     app = ISchoolToolApplication(None)
     groups = IGroupContainer(app, {})
     return groups
Beispiel #22
0
def getGroupContainerForSection(section):
    sy = ISchoolYear(section)
    return IGroupContainer(sy)
Beispiel #23
0
 def url(self):
     groups = IGroupContainer(self.schoolyear)
     return '%s/%s?camefrom=%s' % (absoluteURL(
         groups, self.request), 'addSchoolToolGroup.html',
                                   absoluteURL(self.context, self.request))
Beispiel #24
0
 def container(self):
     schoolyear = self.schoolyear
     return IGroupContainer(schoolyear)
Beispiel #25
0
 def groups(self):
     return IGroupContainer(self.schoolyear, None)
Beispiel #26
0
 def actualContext(self):
     current_term = getUtility(IDateManager).current_term
     if current_term is None:
         return ISchoolToolApplication(None)
     return IGroupContainer(ISchoolYear(current_term))
Beispiel #27
0
def getGroupContainerForApp(app):
    syc = ISchoolYearContainer(app)
    sy = syc.getActiveSchoolYear()
    if sy is None:
        return None
    return IGroupContainer(sy)
Beispiel #28
0
 def url(self):
     link = self.link
     if not link:
         return None
     courses = IGroupContainer(self.schoolyear)
     return "%s/%s" % (absoluteURL(courses, self.request), self.link)
Beispiel #29
0
 def groupContainer(self):
     # XXX must know which group container to pick
     app = ISchoolToolApplication(None)
     return IGroupContainer(app, {})