Example #1
0
def latest_post():
    '''Return the most recent blog post.

    Returns None if there are no blog posts.

    :rtype: ckanext.sweden.blog.model.post.Post or None

    '''
    try:
        from ckanext.sweden.blog.model.post import Post
        post = Session.query(Post).\
            filter(Post.visible == True).\
            order_by('created desc').\
            first()
    except NoResultFound:
        return None

    if post is None:
        return None

    post.content_markdown = markdown(
        unicode(truncate(post.content, length=320, indicator='...',
                         whole_word=True)))
    post.post_author = (model.User.get(post.user_id)
                        or Session.query(model.User).filter_by(
                        id=post.user_id).first())

    return post
Example #2
0
def markdown_extract(text):
    if (text is None) or (text == ''):
        return ''
    html = fromstring(markdown(text))
    plain = html.xpath("string()")
    return unicode(
        truncate(plain, length=190, indicator='...', whole_word=True))
Example #3
0
def markdown(text, **kwargs):
    """Format the text with MarkDown formatting
    
    This function uses the `Python MarkDown library <http://www.freewisdom.org/projects/python-markdown/>`_
    which is included with WebHelpers.
    
    """
    return _markdown.markdown(text, **kwargs)
Example #4
0
def markdown(text, **kwargs):
    """Format the text with MarkDown formatting
    
    This function uses the `Python MarkDown library <http://www.freewisdom.org/projects/python-markdown/>`_
    which is included with WebHelpers.
    
    """
    return _markdown.markdown(text, **kwargs)
Example #5
0
def markdown_extract(text, extract_length=190):
    if (text is None) or (text.strip() == ''):
        return ''
    plain = re.sub(r'<.*?>', '', markdown(text))
    return unicode(
        truncate(plain,
                 length=extract_length,
                 indicator='...',
                 whole_word=True))
Example #6
0
def markdown_extract(text, extract_length=190):
    """ return the plain text representation of markdown encoded text.  That
    is the texted without any html tags.  If extract_length is 0 then it
    will not be truncated."""
    if (text is None) or (text.strip() == ""):
        return ""
    plain = re.sub(r"<.*?>", "", markdown(text))
    if not extract_length or len(plain) < extract_length:
        return plain
    return literal(unicode(truncate(plain, length=extract_length, indicator="...", whole_word=True)))
Example #7
0
def markdown_wrap(text, extract_length=190):
    ''' return the plain text representation of markdown encoded text.  That
    is the texted without any html tags.  If extract_length is 0 then it
    will not be truncated.'''
    if (text is None) or (text.strip() == ''):
        return ''
    plain = RE_MD_HTML_TAGS.sub('', markdown(text))
    if not extract_length or len(plain) < extract_length:
        return literal(plain)
    return literal(unicode(wrap_paragraphs(plain, width=extract_length)))
Example #8
0
def markdown_wrap(text, extract_length=190):
    ''' return the plain text representation of markdown encoded text.  That
    is the texted without any html tags.  If extract_length is 0 then it
    will not be truncated.'''
    if (text is None) or (text.strip() == ''):
        return ''
    plain = RE_MD_HTML_TAGS.sub('', markdown(text))
    if not extract_length or len(plain) < extract_length:
        return literal(plain)
    return literal(unicode(wrap_paragraphs(plain, width=extract_length)))
Example #9
0
 def annotate(self):
     c.prefix = server_api + 'annotation'
     c.uri = 'make one up'
     # TODO: create text in the backend ...
     text = request.params.get('text', '')
     import webhelpers.markdown as md
     if text:
         c.content = md.markdown(text)
     else:
         c.content = ''
     out = render('annotate.html')
     # out is a webhelpers.html.builder.literal
     # we want to work with raw html ...
     out = anno_middleware.modify_html(unicode(out))
     return out
Example #10
0
    def read(self, title):
        try:
            from ckanext.sweden.blog.model.post import Post
            c.post = model.Session.query(Post).\
                filter(Post.url == title).\
                filter(Post.visible == True).\
                one()
        except NoResultFound:
            abort(404)

        c.content_markdown = markdown(c.post.content)
        c.post_author = (model.User.get(c.post.user_id)
                         or model.Session.query(model.User).filter_by(
                             id=c.post.user_id).first())

        return toolkit.render('blog/post.html')
