def _getCriteriaArgs(self):
        context, request = self.context, self.request
        response = request.response

        query = context.buildQuery()
        topicCriteria = interfaces.IListCriterias(context)()
        listCriteria = context.listCriteria()
        args = {}
        if not query:
            return ({}, [])

        props = getToolByName(context, "portal_properties")
        charset = props and props.site_properties.default_charset or "utf-8"

        if "Type" in query.keys():
            items = getCookieItems(request, "Type", charset)
            if items:
                args["Type"] = items
            else:
                args["Type"] = query["Type"]
        elif "portal_type" in query.keys():
            items = getCookieItems(request, "portal_type", charset)
            if items:
                args["portal_type"] = items
            else:
                args["portal_type"] = query["portal_type"]
        filters = []
        # reinit cookies if criterions are no more there
        for cId in [c.Field() for c in listCriteria]:
            if cId not in topicCriteria.keys():
                response.expireCookie(cId)

        if request.cookies.get("sfqueryDisplay", None) not in topicCriteria.keys():
            response.expireCookie("sfqueryDisplay")

        for criteria in listCriteria:
            criteriaId = criteria.Field()
            if (
                criteria.meta_type
                not in ["ATSelectionCriterion", "ATListCriterion", "ATSortCriterion", "ATPortalTypeCriterion"]
                and criteriaId
            ):
                args[criteriaId] = query[criteriaId]
            elif (
                criteria.meta_type in ["ATSelectionCriterion", "ATListCriterion"]
                and criteria.getCriteriaItems()
                and len(criteria.getCriteriaItems()[0]) > 1
                and len(criteria.getCriteriaItems()[0][1]["query"]) > 0
            ):
                items = getCookieItems(request, criteriaId, charset)
                if items and criteriaId in topicCriteria.keys():
                    if "undefined" in items:
                        filters.append({"name": criteriaId, "values": items})
                    else:
                        args[criteriaId] = items
                else:
                    args[criteriaId] = query[criteriaId]

        return args, filters
