Exemple #1
0
def build_indexes():
    """Updates Whoosh indexes with latest posts.  This function should run
    on start-up preferrably.
    """
    index = create_in(config['pylons.cache_dir'], schema)
    writer = index.writer()
    for post in Post.all():
        writer.add_document(
            title=sanitize(post.title),
            # strip HTML tags so search results aren't comprised of partial
            # HTML tags thus ruining the page.
            content=sanitize(post.content),
            summary=u'%s' % (sanitize(post.summary),),
            url=json.dumps(
                {
                    'controller': 'blog',
                    'action': 'view',
                    'category': post.category.slug,
                    'slug': post.slug
                },
                ensure_ascii=False
            ),
            category=json.dumps(
                {
                'name': sanitize(post.category.title),
                'slug': post.category.slug
                },
                ensure_ascii=False
            )
        )
    writer.commit()
    return index
Exemple #2
0
def build_indexes():
    """Updates Whoosh indexes with latest posts.  This function should run
    on start-up preferrably.
    """
    index = create_in(config['pylons.cache_dir'], schema)
    writer = index.writer()
    for post in Post.all():
        writer.add_document(
            title=sanitize(post.title),
            # strip HTML tags so search results aren't comprised of partial
            # HTML tags thus ruining the page.
            content=sanitize(post.content),
            summary=u'%s' % (sanitize(post.summary), ),
            url=json.dumps(
                {
                    'controller': 'blog',
                    'action': 'view',
                    'category': post.category.slug,
                    'slug': post.slug
                },
                ensure_ascii=False),
            category=json.dumps(
                {
                    'name': sanitize(post.category.title),
                    'slug': post.category.slug
                },
                ensure_ascii=False))
    writer.commit()
    return index
Exemple #3
0
def strip_and_truncate(text, limit=200):
    try:
        text = sanitize(text)
    except Exception, e:
        #FIXME: Logg unrecoverable error
        #This is a bad exception that should never happen, if we translate it it will be hard to search in the source code
        return u"Unrecoverable error: could not truncate text"
Exemple #4
0
def strip_and_truncate(text, limit=200):
    try:
        text = sanitize(text)
    except Exception, e:
        #FIXME: Logg unrecoverable error
        #This is a bad exception that should never happen, if we translate it it will be hard to search in the source code
        return u"Unrecoverable error: could not truncate text"
Exemple #5
0
 def transform(self, text):
     """ Transform text. Base for any tags is current context. """
     text = sanitize(text)
     text = auto_link(text, link='urls')
     text = nl2br(text)
     text = tags2links(unicode(text))
     text = at_userid_link(text, self.context, self.request)
     return text
Exemple #6
0
 def transform(self, text):
     """ Transform text. Base for any tags is current context. """
     text = sanitize(text)
     text = auto_link(text, link='urls')
     text = nl2br(text)
     text = tags2links(unicode(text))
     text = at_userid_link(text, self.context, self.request)
     return text
Exemple #7
0
def evolve(root):
    """ Change all poll descriptions to plaintext. """
    from arche.interfaces import ICataloger
    from arche.utils import find_all_db_objects
    from webhelpers.html.render import sanitize

    #Move description to body
    root.body = root.description
    root.description = ""
    ICataloger(root).index_object()

    for obj in find_all_db_objects(root):
        if IPoll.providedBy(obj):
            #Turn description into plaintext
            obj.description = sanitize(obj.description)
            ICataloger(obj).index_object()
        elif IMeeting.providedBy(obj):
            #Move HTML field content to body
            obj.body = obj.description
            obj.description = ""
            ICataloger(obj).index_object()
Exemple #8
0
 def test_compare_strip_tags_to_sanitize(self):
     text = 'I <i>really</i> like <script language="javascript">NEFARIOUS CODE</script> steak!'
     eq_(strip_tags(text), render.sanitize(text))
Exemple #9
0
 def test_compare_strip_tags_to_sanitize(self):
     text = u'I <i>really</i> like <script language="javascript">NEFARIOUS CODE</script> steak!'
     eq_(strip_tags(text), render.sanitize(text))
Exemple #10
0
 def format_text(self, text):
     text = sanitize(text)
     text = auto_link(text)
     return nl2br(text)