Beispiel #1
0
def summarize(value, size=None, cont=None):
    """Truncates the text to the specified size"""
    if size is None:
        size = settings.FEED_SUMMARY_SIZE
    if cont is None:
        cont = settings.FEED_SUMMARY_CONT
    size -= len(cont)
    value = text.sdecode(value)
    if value is not None:
        words = value[:size].split()
        if len(value) > size:
            words[-1] = cont
        value = mark_safe(u' '.join(words))
    return value
Beispiel #2
0
def summarize(value, size=None, cont=None):
    """Truncates the text to the specified size"""
    if size is None:
        size = settings.FEED_SUMMARY_SIZE
    if cont is None:
        cont = settings.FEED_SUMMARY_CONT
    size -= len(cont)
    value = text.sdecode(value)
    if value is not None:
        words = value[:size].split()
        if len(value) > size:
            words[-1] = cont
        value = mark_safe(u' '.join(words))
    return value
Beispiel #3
0
 def make_element(self, name, val=None, **attrib):
     """Created an element from params"""
     val = text.sdecode(val)
     if attrib.pop('cdata', False) and val:
         val = etree.CDATA(val)
     nsmap = attrib.pop('nsmap', None)
     resolve_ns = attrib.pop('resolve_ns', True)
     attrib = dict(i for i in (map(text.sdecode, i) for i in attrib.iteritems()) if None not in i)
     if resolve_ns:
         ns, _, tag = name.rpartition(':')
         ns = self.root.nsmap.get(ns)
         if ns:
             tag = '{%s}%s' % (ns, tag)
     else:
         tag = name
     element = etree.Element(tag, attrib, nsmap)
     element.text = val
     return element
Beispiel #4
0
 def make_element(self, name, val=None, **attrib):
     """Created an element from params"""
     val = text.sdecode(val)
     if attrib.pop('cdata', False) and val:
         val = etree.CDATA(val)
     nsmap = attrib.pop('nsmap', None)
     resolve_ns = attrib.pop('resolve_ns', True)
     attrib = dict(i for i in (map(text.sdecode, i)
                               for i in attrib.iteritems())
                   if None not in i)
     if resolve_ns:
         ns, _, tag = name.rpartition(':')
         ns = self.root.nsmap.get(ns)
         if ns:
             tag = '{%s}%s' % (ns, tag)
     else:
         tag = name
     element = etree.Element(tag, attrib, nsmap)
     if isinstance(val, unicode):
         val = val.replace(u'\x03', u'')  # XXX
     element.text = val
     return element