Ejemplo n.º 1
0
def get_folder_content(folder, user,
                       add_query=None,
                       **args):
    _filters = deepcopy(getattr(folder, 'filters', []))
    objects = []
    if _filters:
        query = None
        if add_query:
            query = QUERY_OPERATORS['and'](query, add_query)

        objects = find_entities(
            user=user,
            add_query=query,
            filters=_filters,
            filter_op='or',
            **args)

    oids = [get_oid(c) for c in folder.contents if can_access(user, c)]
    if args:
        contents = find_entities(
            user=user,
            intersect=oids,
            **args)
        oids = contents.ids if not isinstance(contents, list) else contents

    if isinstance(objects, list):
        objectmap = find_objectmap(folder)
        objects = ResultSet(oids, len(oids), objectmap.object_for)
    else: # ResultSet
        objects.ids = list(objects.ids)
        objects.ids.extend(oids)
        objects.numids += len(oids)

    return objects
Ejemplo n.º 2
0
def merge_with_filter_view(view, args):
    validated = None
    if view and getattr(view, 'filter_instance', None):
        validated = view.filter_instance.validated

    if not validated:
        return deepcopy(args)

    if not args:
        return deepcopy(validated)

    result = deepcopy(validated)
    for arg in deepcopy(args):
        if arg not in validated:
            result[arg] = args[arg]

    return result
Ejemplo n.º 3
0
def merge_with_filter_view(view, args):
    validated = None
    if view and getattr(view, 'filter_instance', None):
        validated = view.filter_instance.validated

    if not validated:
        return deepcopy(args)

    if not args:
        return deepcopy(validated)

    result = deepcopy(validated)
    for arg in deepcopy(args):
        if arg not in validated:
            result[arg] = args[arg]

    return result
Ejemplo n.º 4
0
def get_filter_nodes_to_omit(node, filter_):
    result_node = []
    for child in node.children:
        if hasattr(child, 'filter_analyzer'):
            filter_cp = deepcopy(filter_)
            result_child = child.filter_analyzer(filter_cp)
            if result_child:
                nodes_to_omit = [n for n in result_child.keys()
                                 if result_child[n]['is_unique']]
                result_node.append((child.name, nodes_to_omit))

    return result_node
Ejemplo n.º 5
0
def get_filter_nodes_to_omit(node, filter_):
    result_node = []
    for child in node.children:
        if hasattr(child, 'filter_analyzer'):
            filter_cp = deepcopy(filter_)
            result_child = child.filter_analyzer(filter_cp)
            if result_child:
                nodes_to_omit = [
                    n for n in result_child.keys()
                    if result_child[n]['is_unique']
                ]
                result_node.append((child.name, nodes_to_omit))

    return result_node
Ejemplo n.º 6
0
def get_analyzed_data(node, source, validated, ignore_node=False):
    result = {}
    for child in node.children:
        if hasattr(child, 'analyzer'):
            validated_cp = deepcopy(validated)
            if not ignore_node and child.name in validated_cp:
                validated_cp.pop(child.name)

            result_child = child.analyzer(child, source, validated_cp,
                                          validated.get(child.name, []))
            if result_child is not None:
                result.update(result_child)

    return result
Ejemplo n.º 7
0
def get_analyzed_data(node, source, validated, ignore_node=False):
    result = {}
    for child in node.children:
        if hasattr(child, 'analyzer'):
            validated_cp = deepcopy(validated)
            if not ignore_node and child.name in validated_cp:
                validated_cp.pop(child.name)

            result_child = child.analyzer(
                child, source, validated_cp,
                validated.get(child.name, []))
            if result_child is not None:
                result.update(result_child)

    return result
Ejemplo n.º 8
0
    def __call__(self):
        root = getSite()
        resources = deepcopy(
            getattr(self.request, 'resources', {
                'js_links': [],
                'css_links': []
            }))
        search_action, search_view = get_action_view('novaideoviewmanager',
                                                     'search', self.request)
        search_view_instance = search_view(root,
                                           self.request,
                                           behaviors=[search_action])
        posted_formid = None
        if self.request.POST:
            if '__formid__' in self.request.POST:
                posted_formid = self.request.POST['__formid__']

            if posted_formid and \
              posted_formid.startswith(search_view_instance.viewid):
                search_view_instance.postedform = self.request.POST.copy()
                self.request.POST.clear()

        search_view_result = search_view_instance()
        search_body = ''
        result = {'css_links': [], 'js_links': []}
        if isinstance(search_view_result, dict) and \
           'coordinates' in search_view_result:
            search_render = search_view_result['coordinates'][
                search_view_instance.coordinates][0]
            result['css_links'] = [
                c for c in search_view_result['css_links']
                if c not in resources['css_links']
            ]
            result['js_links'] = [
                c for c in search_view_result['js_links']
                if c not in resources['js_links']
            ]
            search_body = search_view_instance.render_item(
                search_render, search_view_instance.coordinates, None)

        result['search_body'] = search_body
        result['view'] = self
        update_resources(self.request, result)
        return result
Ejemplo n.º 9
0
    def __call__(self):
        root = getSite()
        resources = deepcopy(getattr(
            self.request, 'resources', {'js_links': [], 'css_links': []}))
        search_action, search_view = get_action_view('novaideoviewmanager',
                                                'search',
                                                self.request)
        search_view_instance = search_view(root, self.request,
                                           behaviors=[search_action])
        posted_formid = None
        if self.request.POST:
            if '__formid__' in self.request.POST:
                posted_formid = self.request.POST['__formid__']

            if posted_formid and \
              posted_formid.startswith(search_view_instance.viewid):
                search_view_instance.postedform = self.request.POST.copy()
                self.request.POST.clear()

        search_view_result = search_view_instance()
        search_body = ''
        result = {'css_links': [], 'js_links': []}
        if isinstance(search_view_result, dict) and \
           'coordinates' in search_view_result:
            search_render = search_view_result['coordinates'][search_view_instance.coordinates][0]
            result['css_links'] = [c for c in search_view_result['css_links']
                                   if c not in resources['css_links']]
            result['js_links'] = [c for c in search_view_result['js_links']
                                  if c not in resources['js_links']]
            search_body = search_view_instance.render_item(
                search_render,
                search_view_instance.coordinates,
                None)

        result['search_body'] = search_body
        result['view'] = self
        update_resources(self.request, result)
        return result