Example #2
0
    def _getCriteriaArgs(self):
        context, request = self.context, self.request
        response = request.response

        query = context.buildQuery()
        topicCriteria = interfaces.IListCriterias(context)()
        listCriteria = context.listCriteria()
        _args = {}
        if not query:
            return ({}, [])

        props = getToolByName(context, 'portal_properties')
        charset = props and props.site_properties.default_charset or 'utf-8'

        if 'Type' in query.keys():
            items = getCookieItems(request, 'Type', charset)
            if items:
                _args['Type'] = items
            else:
                _args['Type'] = query['Type']
        elif 'portal_type' in query.keys():
            items = getCookieItems(request, 'portal_type', charset)
            if items:
                _args['portal_type'] = items
            else:
                _args['portal_type'] = query['portal_type']
        filters = []
        #reinit cookies if criterions are no more there
        for cId in [c.Field() for c in listCriteria]:
            if cId not in topicCriteria.keys():
                response.expireCookie(cId)

        if request.cookies.get('sfqueryDisplay',
                               None) not in topicCriteria.keys():
            response.expireCookie('sfqueryDisplay')

        for criteria in listCriteria:
            criteriaId = criteria.Field()
            if criteriaId and criteria.meta_type not in [
                    'ATSelectionCriterion', 'ATListCriterion',
                    'ATSortCriterion', 'ATPortalTypeCriterion'
            ]:
                _args[criteriaId] = query[criteriaId]
            elif criteria.meta_type in ['ATSelectionCriterion',
                                        'ATListCriterion'] \
               and criteria.getCriteriaItems() \
               and len(criteria.getCriteriaItems()[0]) > 1 \
               and len(criteria.getCriteriaItems()[0][1]['query']) > 0:
                items = getCookieItems(request, criteriaId, charset)
                if items and criteriaId in topicCriteria.keys():
                    if 'undefined' in items:
                        filters.append({'name': criteriaId, 'values': items})
                    else:
                        _args[criteriaId] = items
                else:
                    _args[criteriaId] = query[criteriaId]

        return _args, filters
    def _getCriteriaArgs(self):
        context, request = self.context, self.request
        response = request.response

        queryField = context.getField("query")
        listCriteria = queryField.getRaw(context)

        # Restrict for the presence of an operator-value in the query string to
        # avoid an error on the standard event folder, where no
        # querystring-value is given.
        # Don't include operator-only querystrings like, like relative date
        # queries for start/end dates.  For an calendar view, restricting on
        # start or end doesn't make much sense anyways
        query = dict([(a["i"], a["v"]) for a in listCriteria if "v" in a])

        topicCriteria = interfaces.IListCriterias(context)()
        args = {}
        if not query:
            return ({}, [])

        props = getToolByName(context, "portal_properties")
        charset = props and props.site_properties.default_charset or "utf-8"

        if "Type" in query.keys():
            items = getCookieItems(request, "Type", charset)
            if items:
                args["Type"] = items
            else:
                args["Type"] = query["Type"]
        filters = []
        # reinit cookies if criterions are no more there
        for cId in [c["i"] for c in listCriteria]:
            if cId not in topicCriteria.keys():
                response.expireCookie(cId)

        if request.cookies.get("sfqueryDisplay", None) not in topicCriteria.keys():
            response.expireCookie("sfqueryDisplay")

        for criteria in listCriteria:
            criteriaId = criteria["i"]
            if (
                criteria["o"]
                not in ["plone.app.querystring.operation.selection.is", "plone.app.querystring.operation.list.contains"]
                and criteriaId != "portal_type"
            ):
                args[criteriaId] = query[criteriaId]
            else:
                items = getCookieItems(request, criteriaId, charset)
                if items and criteriaId in topicCriteria.keys():
                    if "undefined" in items:
                        filters.append({"name": criteriaId, "values": items})
                    else:
                        args[criteriaId] = items
                else:
                    args[criteriaId] = query[criteriaId]

        return args, filters
    def _getCriteriaArgs(self):
        context, request = self.context, self.request
        response = request.response

        query = context.buildQuery()
        topicCriteria = interfaces.IListCriterias(context)()
        listCriteria = context.listCriteria()
        _args = {}
        if not query:
            return ({}, [])

        props = getToolByName(context, 'portal_properties')
        charset = props and props.site_properties.default_charset or 'utf-8'

        if 'Type' in query.keys():
            items = getCookieItems(request, 'Type', charset)
            if items:
                _args['Type'] = items
            else:
                _args['Type'] = query['Type']
        elif 'portal_type' in query.keys():
            items = getCookieItems(request, 'portal_type', charset)
            if items:
                _args['portal_type'] = items
            else:
                _args['portal_type'] = query['portal_type']
        filters = []
        #reinit cookies if criterions are no more there
        for cId in [c.Field() for c in listCriteria]:
            if cId not in topicCriteria.keys():
                response.expireCookie(cId)

        if request.cookies.get('sfqueryDisplay', None) not in topicCriteria.keys():
            response.expireCookie('sfqueryDisplay')

        for criteria in listCriteria:
            criteriaId = criteria.Field()
            if criteriaId and criteria.meta_type not in ['ATSelectionCriterion',
                                                         'ATListCriterion',
                                                         'ATSortCriterion',
                                                         'ATPortalTypeCriterion']:
                _args[criteriaId] = query[criteriaId]
            elif criteria.meta_type in ['ATSelectionCriterion',
                                        'ATListCriterion'] \
               and criteria.getCriteriaItems() \
               and len(criteria.getCriteriaItems()[0]) > 1 \
               and len(criteria.getCriteriaItems()[0][1]['query']) > 0:
                items = getCookieItems(request, criteriaId, charset)
                if items and criteriaId in topicCriteria.keys():
                    if 'undefined' in items:
                        filters.append({'name':criteriaId, 'values':items})
                    else:
                        _args[criteriaId] = items
                else:
                    _args[criteriaId] = query[criteriaId]

        return _args, filters
