Как я могу сравнить два списка NewsItem и вычесть один и тот же NewsItem? - PullRequest
2 голосов
/ 20 мая 2019

Мой Plone 4.x и Python 2.7.

Я создаю шаблон, вижу фрагмент:

    tal:define="path_list here/getPhysicalPath;
                path python:'/'.join(path_list);
                pathdepth viewletOptions/path/depth | python:-1;
                highlighted python:here.portal_catalog(path={'query':path,'depth':pathdepth}
                                                    ,portal_type='News Item'
                                                    ,review_state='highlight'
                                                    ,sort_on='effective'
                                                    ,sort_order='reverse'
                                                    ,hasImage=True)[:4];
                oldnew python:here.portal_catalog(path={'query':path,'depth':pathdepth}
                                                    ,portal_type='News Item'
                                                    ,review_state=['highlight','published']
                                                    ,sort_on='effective'
                                                    ,sort_order='reverse')[5:7];">

У меня есть два списка highlighted 'n oldnew,и я попытался создать скрипт (python) в ZMI очень просто

    for i in highlighted:
      if i in oldnew:
        oldnew.remove(i)
    return oldnew

и выдал ошибку

TypeError: mybrains.__cmp__(x,y) requires y to be a 'mybrains', not a 'Acquisition.ImplicitAcquisitionWrapper'

Как я могу удалить те же NewsItens из highlighted в oldnew?

1 Ответ

0 голосов
/ 21 мая 2019

Поскольку у вас есть несколько рабочих процессов, назначенных для элементов, этого нельзя достичь с помощью ZMI-скрипта, потому что вы получите «Недостаточные привилегии» при попытке доступа к нескольким состояниям рабочего процесса из-за ограниченного Python.

Вместо этого используйте просмотр в браузере и включите следующие вспомогательные методы для получения нужных элементов:

def getStates(context, obj):
    """
    For each assigned workflow of object collect state and return all states.
    """
    states = []
    wfs = context.portal_workflow.getWorkflowsFor(obj)
    for wf in wfs:
        state_info_dict = wf.getStatusOf(wf.id, obj)
        state = state_info_dict['review_state']
        states.append(state)
    return states


def getChildrenByStates(context, include_state='highlighted', exclude_state='published'):
    """"
    Get all children of context which have the include_state but not not the exclude_state.
    """
    objects = []
    path = '/'.join(context.aq_inner.getPhysicalPath())
    search_results = context.portal_catalog(path={'query':path,'depth':-1})
    for search_result in search_results:
        obj = search_result.getObject()
        states = getStates(context, obj)
        if include_state in states and not exclude_state in states:
            objects.append(obj)
    return objects
...