Beispiel #1
0
 def __init__(self, context, request):
     self.context = context
     self.request = request
     self.portal = getSite()
     self.comparators = Comparators(request)
     self.status = IStatusMessage(self.request)
     self.schema = IFormDefinition(self.context).schema
Beispiel #2
0
 def __init__(self, context, request):
     self.context = context
     self.request = request
     self.portal = getSite()
     self.comparators = Comparators(request)
     self.status = IStatusMessage(self.request)
     self.schema = IFormDefinition(self.context).schema
Beispiel #3
0
 def __init__(self, context, request=None):
     self.context = context
     self.request = None
     self.version = API_VERSION
     self.comparators = Comparators(request)
     self.fields = SearchableFields(context, request)
     self._capabilities_security_context()
Beispiel #4
0
class MeasureCriteriaView(object):

    def __init__(self, context, request):
        self.context = context
        self.request = request
        self.portal = getSite()
        self.comparators = Comparators(request)
        self.status = IStatusMessage(self.request)
        self.schema = IFormDefinition(self.context).schema

    def _update(self, *args, **kwargs):
        req = self.request
        prefix = 'payload-query-'
        payload_keys = [k for k in self.request.form if k.startswith(prefix)]
        if not payload_keys:
            return
        _info = lambda name: (name.replace(prefix, ''), req.get(name))
        payloads = map(_info, payload_keys)
        log_messages = []
        for name, payload in payloads:
            composed = self.composed_query(name)
            if not composed:
                raise ValueError('unknown query name')
            adapter = ComposedQueryJSONAdapter(composed, self.schema)
            adapter.update(str(payload))
            msg = u'Updated query criteria for %s' % name
            self.status.addStatusMessage(msg, type='info')
            log_messages.append(msg)
        history_log(
            self.context,
            message='\n'.join(log_messages),
            set_modified=True,
            )
        return True   # updated

    def update(self, *args, **kwargs):
        req = self.request
        if req.get('REQUEST_METHOD') != 'POST':
            return
        updated = self._update(*args, **kwargs)
        if updated:
            notify(ObjectModifiedEvent(self.context))
            req.response.redirect(self.context.absolute_url())  # to view tab

    def __call__(self, *args, **kwargs):
        self.update(*args, **kwargs)
        return self.index(*args, **kwargs)

    def portalurl(self):
        return self.portal.absolute_url()

    def include_queries(self):
        include = []
        if self.context.numerator_type == 'multi_filter':
            include.append('numerator')
        if self.context.denominator_type == 'multi_filter':
            include.append('denominator')
        return include

    def composed_query(self, name):
        return queryAdapter(self.context, IComposedQuery, name=name)

    def composed_queries(self):
        return [self.composed_query(name) for name in self.include_queries()]

    def get_filter(self, name):
        match = [info for info in self.filters() if info.get('uid') == name]
        if not match:
            return None
        return match[0].get('filter')

    def find_filters(self, composed):
        r = []
        for group in composed:
            for rfilter in group:
                r.append(rfilter)
        return r

    def filter_groupname(self, rfilter):
        uid = IUUID(rfilter)
        r = [d.get('groupname') for d in self._filters if d.get('uid') == uid]
        return r[0]

    def filters(self):
        if not hasattr(self, '_filters'):
            self._filters = []
            included = self.include_queries()
            for name in included:
                title = name.title()
                composed = self.composed_query(name)
                found = self.find_filters(composed)
                if found:
                    rfilter = found[0]
                    self._filters.append({
                        'groupname': name,
                        'uid': IUUID(rfilter),
                        'title': title,
                        'filter': rfilter,
                        })
        return self._filters

    def filter_json(self, name):
        """Get JSON payload for record filter, by name (uid)"""
        match = [info for info in self.filters() if info.get('uid') == name]
        if not match:
            return '{}'   # no matching filter
        rfilter = match[0].get('filter')
        return FilterJSONAdapter(rfilter, self.schema).serialize()

    def composed_json(self, name):
        composed = self.composed_query(name)
        return ComposedQueryJSONAdapter(composed, self.schema).serialize()

    def json(self, name):
        return self.composed_json(name)

    def comparator_title(self, comparator):
        return self.comparators.get(comparator).label

    def comparator_symbol(self, comparator):
        return self.comparators.get(comparator).symbol