Example #11
0
def markdown(text, **kwargs):
    """Format the text to HTML with MarkDown formatting.
    
    This function uses the `Python MarkDown library 
    <http://www.freewisdom.org/projects/python-markdown/>`_
    which is included with WebHelpers.  It does not include extensions
    due to circular import issues.  If you need the footnotes or RSS
    extensions, use the full Markdown package instead.  
    
    IMPORTANT:
    If your source text is untrusted and may contain malicious HTML markup,
    pass ``safe_mode="escape"`` to escape it, ``safe_mode="replace"`` to
    replace it with a scolding message, or ``safe_mode="remove"`` to strip it.

    There is at least one other Markdown package for Python.  python-markdown2
    (http://code.google.com/p/python-markdown2/), which claims to be faster and
    to handle edge cases better.  WebHelpers is sticking to the original Python
    Markdown for now for backward compatibility and because nobody has
    complained about the speed.
    """
    return literal(_markdown.markdown(text, **kwargs))
Example #12
0
def markdown(text, **kwargs):
    """Format the text to HTML with MarkDown formatting.
    
    This function uses the `Python MarkDown library 
    <http://www.freewisdom.org/projects/python-markdown/>`_
    which is included with WebHelpers.  It does not include extensions
    due to circular import issues.  If you need the footnotes or RSS
    extensions, use the full Markdown package instead.  
    
    IMPORTANT:
    If your source text is untrusted and may contain malicious HTML markup,
    pass ``safe_mode="escape"`` to escape it, ``safe_mode="replace"`` to
    replace it with a scolding message, or ``safe_mode="remove"`` to strip it.

    There is at least one other Markdown package for Python.  python-markdown2
    (http://code.google.com/p/python-markdown2/), which claims to be faster and
    to handle edge cases better.  WebHelpers is sticking to the original Python
    Markdown for now for backward compatibility and because nobody has
    complained about the speed.
    """
    return literal(_markdown.markdown(text, **kwargs))
Example #13
0
File: helpers.py Project: HHS/ckan
def markdown_extract(text, extract_length=190):
    if (text is None) or (text.strip() == ''):
        return ''
    plain = re.sub(r'<.*?>', '', markdown(text))
    return literal(unicode(truncate(plain, length=extract_length, indicator='...', whole_word=True)))
Example #14
0
 def markdown(self):
     text = request.POST['data']
     if text is None:
         abort(400)
     c.content = markdown(text)
     return render('/util/response.html')
Example #15
0
from ckanext.blog.authorize import blog_admin

log = getLogger(__name__)

def latest_post():
    try:
      from ckanext.blog.model.post import Post
      post = Session.query(Post).\
          filter(Post.visible == True).\
          order_by('created desc').\
          first()
    except NoResultFound, e:
      return None

    post.content_markdown = markdown(unicode(truncate(post.content, length=320, indicator='...', whole_word=True)))
    post.post_author = model.User.get(post.user_id) or Session.query(model.User).filter_by(id=post.user_id).first()
    return post

class BlogPlugin(p.SingletonPlugin):
    """This extension adds blogging functionality to ckan

    This extension implements four interfaces

      - ``IConfigurer`` allows to modify the configuration
      - ``IConfigurable`` get the configuration
      - ``IAuthFunctions`` to add custom authorization
      - ``IRoutes`` to add custom routes
    """
    p.implements(p.IConfigurer, inherit=True)
    p.implements(p.IConfigurable, inherit=True)
Example #16
0
def markdown_extract(text):
    if (text is None) or (text == ''):
        return ''
    html = fromstring(markdown(text))
    plain = html.xpath("string()")
    return unicode(truncate(plain, length=190, indicator='...', whole_word=True))
Example #17
0
def markdown_extract(text, extract_length=190):
    if (text is None) or (text.strip() == ""):
        return ""
    plain = re.sub(r"<.*?>", "", markdown(text))
    return literal(unicode(truncate(plain, length=extract_length, indicator="...", whole_word=True)))
Example #18
0
def markdown_extract(text, extract_length=190):
    if (text is None) or (text == ""):
        return ""
    html = fromstring(markdown(text))
    plain = html.xpath("string()")
    return unicode(truncate(plain, length=extract_length, indicator="...", whole_word=True))
Example #19
0
log = getLogger(__name__)


def latest_post():
    try:
        from ckanext.blog.model.post import Post
        post = Session.query(Post).\
            filter(Post.visible == True).\
            order_by('created desc').\
            first()
    except NoResultFound, e:
        return None

    post.content_markdown = markdown(
        unicode(
            truncate(post.content,
                     length=320,
                     indicator='...',
                     whole_word=True)))
    post.post_author = model.User.get(post.user_id) or Session.query(
        model.User).filter_by(id=post.user_id).first()
    return post


class BlogPlugin(p.SingletonPlugin):
    """This extension adds blogging functionality to ckan

    This extension implements four interfaces

      - ``IConfigurer`` allows to modify the configuration
      - ``IConfigurable`` get the configuration
      - ``IAuthFunctions`` to add custom authorization