예제 #1
0
def ComponentRegistrationAddSubscriber(componentRegistration, event):
    """Receive notification of add event."""
    component = componentRegistration.component
    try:
        dependents = IDependable(component)
    except TypeError:
        return
    objectpath = zapi.getPath(componentRegistration)
    dependents.addDependent(objectpath)
예제 #2
0
 def hasDependents(self, item):
     # We cannot adapt security-proxied objects to IDependable.  Unwrapping
     # is safe since we do not modify anything, and the information whether
     # an object can be deleted or not is not classified.
     unwrapped_context = removeSecurityProxy(item)
     dependable = IDependable(unwrapped_context, None)
     if dependable is None:
         return False
     else:
         return bool(dependable.dependents())
예제 #3
0
def CheckDependency(event):
    object = event.object
    dependency = IDependable(object, None)
    if dependency is not None:
        dependents = dependency.dependents()
        if dependents:
            mapping = {
                "object": zapi.getPath(object),
                "dependents": ", ".join(dependents)
                }
            raise DependencyError(Message(exception_msg, mapping=mapping))
예제 #4
0
def getBoundContact(context):
    person = IBasicPerson(removeSecurityProxy(context))
    annotations = IAnnotations(person)
    contact = annotations.get(PERSON_CONTACT_KEY, None)
    if contact is None:
        contact = BoundContact()
        annotations[PERSON_CONTACT_KEY] = contact
        contact.__name__ = 'contact'
        contact.__parent__ = person
        dependable = IDependable(contact)
        dependable.addDependent("")
        notify(ObjectAddedEvent(contact, contact.__parent__, contact.__name__))
    return contact
예제 #5
0
def getBoundContact(context):
    person = IBasicPerson(removeSecurityProxy(context))
    annotations = IAnnotations(person)
    contact = annotations.get(PERSON_CONTACT_KEY, None)
    if contact is None:
        contact = BoundContact()
        annotations[PERSON_CONTACT_KEY] = contact
        contact.__name__ = 'contact'
        contact.__parent__ = person
        dependable = IDependable(contact)
        dependable.addDependent("")
        notify(ObjectAddedEvent(contact, contact.__parent__, contact.__name__))
    return contact
예제 #6
0
 def demographics(self):
     pos = 0
     result = []
     for demo in self.context.values():
         dependable = IDependable(removeSecurityProxy(demo), None)
         removable = dependable is None or not dependable.dependents()
         pos += 1
         result.append({
             'name': demo.__name__,
             'title': demo.title,
             'pos': pos,
             'removable': removable,
         })
     return result
예제 #7
0
 def demographics(self):
     pos = 0
     result = []
     for demo in self.context.values():
         dependable = IDependable(removeSecurityProxy(demo), None)
         removable = dependable is None or not dependable.dependents()
         pos += 1
         result.append({
             'name': demo.__name__,
             'title': demo.title,
             'pos': pos,
             'removable': removable,
         })
     return result
예제 #8
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('')
예제 #9
0
    def has_dependents(self):
        """Check whether an object has dependents (via IDependable).

        Objects that have dependents cannot be removed from the system.

        Sample usage in a page template:

          <input type="checkbox" name="delete"
                 tal:attributes="disabled obj/schooltool:has_dependents" />

        """
        # We cannot adapt security-proxied objects to IDependable.  Unwrapping
        # is safe since we do not modify anything, and the information whether
        # an object can be deleted or not is not classified.
        unwrapped_context = removeSecurityProxy(self.context)
        dependable = IDependable(unwrapped_context, None)
        if dependable is None:
            return False
        else:
            return bool(dependable.dependents())
예제 #10
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)
예제 #11
0
파일: main.py 프로젝트: l1ph0x/schooltool-2
    def restoreManagerUser(self, app, password):
        """Ensure there is a manager user

        Create a user if needed, set password to default, grant
        manager permissions
        """
        # set the site so that catalog utilities and person factory
        # utilities and subscribers were available
        setSite(app)
        if MANAGER_USERNAME not in app['persons']:
            factory = getUtility(IPersonFactory)
            manager = factory.createManagerUser(MANAGER_USERNAME)
            app['persons'][MANAGER_USERNAME] = manager
            IDependable(manager).addDependent('')
        manager = app['persons'][MANAGER_USERNAME]
        manager.setPassword(password)
        app['persons'].super_user = manager
        setSite(None)
예제 #12
0
def setUpLeaveSchoolDemographics(app):
    dfs = app.get('schooltool.basicperson.demographics_fields')
    if dfs is None:
        return
    dfs['leave_date'] = DateFieldDescription('leave_date',
                                             _('Date of un-enrollment'),
                                             limit_keys=['students'])
    dfs['leave_reason'] = EnumFieldDescription('leave_reason',
                                               _('Reason for un-enrollment'),
                                               limit_keys=['students'])
    dfs['leave_reason'].items = [_('Transferred'), _('Dropped out')]
    dfs['leave_destination'] = EnumFieldDescription('leave_destination',
                                                    _('Destination school'),
                                                    limit_keys=['students'])
    dfs['leave_destination'].items = [
        _('Example School A'), _('Example School B')
    ]
    for name in LEAVE_SCHOOL_FIELDS:
        if name in dfs:
            IDependable(dfs[name]).addDependent('')
예제 #13
0
 def __call__(self):
     contact = IContact(self.object)
     dependable = IDependable(contact)
     dependable.removeDependent("")
     notify(
         ObjectRemovedEvent(contact, contact.__parent__, contact.__name__))
예제 #14
0
 def render(self, *args, **kw):
     unwrapped = removeSecurityProxy(self.context)
     dependable = IDependable(unwrapped, None)
     if dependable is None or not bool(dependable.dependents()):
         return super(GroupDeleteLink, self).render(*args, **kw)
예제 #15
0
 def __call__(self):
     contact = IContact(self.object)
     dependable = IDependable(contact)
     dependable.removeDependent("")
     notify(ObjectRemovedEvent(contact, contact.__parent__, contact.__name__))
예제 #16
0
 def render(self, *args, **kw):
     dep = IDependable(removeSecurityProxy(self.context), None)
     if (dep is not None and dep.dependents()):
         return ''
     return flourish.page.ModalFormLinkViewlet.render(self, *args, **kw)
예제 #17
0
 def render(self, *args, **kw):
     unwrapped = removeSecurityProxy(self.context)
     dependable = IDependable(unwrapped, None)
     if dependable is None or not bool(dependable.dependents()):
         return super(GroupDeleteLink, self).render(*args, **kw)
예제 #18
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__]
예제 #19
0
 def render(self, *args, **kw):
     dep = IDependable(removeSecurityProxy(self.context), None)
     if (dep is not None and dep.dependents()):
         return ''
     return flourish.page.ModalFormLinkViewlet.render(self, *args, **kw)