Beispiel #5
0
class MeasureCriteriaView(object):
    def __init__(self, context, request):
        self.context = context
        self.request = request
        self.portal = getSite()
        self.comparators = Comparators(request)
        self.status = IStatusMessage(self.request)
        self.schema = IFormDefinition(self.context).schema

    def _update(self, *args, **kwargs):
        req = self.request
        prefix = 'payload-query-'
        payload_keys = [k for k in self.request.form if k.startswith(prefix)]
        if not payload_keys:
            return
        _info = lambda name: (name.replace(prefix, ''), req.get(name))
        payloads = map(_info, payload_keys)
        log_messages = []
        for name, payload in payloads:
            composed = self.composed_query(name)
            if not composed:
                raise ValueError('unknown query name')
            adapter = ComposedQueryJSONAdapter(composed, self.schema)
            adapter.update(str(payload))
            msg = u'Updated query criteria for %s' % name
            self.status.addStatusMessage(msg, type='info')
            log_messages.append(msg)
        history_log(
            self.context,
            message='\n'.join(log_messages),
            set_modified=True,
        )
        return True  # updated

    def update(self, *args, **kwargs):
        req = self.request
        if req.get('REQUEST_METHOD') != 'POST':
            return
        updated = self._update(*args, **kwargs)
        if updated:
            notify(ObjectModifiedEvent(self.context))
            req.response.redirect(self.context.absolute_url())  # to view tab

    def __call__(self, *args, **kwargs):
        self.update(*args, **kwargs)
        return self.index(*args, **kwargs)

    def portalurl(self):
        return self.portal.absolute_url()

    def include_queries(self):
        include = []
        if self.context.numerator_type == 'multi_filter':
            include.append('numerator')
        if self.context.denominator_type == 'multi_filter':
            include.append('denominator')
        return include

    def composed_query(self, name):
        return queryAdapter(self.context, IComposedQuery, name=name)

    def composed_queries(self):
        return [self.composed_query(name) for name in self.include_queries()]

    def get_filter(self, name):
        match = [info for info in self.filters() if info.get('uid') == name]
        if not match:
            return None
        return match[0].get('filter')

    def find_filters(self, composed):
        r = []
        for group in composed:
            for rfilter in group:
                r.append(rfilter)
        return r

    def filter_groupname(self, rfilter):
        uid = IUUID(rfilter)
        r = [d.get('groupname') for d in self._filters if d.get('uid') == uid]
        return r[0]

    def filters(self):
        if not hasattr(self, '_filters'):
            self._filters = []
            included = self.include_queries()
            for name in included:
                title = name.title()
                composed = self.composed_query(name)
                found = self.find_filters(composed)
                if found:
                    rfilter = found[0]
                    self._filters.append({
                        'groupname': name,
                        'uid': IUUID(rfilter),
                        'title': title,
                        'filter': rfilter,
                    })
        return self._filters

    def filter_json(self, name):
        """Get JSON payload for record filter, by name (uid)"""
        match = [info for info in self.filters() if info.get('uid') == name]
        if not match:
            return '{}'  # no matching filter
        rfilter = match[0].get('filter')
        return FilterJSONAdapter(rfilter, self.schema).serialize()

    def composed_json(self, name):
        composed = self.composed_query(name)
        return ComposedQueryJSONAdapter(composed, self.schema).serialize()

    def json(self, name):
        return self.composed_json(name)

    def comparator_title(self, comparator):
        return self.comparators.get(comparator).label

    def comparator_symbol(self, comparator):
        return self.comparators.get(comparator).symbol