Exemple #1
0
 def add(self, slot, portlet_type, **kw):
     factory = get_content_factories()['Portlet']
     portlet = factory(portlet_type, **kw)
     if slot not in self:
         self[slot] = pf = get_content_factories()['PortletFolder'](slot)
         pf.__parent__ = self.context
     portlets = self[slot]
     portlets[portlet.uid] = portlet
     portlet.__parent__ = portlets
     return portlet
Exemple #2
0
 def add(self, slot, portlet_type, **kw):
     factory = get_content_factories()['Portlet']
     portlet = factory(portlet_type, **kw)
     if slot not in self:
         self[slot] = pf = get_content_factories()['PortletFolder'](slot)
         pf.__parent__ = self.context
     portlets = self[slot]
     portlets[portlet.uid] = portlet
     portlet.__parent__ = portlets
     return portlet
Exemple #3
0
 def course_module(self):
     if self.request.has_permission('perm:Edit', self.context):
         jqueryui.need()
         touchpunch_js.need()
     response = {}
     response['course'] = find_interface(self.context, ICourse)
     response['course_modules'] = response['course'].items()
     response['in_course'] = self.fikaProfile.in_course(response['course'])
     response['course_module_toggle'] = self._render_course_module_toggle
     response['course_pagination'] = render_course_pagination
     response['module_segments'] = self.context.values()
     response['is_assessment'] = {}
     for segment in self.context.values():
         response['is_assessment'][segment.__name__] = isinstance(segment, Assessment)
         if isinstance(segment, ImageSlideshow):
             lightbox_js.need()
             lightbox_css.need()
             break
         for segmentcontent in segment.values():
             if isinstance(segmentcontent, ImageSlideshow):
                 lightbox_js.need()
                 lightbox_css.need()
                 break
     response['addable_types'] = {}
     factories = get_content_factories(self.request.registry)
     for (obj, addable) in get_addable_content(self.request.registry).items():
         if 'Segment' in addable:
             factory = factories.get(obj, None)
             response['addable_types'][obj] = getattr(factory, 'icon', 'file')
     return response
Exemple #4
0
def appmaker(zodb_root):
    try:
        return zodb_root['app_root']
    except KeyError:
        from pyramid.threadlocal import get_current_registry
        from zope.interface import alsoProvides
        import transaction

        from arche.utils import get_content_factories
        from arche.interfaces import IRoot
        from arche.populators import root_populator

        factories = get_content_factories()
        #This is where initial population takes place, but first some site setup
        if not 'initial_setup' in zodb_root or not zodb_root['initial_setup'].setup_data:
            InitialSetup = factories['InitialSetup']
            zodb_root['initial_setup'] = InitialSetup()
            transaction.commit()
            return zodb_root['initial_setup']
        else:
            #FIXME move this population to its own method so tests can use it
            #Root added
            data = dict(zodb_root['initial_setup'].setup_data)
            #Attach and remove setup context
            zodb_root['app_root'] = root_populator(**data)
            del zodb_root['initial_setup']
            return zodb_root['app_root']
Exemple #5
0
def root_populator(title="",
                   userid="",
                   email="",
                   password="",
                   populator_name=""):
    factories = get_content_factories()
    root = factories['Root'](title=title)
    #Add users
    root['users'] = users = factories['Users']()
    #Add user
    assert userid
    users[userid] = factories['User'](email=email, password=password)
    #Add groups
    root['groups'] = groups = factories['Groups']()
    #Add administrators group
    description = _(
        u"Group for all administrators. Add any administrators to this group.")
    groups['administrators'] = adm_group = factories['Group'](
        title=_(u"Administrators"), description=description, members=[userid])
    #Add admin role
    local_roles = get_local_roles(root)
    local_roles[adm_group.principal_name] = (ROLE_ADMIN, )
    #Run extra populator
    if populator_name:
        reg = get_current_registry()
        populator = reg.getAdapter(root, IPopulator, name=populator_name)
        populator.populate()
    #Publish root
    try:
        wf = get_context_wf(root)
        wf.do_transition('private:public', force=True)
    except WorkflowException:
        pass
    return root
Exemple #6
0
def root_populator(title="", userid="", email="", password="", populator_name=""):
    factories = get_content_factories()
    root = factories["Root"](title=title)
    # Add users
    root["users"] = users = factories["Users"]()
    # Add user
    assert userid
    users[userid] = factories["User"](email=email, password=password)
    # Add groups
    root["groups"] = groups = factories["Groups"]()
    # Add administrators group
    description = _("Group for all administrators. Add any administrators to this group.")
    groups["administrators"] = adm_group = factories["Group"](
        title=_("Administrators"), description=description, members=[userid]
    )
    # Add admin role
    local_roles = get_local_roles(root)
    local_roles[adm_group.principal_name] = (ROLE_ADMIN,)
    # Run extra populator
    if populator_name:
        reg = get_current_registry()
        populator = reg.getAdapter(root, IPopulator, name=populator_name)
        populator.populate()
    # Publish root
    try:
        wf = get_context_wf(root)
        wf.do_transition("private:public", force=True)
    except WorkflowException:
        pass
    return root