Example #5
0
    def _getCriteriaArgs(self):
        context, request = self.context, self.request
        response = request.response

        listCriteria = context.query

        # Handle operator-only query strings accordingly.
        # Also convert to str since unicode breaks the catalog-query
        query = dict([
            'v' in a and (str(a['i']), [str(value) for value in a['v']])
            or (str(a['i']), [str(value) for value in a['o']])
            for a in listCriteria
        ])

        topicCriteria = interfaces.IListCriterias(context)()
        _args = {}
        if not query:
            return ({}, [])

        props = getToolByName(context, 'portal_properties')
        charset = props and props.site_properties.default_charset or 'utf-8'

        if 'Type' in query.keys():
            items = getCookieItems(request, 'Type', charset)
            if items:
                _args['Type'] = items
            else:
                _args['Type'] = query['Type']
        filters = []
        #reinit cookies if criterions are no more there
        for cId in [c['i'] for c in listCriteria]:
            if cId not in topicCriteria.keys():
                response.expireCookie(cId)

        if request.cookies.get('sfqueryDisplay',
                               None) not in topicCriteria.keys():
            response.expireCookie('sfqueryDisplay')

        for criteria in listCriteria:
            criteriaId = criteria['i']
            if criteria['o'] not in \
               ['plone.app.querystring.operation.selection.is',
                'plone.app.querystring.operation.list.contains'] \
               and criteriaId != 'portal_type':
                _args[criteriaId] = query[criteriaId]
            else:
                items = getCookieItems(request, criteriaId, charset)
                if items and criteriaId in topicCriteria.keys():
                    if 'undefined' in items:
                        filters.append({'name': criteriaId, 'values': items})
                    else:
                        _args[criteriaId] = items
                else:
                    _args[criteriaId] = query[criteriaId]

        return _args, filters
    def _getCriteriaArgs(self):
        context, request = self.context, self.request
        response = request.response

        listCriteria = context.query

        # Handle operator-only query strings accordingly.
        # Also convert to str since unicode breaks the catalog-query
        query = dict(['v' in a and (str(a['i']),
            [str(value) for value in a['v']]) or
            (str(a['i']), [str(value) for value in a['o']])
            for a in listCriteria])

        topicCriteria = interfaces.IListCriterias(context)()
        _args = {}
        if not query:
            return ({}, [])

        props = getToolByName(context, 'portal_properties')
        charset = props and props.site_properties.default_charset or 'utf-8'

        if 'Type' in query.keys():
            items = getCookieItems(request, 'Type', charset)
            if items:
                _args['Type'] = items
            else:
                _args['Type'] = query['Type']
        filters = []
        #reinit cookies if criterions are no more there
        for cId in [c['i'] for c in listCriteria]:
            if cId not in topicCriteria.keys():
                response.expireCookie(cId)

        if request.cookies.get('sfqueryDisplay', None) not in topicCriteria.keys():
            response.expireCookie('sfqueryDisplay')

        for criteria in listCriteria:
            criteriaId = criteria['i']
            if criteria['o'] not in \
               ['plone.app.querystring.operation.selection.is',
                'plone.app.querystring.operation.list.contains'] \
               and criteriaId != 'portal_type':
                _args[criteriaId] = query[criteriaId]
            else:
                items = getCookieItems(request, criteriaId, charset)
                if items and criteriaId in topicCriteria.keys():
                    if 'undefined' in items:
                        filters.append({'name':criteriaId, 'values':items})
                    else:
                        _args[criteriaId] = items
                else:
                    _args[criteriaId] = query[criteriaId]

        return _args, filters
