コード例 #1
0
ファイル: cache.py プロジェクト: upiq/uu.formlibrary
def datapoint_cache_key(method, self, context):
    """
    Return four item tuple of UID/modified for each of measure, form
    context.  If measure or form is modified, key is naturally not
    up-to-date, which avoids struggles with invalidation if this key
    is consistently used in all places we might need to cache.

    Note: use string timestamps for cache keys, as they should consume
    half the space (persisted) or RAM as storing a DateTime 3.x object.
    """
    usebrain = isbrain(context)
    # consistent UID getter works with brains and form content:
    _uid = lambda o: o.UID if usebrain else IUUID(o)
    # consistent timestamp getter for content objects and brains:
    return (IUUID(self), modified(self), _uid(context), modified(context))
コード例 #2
0
ファイル: cache.py プロジェクト: mostscript/uu.formlibrary
def datapoint_cache_key(method, self, context):
    """
    Return four item tuple of UID/modified for each of measure, form
    context.  If measure or form is modified, key is naturally not
    up-to-date, which avoids struggles with invalidation if this key
    is consistently used in all places we might need to cache.

    Note: use string timestamps for cache keys, as they should consume
    half the space (persisted) or RAM as storing a DateTime 3.x object.
    """
    usebrain = isbrain(context)
    # consistent UID getter works with brains and form content:
    _uid = lambda o: o.UID if usebrain else IUUID(o)
    # consistent timestamp getter for content objects and brains:
    return (
        IUUID(self),
        modified(self),
        _uid(context),
        modified(context),
    )
コード例 #3
0
 def _datapoint(self, context):
     """uncached datapoint implementation"""
     if isbrain(context):
         context = get(context)
     n = m = None
     if (self._source_type() == MULTI_FORM_TYPE
             and self.denominator_type != 'constant'):
         n, m = self._mr_values(context)
         divide = lambda a, b: float(a) / float(b) if b else NOVALUE
         if n is None or not m:
             raw = NOVALUE
         else:
             raw = divide(n, m)
         normalized = self._normalize(raw)
     else:
         n, m = self._flex_values(context)
         raw, normalized = self._values(context)
     url = context.absolute_url()
     if 'nohost' in url:
         # in cases where a point is indexed in non-interactive session,
         # we need a real URL to work with, assumes that 'site_url'
         # property is set in portal_properties/site_properties
         siteid, baseurl = self._base()
         if baseurl:
             url = url.replace('http://nohost/%s' % siteid, baseurl)
     point_record = {
         'title': context.Title(),
         'url': url,
         'path': content_path(context),
         'start': context.start,
         'value': normalized,
         'raw_value': raw,
         'display_value': self.display_format(normalized),
         'user_notes': self.note_for(context),
     }
     if n is not None:
         point_record['raw_numerator'] = n
     if m is not None:
         point_record['raw_denominator'] = m
     return point_record
コード例 #4
0
ファイル: content.py プロジェクト: upiq/uu.formlibrary
 def _datapoint(self, context):
     """uncached datapoint implementation"""
     if isbrain(context):
         context = get(context)
     n = m = None
     if (self._source_type() == MULTI_FORM_TYPE and
             self.denominator_type != 'constant'):
         n, m = self._mr_values(context)
         divide = lambda a, b: float(a) / float(b) if b else NOVALUE
         if n is None or not m:
             raw = NOVALUE
         else:
             raw = divide(n, m)
         normalized = self._normalize(raw)
     else:
         n, m = self._flex_values(context)
         raw, normalized = self._values(context)
     url = context.absolute_url()
     if 'nohost' in url:
         # in cases where a point is indexed in non-interactive session,
         # we need a real URL to work with, assumes that 'site_url'
         # property is set in portal_properties/site_properties
         siteid, baseurl = self._base()
         if baseurl:
             url = url.replace('http://nohost/%s' % siteid, baseurl)
     point_record = {
         'title': context.Title(),
         'url': url,
         'path': content_path(context),
         'start': context.start,
         'value': normalized,
         'raw_value': raw,
         'display_value': self.display_format(normalized),
         'user_notes': self.note_for(context),
     }
     if n is not None:
         point_record['raw_numerator'] = n
     if m is not None:
         point_record['raw_denominator'] = m
     return point_record