Exemple #7
0
def appmaker(zodb_root):
    try:
        return zodb_root['app_root']
    except KeyError:
        from pyramid.threadlocal import get_current_registry
        from zope.interface import alsoProvides
        import transaction

        from arche.utils import get_content_factories
        from arche.interfaces import IRoot
        from arche.populators import root_populator

        factories = get_content_factories()
        #This is where initial population takes place, but first some site setup
        if not 'initial_setup' in zodb_root or not zodb_root[
                'initial_setup'].setup_data:
            InitialSetup = factories['InitialSetup']
            zodb_root['initial_setup'] = InitialSetup()
            transaction.commit()
            return zodb_root['initial_setup']
        else:
            #FIXME move this population to its own method so tests can use it
            #Root added
            data = dict(zodb_root['initial_setup'].setup_data)
            #Attach and remove setup context
            zodb_root['app_root'] = root_populator(**data)
            del zodb_root['initial_setup']
            return zodb_root['app_root']
Exemple #8
0
def appmaker(zodb_root):
    try:
        return zodb_root['app_root']
    except KeyError:
        from pyramid.threadlocal import get_current_registry
        from zope.interface import alsoProvides
        from zope.component.event import objectEventNotify
        import transaction
        from arche.utils import get_content_factories
        from arche.interfaces import IRoot
        from arche.populators import root_populator
        from arche.models.evolver import run_initial_migrations
        from arche.events import ObjectAddedEvent

        factories = get_content_factories()
        #This is where initial population takes place, but first some site setup
        if not 'initial_setup' in zodb_root or not zodb_root['initial_setup'].setup_data:
            InitialSetup = factories['InitialSetup']
            zodb_root['initial_setup'] = InitialSetup()
            transaction.commit()
            return zodb_root['initial_setup']
        else:
            #FIXME move this population to its own method so tests can use it
            #Root added
            data = dict(zodb_root['initial_setup'].setup_data)
            #Attach and remove setup context
            zodb_root['app_root'] = root = root_populator(**data)
            transaction.commit()
            run_initial_migrations(root)
            # Manually notify added event
            objectEventNotify(ObjectAddedEvent(root, None, None))
            del zodb_root['initial_setup']
            return root
Exemple #9
0
def default_factory_attr(node, kw):
    """ This probably won't fire unless you add something,
        but it might be useful for other forms aswell.
    """
    request = kw['request']
    if request.view_name == 'add':
        content_type = request.GET.get('content_type')
        factory = get_content_factories()[content_type]
        return getattr(factory, node.name)
    getattr(kw['context'], node.name)
Exemple #10
0
def default_factory_attr(node, kw):
    """ This probably won't fire unless you add something,
        but it might be useful for other forms aswell.
    """
    request = kw['request']
    if request.view_name == 'add':
        content_type = request.GET.get('content_type')
        factory = get_content_factories()[content_type]
        return getattr(factory, node.name)
    getattr(kw['context'], node.name)
Exemple #11
0
 def addable_content(self, context):
     _marker = object()
     context_type = getattr(context, 'type_name', None)
     factories = get_content_factories(self.request.registry)
     for (name, addable) in get_addable_content(self.request.registry).items():
         if context_type in addable:
             factory = factories.get(name, None)
             if factory is not None:
                 add_perm = getattr(factory, 'add_permission', _marker)
                 if self.request.has_permission(add_perm, context):
                     yield factory
Exemple #12
0
def content_types_panel(context, request, va, **kw):
    response = {
        'content_factories': get_content_factories(request.registry),
        'addable_content': get_addable_content(request.registry),
        'content_views': get_content_views(request.registry),
        'content_schemas': get_content_schemas(request.registry),
        'workflows': get_workflows(request.registry),
        'acl_iface': IContextACL,
        'local_roles_iface': ILocalRoles,
        }
    return render('arche:templates/sysinfo/content_types.pt', response, request = request)
Exemple #13
0
def batch_file_upload_handler_view(context, request):
    controls = request.params.items()
    controls.insert(0, ('__start__', 'file_data:mapping'))
    controls.append(('__end__', 'file_data:mapping'))
    schema = AddFileSchema()
    schema = schema.bind(request = request, context = context)
    form = deform.Form(schema)
    appstruct = form.validate(controls)
    factory = get_content_factories()['File']
    obj = factory(**appstruct)
    name = generate_slug(context, obj.filename)
    context[name] = obj
    return Response()