Example #7
0
    def _getCriteriaArgs(self):
        context, request = self.context, self.request
        response = request.response

        listCriteria = context.query

        query = dict([(key, convert(value))
                      for key, value in queryparser.parseFormquery(
                          context, listCriteria).items()])

        topicCriteria = interfaces.IListCriterias(context)()
        _args = {}
        if not query:
            return ({}, [])

        props = getToolByName(context, 'portal_properties')
        charset = props and props.site_properties.default_charset or 'utf-8'

        if 'Type' in query.keys():
            items = getCookieItems(request, 'Type', charset)
            if items:
                _args['Type'] = items
            else:
                _args['Type'] = query['Type']
        filters = []
        #reinit cookies if criterions are no more there
        for cId in [c['i'] for c in listCriteria]:
            if cId not in topicCriteria.keys():
                response.expireCookie(cId)

        if request.cookies.get('sfqueryDisplay',
                               None) not in topicCriteria.keys():
            response.expireCookie('sfqueryDisplay')

        for criteria in listCriteria:
            criteriaId = criteria['i']
            if criteria['o'] not in \
               ['plone.app.querystring.operation.selection.is',
                'plone.app.querystring.operation.list.contains'] \
               and criteriaId != 'portal_type':
                _args[criteriaId] = query[criteriaId]
            else:
                items = getCookieItems(request, criteriaId, charset)
                if items and criteriaId in topicCriteria.keys():
                    if 'undefined' in items:
                        filters.append({'name': criteriaId, 'values': items})
                    else:
                        _args[criteriaId] = items
                else:
                    _args[criteriaId] = query[criteriaId]

        return _args, filters
    def _getCriteriaArgs(self):
        context, request = self.context, self.request
        response = request.response

        listCriteria = context.query

        query = dict([
            (key, convert(value))
            for key, value in queryparser.parseFormquery(context, listCriteria).items()
        ])

        topicCriteria = interfaces.IListCriterias(context)()
        _args = {}
        if not query:
            return ({}, [])

        props = getToolByName(context, 'portal_properties')
        charset = props and props.site_properties.default_charset or 'utf-8'

        if 'Type' in query.keys():
            items = getCookieItems(request, 'Type', charset)
            if items:
                _args['Type'] = items
            else:
                _args['Type'] = query['Type']
        filters = []
        #reinit cookies if criterions are no more there
        for cId in [c['i'] for c in listCriteria]:
            if cId not in topicCriteria.keys():
                response.expireCookie(cId)

        if request.cookies.get('sfqueryDisplay', None) not in topicCriteria.keys():
            response.expireCookie('sfqueryDisplay')

        for criteria in listCriteria:
            criteriaId = criteria['i']
            if criteria['o'] not in \
               ['plone.app.querystring.operation.selection.is',
                'plone.app.querystring.operation.list.contains'] \
               and criteriaId != 'portal_type':
                _args[criteriaId] = query[criteriaId]
            else:
                items = getCookieItems(request, criteriaId, charset)
                if items and criteriaId in topicCriteria.keys():
                    if 'undefined' in items:
                        filters.append({'name':criteriaId, 'values':items})
                    else:
                        _args[criteriaId] = items
                else:
                    _args[criteriaId] = query[criteriaId]

        return _args, filters
Example #9
0
    def _getCriteriaArgs(self):
        context, request = self.context, self.request
        response = request.response

        query = context.buildQuery()
        topicCriteria = listQueryTopicCriteria(context)
        args = {}
        if not query:
            return ({}, [])

        for fname in ['portal_type', 'Type']:
            if fname in query.keys():
                items = getCookieItems(request, fname)
                if items:
                    args[fname] = items
                else:
                    args[fname] = query[fname]

        filters = []
        #reinit cookies if criterions are no more there
        for criteria in context.listCriteria():
            if criteria not in listQueryTopicCriteria(context):
                response.expireCookie(criteria.Field())

        if request.cookies.get('sfqueryDisplay',
                               None) not in [a.Field() for a in topicCriteria]:
            response.expireCookie('sfqueryDisplay')

        for criteria in self.context.listCriteria():
            if criteria.meta_type not in [
                    'ATSelectionCriterion', 'ATListCriterion',
                    'ATSortCriterion', 'ATPortalTypeCriterion'
            ] and criteria.Field():
                args[criteria.Field()] = query[criteria.Field()]
            elif criteria.meta_type in [
                    'ATSelectionCriterion', 'ATListCriterion'
            ] and criteria.getCriteriaItems() and len(
                    criteria.getCriteriaItems()[0]) > 1 and len(
                        criteria.getCriteriaItems()[0][1]['query']) > 0:
                items = getCookieItems(request, criteria.Field())
                if items and criteria in topicCriteria:
                    if 'undefined' in items:
                        filters.append({
                            'name': criteria.Field(),
                            'values': items
                        })
                    else:
                        args[criteria.Field()] = items
                else:
                    args[criteria.Field()] = query[criteria.Field()]

        return args, filters
