Esempio n. 1
0
def theme_get_page(page_id):
    page = _get_page(page_id)
    page.content = html.to_html(page)
    # increase counter:
    page.read_count = page.read_count + counter.inc(page.id)
    categories = _get_categories()
    return dict(__navigation__=('/page/%s' % page_id,), page=page, categories=categories)
Esempio n. 2
0
 def on_publish(self, gadget, wavelet, is_draft=False):
     connection = models.Connection.get(wavelet.wave_id)
     if not connection:
         return False
     blogger = utils.Blogger.open(wavelet.wave_id, connection.owner)
     if not blogger:
         return False
     body = html.to_html(wavelet.root_blip)
     contents = _OUTPUT_TEMPLATE % {"body": body}
     blog = gadget.get_blog()
     post = blogger.publish(blog, connection.feed_link, wavelet.title, contents, is_draft)
     link = post.get_html_link()
     if link:
         url = link.href
         title = link.title
         if not connection.feed_link:
             connection.feed_link = post.get_self_link().href
             connection.html_link = url
             connection.put()
     else:
         url = None
         title = None
     gadget.set_url(url)
     gadget.set_title(title)
     tz = time.timezone
     if tz >= 0:
         sign = "+"
     else:
         sign = ""
     post_time = datetime.now().strftime("%a, %d %b %Y %H:%M:%S ") + sign + str(tz)
     gadget.set_post_time(post_time)
Esempio n. 3
0
def theme_get_article(article_id):
    article = _get_article(article_id)
    # todo: cache article content:
    article.content = html.to_html(article)
    # increase counter:
    article.read_count = article.read_count + counter.inc(article.id)
    categories = _get_categories()
    category_dict = dict()
    for cat in categories:
        category_dict[cat.id] = cat.name
    return dict(__navigation__=('/category/%s' % article.category_id, '/articles'), article=article, categories=categories, get_category_name=lambda cid: category_dict.get(cid, 'ERROR'))
Esempio n. 4
0
def wiki_by_id(wiki_id):
    wiki = _get_wiki(wiki_id)
    pages = _get_wikipages(wiki)
    return dict(
        __navigation__=("/wiki/%s" % wiki_id,),
        wiki=wiki,
        pages=pages,
        wiki_name=wiki.name,
        wiki_content=html.to_html(wiki),
        read_count=counter.inc(wiki.id),
    )
Esempio n. 5
0
def rss():
    ctx.response.content_type = 'application/rss+xml'
    limit = 20
    ss = setting.get_website_settings()
    description = ss['description']
    copyright = ss['copyright']
    domain = ctx.website.domain
    articles = _get_articles(1, 20)
    rss_time = articles and articles[0].creation_time or time.time()
    L = [
        '<?xml version="1.0"?>\n<rss version="2.0"><channel><title><![CDATA[',
        ctx.website.name,
        ']]></title><link>http://',
        domain,
        '/</link><description><![CDATA[',
        description,
        ']]></description><lastBuildDate>',
        _rss_datetime(rss_time),
        '</lastBuildDate><generator>iTranswarp</generator><ttl>30</ttl>'
    ]
    for a in articles:
        L.append('<item><title><![CDATA[')
        L.append(a.name)
        L.append(']]></title><link>http://')
        L.append(domain)
        L.append('/article/')
        L.append(a.id)
        L.append('</link><guid>http://')
        L.append(domain)
        L.append('/article/')
        L.append(a.id)
        L.append('</guid><author><![CDATA[')
        L.append(a.user_name)
        L.append(']]></author><pubDate>')
        L.append(_rss_datetime(a.creation_time))
        L.append('</pubDate><description><![CDATA[')
        L.append(html.to_html(a))
        L.append(']]></description></item>')
    L.append(r'</channel></rss>')
    return map(_safe_str, L)