def includeme(config):
    #Adjusting add perms to all Editors is kind of reckless. This will probably change in Arche.
    acl_reg = config.registry.acl
    factories = get_content_factories(config.registry)
    add_perms = []
    for factory in factories.values():
        if hasattr(factory, 'add_permission'):
            add_perms.append(factory.add_permission)
    #Root perms
    del acl_reg['Root']
    root_acl = acl_reg.new_acl('Root')
    root_acl.add(security.ROLE_ADMIN, security.ALL_PERMISSIONS)
    root_acl.add(security.ROLE_EDITOR, add_perms)
    root_acl.add(security.ROLE_AUTHENTICATED, security.PERM_VIEW)
    #Org perms
    org_acl = acl_reg.new_acl('Organisation')
    org_acl.add(security.ROLE_ADMIN, security.ALL_PERMISSIONS)
    org_acl.add(security.ROLE_EDITOR, add_perms)
    org_acl.add(security.ROLE_EDITOR, (security.PERM_VIEW, security.PERM_EDIT))
    org_acl.add(security.ROLE_VIEWER, security.PERM_VIEW)
Exemple #15
0
def root_populator(title = "", userid = "", email = "", password = ""):
    factories = get_content_factories()
    root = factories['Root'](title = title)
    #Add users
    root['users'] = users = factories['Users']()
    #Add user
    assert userid
    users[userid] = factories['User'](email = email, password = password)
    #Add groups
    root['groups'] = groups = factories['Groups']()
    #Add administrators group
    description = _("Group with administrative rights.")
    title = _(u"Administrators")
    request = get_current_request()
    if request is not None:
        description = request.localizer.translate(description)
        title = request.localizer.translate(title)
    groups['administrators'] = adm_group = factories['Group'](title = title,
                                                              description = description,
                                                              members = [userid])
    #Add admin role
    root.local_roles[adm_group.principal_name] = (ROLE_ADMIN,)
    return root
Exemple #16
0
def includeme(config):
    from arche.utils import get_content_factories

    config.registry._roles = rr = RolesRegistry()
    rr.add(ROLE_ADMIN)
    rr.add(ROLE_EDITOR)
    rr.add(ROLE_VIEWER)
    rr.add(ROLE_OWNER)
    rr.add(ROLE_REVIEWER)
    config.registry.registerAdapter(Roles)
    config.registry._acl = aclreg = ACLRegistry()
    aclreg.default.add(ROLE_ADMIN, ALL_PERMISSIONS)
    aclreg.default.add(ROLE_EDITOR, [PERM_VIEW, PERM_EDIT, PERM_DELETE])
    aclreg.default.add(ROLE_OWNER, [PERM_VIEW, PERM_EDIT])
    aclreg.default.add(ROLE_VIEWER, [PERM_VIEW])
    aclreg.default.add(ROLE_REVIEWER, [PERM_VIEW, PERM_REVIEW_CONTENT])
    # Default add perms - perhaps configurable somewhere else?
    # Anyway, factories need to be included first otherwise this won't work!
    factories = get_content_factories(config.registry)
    add_perms = []
    for factory in factories.values():
        if hasattr(factory, "add_permission"):
            add_perms.append(factory.add_permission)
    aclreg.default.add(ROLE_ADMIN, add_perms)
Exemple #17
0
def includeme(config):
    from arche.utils import get_content_factories

    config.registry._roles = rr = RolesRegistry()
    rr.add(ROLE_ADMIN)
    rr.add(ROLE_EDITOR)
    rr.add(ROLE_VIEWER)
    rr.add(ROLE_OWNER)
    rr.add(ROLE_REVIEWER)
    config.registry.registerAdapter(Roles)
    config.registry._acl = aclreg = ACLRegistry()
    aclreg.default.add(ROLE_ADMIN, ALL_PERMISSIONS)
    aclreg.default.add(ROLE_EDITOR, [PERM_VIEW, PERM_EDIT, PERM_DELETE])
    aclreg.default.add(ROLE_OWNER, [PERM_VIEW, PERM_EDIT])
    aclreg.default.add(ROLE_VIEWER, [PERM_VIEW])
    aclreg.default.add(ROLE_REVIEWER, [PERM_VIEW, PERM_REVIEW_CONTENT])
    #Default add perms - perhaps configurable somewhere else?
    #Anyway, factories need to be included first otherwise this won't work!
    factories = get_content_factories(config.registry)
    add_perms = []
    for factory in factories.values():
        if hasattr(factory, 'add_permission'):
            add_perms.append(factory.add_permission)
    aclreg.default.add(ROLE_ADMIN, add_perms)
Exemple #18
0
def createContent(type_name, *args, **kw):
    """ Replaces the betahaus.pyracont createContent method with a wrapper for Arches
        factory implementation.
    """
    factories = get_content_factories()
    return factories[type_name](*args, **kw)
Exemple #19
0
def evolve(root):
    from arche.utils import get_content_factories
    if 'groups' not in root:
        factories = get_content_factories()
        root['groups'] = factories['Groups']()
Exemple #20
0
 def get_content_factory(self, name):
     return get_content_factories(self.request.registry).get(name)
Exemple #21
0
 def populate(self, **kw):
     factories = get_content_factories()
     self.context['courses'] = factories['Courses']()