Example #10
0
    def getColorIndex(self):
        context, request, brain = self.context, self.request, self.source
        criteriaItems = getCriteriaItems(context, request)
        colorIndex = ''
        if not criteriaItems:
            return colorIndex

        selectedItems = getCookieItems(request, criteriaItems['name'])
        if not selectedItems:
            selectedItems = criteriaItems['values']

        if not isinstance(selectedItems, list):
            selectedItems = [
                selectedItems,
            ]

        if criteriaItems:
            brainVal = getattr(brain, criteriaItems['name'])
            brainVal = isinstance(brainVal, (tuple, list)) and brainVal or [
                brainVal,
            ]
            for val in brainVal:
                if criteriaItems['values'].count(
                        val) != 0 and val in selectedItems:
                    colorIndex = 'colorIndex-' + str(
                        criteriaItems['values'].index(val))
                    colorIndex += ' ' + criteriaItems[
                        'name'] + 'colorIndex-' + str(
                            criteriaItems['values'].index(val))
                    break

        return colorIndex
    def getColorIndex(self):
        context, request, brain = self.context, self.request, self.source
        criteriaItems = getMultiAdapter((context, request), interfaces.ICriteriaItems)()
        final = {"color": "", "class": ""}
        if not criteriaItems:
            return final.copy()
        colorsDict = self.calendar.queryColors or {}

        props = getToolByName(self.context, "portal_properties")
        charset = props and props.site_properties.default_charset or "utf-8"
        selectedItems = getCookieItems(request, criteriaItems["name"], charset)
        if not selectedItems:
            selectedItems = criteriaItems["values"]

        if not isinstance(selectedItems, list):
            selectedItems = [selectedItems]
        final = {}
        if criteriaItems:
            brainVal = getattr(brain, criteriaItems["name"])
            brainVal = isinstance(brainVal, (tuple, list)) and brainVal or [brainVal]
            valColorsDict = colorsDict.get(criteriaItems["name"], {})
            for val in brainVal:
                if criteriaItems["values"].count(val) != 0 and val in selectedItems:
                    final["color"] = colorsDict.get(criteriaItems["name"], {}).get(val, "")
                    colorIndex = " colorIndex-" + str(criteriaItems["values"].index(val))
                    colorIndex += " " + criteriaItems["name"] + "colorIndex-" + str(criteriaItems["values"].index(val))
                    final["class"] = colorIndex
        return final.copy()
    def getColorIndex(self):
        context, request, brain = self.context, self.request, self.source
        availableSubFolders = getattr(self.calendar, "availableSubFolders", [])
        final = {"color": "", "class": ""}
        if not availableSubFolders:
            return final.copy()
        colorsDict = self.calendar.queryColors

        props = getToolByName(self.context, "portal_properties")
        charset = props and props.site_properties.default_charset or "utf-8"
        selectedItems = getCookieItems(request, "subFolders", charset)
        if not selectedItems:
            selectedItems = availableSubFolders

        if not isinstance(selectedItems, list):
            selectedItems = [selectedItems]
        for val in availableSubFolders:
            if val in selectedItems:
                for parentid in brain.getPath().split("/"):
                    if val == parentid:
                        final["color"] = colorsDict.get("subFolders", {}).get(val, "")
                        colorIndex = " colorIndex-" + str(availableSubFolders.index(val))
                        colorIndex += " subFolderscolorIndex-" + str(availableSubFolders.index(val))
                        final["class"] = colorIndex

        return final.copy()
Example #13
0
    def getColorIndex(self):
        context, request, brain = self.context, self.request, self.source
        criteriaItems = getMultiAdapter((context, request),
                                        interfaces.ICriteriaItems)()
        final = {'color':'',
                 'class':''}
        if not criteriaItems:
            return final.copy()
        colorsDict = self.calendar.queryColors

        props = getToolByName(self.context, 'portal_properties')
        charset = props and props.site_properties.default_charset or 'utf-8'
        selectedItems = getCookieItems(request, criteriaItems['name'], charset)
        if not selectedItems:
            selectedItems = criteriaItems['values']

        if not isinstance(selectedItems, list):
            selectedItems = [selectedItems, ]
        final = {}
        if criteriaItems:
            brainVal = getattr(brain, criteriaItems['name'])
            brainVal = isinstance(brainVal, (tuple, list)) and brainVal or [brainVal, ]
            valColorsDict = colorsDict.get(criteriaItems['name'], {})
            for val in brainVal:
                if criteriaItems['values'].count(val) != 0 \
                   and val in selectedItems:
                    final['color'] = colorsDict.get(criteriaItems['name'], {}).get(val, '')
                    colorIndex = ' colorIndex-%s' % criteriaItems['values'].index(val)
                    colorIndex += ' ' + criteriaItems['name'] + colorIndex
                    final['class'] = colorIndex
        return final.copy()
