Exemple #1
0
    def __call__(self, context):
        while True:
            if IProject.providedBy(context):
                break

            if IDraftContent.providedBy(context):
                context = context.getLocation()
                if not ITasks.providedBy(context):
                    context = None
                context = getattr(context, '__parent__', None)
                break

            context = getattr(context, '__parent__', None)
            if context is None:
                break

        if context is not None:
            context = context.get('tasks')
        if context is None:
            return SimpleVocabulary(())

        ids = getUtility(IIntIds)

        categories = []
        for category in context.category.values():
            id = ids.getId(removeAllProxies(category))

            term = SimpleTerm(id, str(id), category.title)
            term.description = category.description

            categories.append((category.title, term))

        categories.sort()
        return SimpleVocabulary([term for title, term in categories])
Exemple #2
0
    def __call__(self, context):
        while True:
            if IBlog.providedBy(context):
                break

            if IDraftContent.providedBy(context):
                context = context.getLocation()
                if ISpace.providedBy(context):
                    context = context.get('blog')
                break

            context = getattr(context, '__parent__', None)
            if context is None:
                break

        if context is None:
            return SimpleVocabulary(())

        ids = getUtility(IIntIds)

        categories = []
        for category in context['category'].values():
            try:
                id = ids.getId(removeAllProxies(category))
            except:
                continue

            term = SimpleTerm(id, str(id), category.title)
            term.description = category.description

            categories.append((category.title, term))

        categories.sort()
        return SimpleVocabulary([term for title, term in categories])
Exemple #3
0
    def __init__(self, content, default=None):
        self.draft = False

        if IContent.providedBy(content):
            while content is not None:
                if IDraftContent.providedBy(content):
                    self.draft = True

                content = getattr(content, '__parent__', None)
Exemple #4
0
    def __init__(self, content, default=None):
        while not IDraftContent.providedBy(content):
            content = content.__parent__

            if ISite.providedBy(content) or content is None:
                self.isDraft = False
                return

        self.isDraft = True
    def __call__(self, context):
        if not IDraftContent.providedBy(context):
            return Vocabulary(())

        ct = IContentType(context)
        types = []
        for tp in ct.destination:
            types.append(tp.name)

        kwargs = {}
        if types:
            kwargs['type'] = {'any_of': types}

        request = getRequest()
        catalog = getUtility(ICatalog)

        perms = {}
        permissions = []
        for id in listAllowedRoles(request.principal, context):
            perms[ct.submit] = 1
            perms[ct.publish] = 1
            permissions.append((ct.submit, id))
            permissions.append((ct.publish, id))

        results = catalog.searchResults(
            draftSubmitTo={'any_of': permissions}, **kwargs)

        if not results:
            return Vocabulary(())

        perms = perms.keys()
        ids = getUtility(IIntIds)

        contents = []
        for content in results:
            allow = False
            for perm in perms:
                if checkPermission(perm, content):
                    allow = True
                    break

            if allow:
                contents.append(
                    (getPath(content),
                     IItem(content).title, ids.getId(content), content))

        contents.sort()

        terms = []
        for path, title, id, content in contents:
            term = SimpleTerm(
                id, str(id), getMultiAdapter((content, request), IBreadcrumb))
            term.content = content
            terms.append(term)

        return Vocabulary(terms)
Exemple #6
0
def getKeyReference(object):
    if not IPersistent.providedBy(object):
        return

    try:
        return KeyReferenceToPersistent(removeSecurityProxy(object))
    except NotYet:
        while not IDraftContent.providedBy(object):
            object = getattr(object, '__parent__', None)
            if object is None:
                raise
Exemple #7
0
    def __init__(self, context, default=None):
        self.value = default
        self.allowed = default

        if not IDraftContent.providedBy(context):
            return

        ct = IContentType(context, None)
        if ct is None:
            return

        location = context.getLocation()
        if location is None:
            return

        users = getAccessList(removeSecurityProxy(location), ct.publish)

        self.value = users
        self.allowed = users
def CategoryIdsVocabulary(context):

    while True:

        if ISpace.providedBy(context):
            break

        if IDraftContent.providedBy(context):
            context = context.getLocation()
            break

        context = getattr(context, '__parent__', None)
        if context is None:
            break

    if context is None:
        return SimpleVocabulary(())

    getId = getUtility(IIntIds).getId
    terms = []

    while True:

        ws = queryAdapter(context, IWorkspaceFactory, name='media')

        if ws is not None and ws.isInstalled():
            for category in context['media']['category'].values():
                id = getId(removeAllProxies(category))
                term = SimpleTerm(id, str(id), category.title)
                term.description = category.description
                terms.append(term)

        if IPortal.providedBy(context):
            break

        context = getattr(context, '__parent__', None)
        if context is None or not ISpace.providedBy(context):
            break

    terms.sort(key=lambda t:t.title)

    return SimpleVocabulary(terms)
def CategoryIdsVocabulary(context):

    while True:
        if ISpace.providedBy(context):
            break

        if IDraftContent.providedBy(context):
            context = context.getLocation()
            if context is not None:
                context = context.__parent__
            break

        context = getattr(context, '__parent__', None)
        if context is None:
            break

    if context is None:
        return SimpleVocabulary(())

    getId = getUtility(IIntIds).getId
    terms = []

    while True:
        wf = queryAdapter(context, IWorkspaceFactory, name='news')
        if wf is not None and wf.isInstalled():
            for category in context['news']['category'].values():
                id = getId(removeAllProxies(category))
                term = SimpleTerm(id, str(id), category.title)
                term.description = category.description
                terms.append((term.title, term))

        if ISite.providedBy(context):
            break

        context = getattr(context, '__parent__', None)
        if context is None or not ISpace.providedBy(context):
            break

    terms.sort()
    return SimpleVocabulary([term for _t, term in terms])
Exemple #10
0
    def __init__(self, content, default=None):
        self.status = default

        if IDraftContent.providedBy(content) and \
                ISubmittedDraftContent.providedBy(content):
            self.status = u'submitted'