Example #14
0
    def getColorIndex(self):
        context, request, brain = self.context, self.request, self.source
        availableSubFolders = getattr(self.calendar, 'availableSubFolders', [])
        final = {'color':'',
                 'class':''}
        if not availableSubFolders:
            return final.copy()
        colorsDict = self.calendar.queryColors

        props = getToolByName(self.context, 'portal_properties')
        charset = props and props.site_properties.default_charset or 'utf-8'
        selectedItems = getCookieItems(request, 'subFolders', charset)
        if not selectedItems:
            selectedItems = availableSubFolders

        if not isinstance(selectedItems, list):
            selectedItems = [selectedItems, ]
        for val in availableSubFolders:
            if val not in selectedItems:
                continue
            for parentid in brain.getPath().split('/'):
                if val != parentid:
                    continue
                final['color'] = colorsDict.get('subFolders', {}).get(val, '')
                colorIndex = ' colorIndex-%s' % availableSubFolders.index(val)
                colorIndex += ' subFolderscolorIndex-%s' % availableSubFolders.index(val)
                final['class'] = colorIndex
        return final.copy()
    def _getCriteriaArgs(self):
        context, request = self.context, self.request
        response = request.response

        query = context.buildQuery()
        topicCriteria = listQueryTopicCriteria(context)
        args = {}
        if not query:
            return ({}, [])

        for fname in ['portal_type', 'Type']:
            if fname in query.keys():
                items = getCookieItems(request, fname)
                if items:
                    args[fname] = items
                else:
                    args[fname] = query[fname]

        filters = []
        #reinit cookies if criterions are no more there
        for criteria in context.listCriteria():
            if criteria not in listQueryTopicCriteria(context):
                response.expireCookie(criteria.Field())

        if request.cookies.get('sfqueryDisplay', None) not in [a.Field() for a in topicCriteria]:
            response.expireCookie('sfqueryDisplay')

        for criteria in self.context.listCriteria():
            if criteria.meta_type not in ['ATSelectionCriterion', 'ATListCriterion', 'ATSortCriterion', 'ATPortalTypeCriterion'] and criteria.Field():
                args[criteria.Field()] = query[criteria.Field()]
            elif criteria.meta_type in ['ATSelectionCriterion', 'ATListCriterion'] and criteria.getCriteriaItems() and len(criteria.getCriteriaItems()[0])>1 and len(criteria.getCriteriaItems()[0][1]['query'])>0:
                items = getCookieItems(request, criteria.Field())
                if items and criteria in topicCriteria:
                    if 'undefined' in items:
                        filters.append({'name':criteria.Field(), 'values':items})
                    else:
                        args[criteria.Field()] = items
                else:
                    args[criteria.Field()] = query[criteria.Field()]

        return args, filters
Example #16
0
    def getColorIndex(self):
        context, request, brain = self.context, self.request, self.source
        criteriaItems = getCriteriaItems(context, request)
        colorIndex = ''
        if not criteriaItems:
            return colorIndex

        selectedItems = getCookieItems(request, criteriaItems['name'])
        if not selectedItems:
            selectedItems = criteriaItems['values']

        if not isinstance(selectedItems, list):
            selectedItems = [selectedItems,]

        if criteriaItems:
            brainVal = getattr(brain, criteriaItems['name'])
            brainVal = isinstance(brainVal, (tuple, list)) and brainVal or [brainVal,]
            for val in brainVal:
                if criteriaItems['values'].count(val) != 0 and val in selectedItems:
                    colorIndex = 'colorIndex-'+str(criteriaItems['values'].index(val))
                    colorIndex += ' '+criteriaItems['name']+'colorIndex-'+str(criteriaItems['values'].index(val))
                    break

        return colorIndex
Example #17
0
 def getCookieItems(self, field):
     props = getToolByName(self.context, 'portal_properties')
     charset = props and props.site_properties.default_charset or 'utf-8'
     return getCookieItems(self.request, field, charset)
Example #18
0
 def getCookieItems(self, field):
     props = getToolByName(self.context, 'portal_properties')
     charset = props and props.site_properties.default_charset or 'utf-8'
     return getCookieItems(self.request, field, charset)