Beispiel #1
0
def site_changes(request, feedtype=None):
    pages = all_pages(request.site._id)
    changes = get_changes(request.site._id)

    if feedtype == "atom":
        
        feed = AtomFeed(
                    title="%s: Latest changes" % request.site.title and request.site.title or request.site.cname,
                    subtitle=request.site.subtitle,
                    updated = changes[0].updated,
                    feed_url = request.url
        )
        for rev in changes:
            _url = "%s%s" % (request.host_url, url_for("show_page", pagename=rev.title.replace(' ', '_')))
            feed.add(rev.title, convert_markdown(rev.content), 
                updated=rev.updated,
                url=_url,
                id=_url,
                author=rev.title.replace(' ', '_')
            )
        return feed.get_response()
    elif feedtype == 'json':
        json = {
                'title': "%s: Latest changes" % request.site.title and request.site.title or request.site.cname,
                'subtitle': request.site.subtitle,
                'updated':datetime_tojson(changes[0].updated),
                'feed_url': request.url,
                'pages': []
            }
        for rev in changes:
            url = "%s%s" % (request.host_url, url_for("show_page", pagename=rev.title.replace(' ', '_')))
            json['pages'].append({
                'title': rev.title,
                'content': rev.content,
                'url':  url,
                'updated':datetime_tojson(rev.updated),
                'id':rev.title.replace(' ', '_')
            })
        return send_json(json)
    elif feedtype == 'rdf':
        site_title = request.site.title and request.site.title or request.site.cname
        site_url = request.host_url
        if not local.site_url:
            site_url += local.site_url
        
        sioc = SiocWiki(site_url, site_title, datetime_tojson(request.site.created))
        for rev in changes:
            _url = "%s%s" % (request.host_url, url_for("show_page", pagename=rev.title.replace(' ', '_')))
            sioc.add_page(rev.content, rev.title, _url, datetime_tojson(rev.updated))
        return send_sioc(sioc.to_str())

    return render_response('site/changes.html', changes=changes, pages=pages)
Beispiel #2
0
def show_page(request=None, pagename=None):
    mimetypes = request.accept_mimetypes
    
    if pagename is None:
        pagename ='home'
        
    #pagename = pagename.replace(" ", "_")

    redirect_from = request.values.get('redirect_from', '')
        
    page = get_page(request.site._id, pagename)
    if not page or page._id is None:
        alias = AliasPage.get_alias(request.site._id, pagename)
        if alias is not None:
            page = Page.get(alias.page)
            return redirect(url_for('show_page', 
            pagename=page.title.replace(' ', '_'),
            redirect_from=pagename))
            
   
    if not page or page._id is None:
        if pagename.lower() in FORBIDDEN_PAGES:
            redirect_url = "%s?error=%s" % (
                url_for('show_page', pagename='home'),
                u"Page name invalid."
            )
            return redirect(redirect_url)
        page = Page(
            site=request.site._id,
            title=pagename.replace("_", " ")
        )
    
    if mimeparse.best_match(['application/rdf+xml', 'text/xml', 'text/html'], 
    request.headers['ACCEPT']) == "application/rdf+xml":
        site_title = request.site.title and request.site.title or request.site.cname
        site_url = request.host_url
        if not local.site_url:
            site_url += local.site_url
        
        sioc = SiocWiki(site_url, site_title, datetime_tojson(request.site.created))
        sioc.add_page(page.content, page.title, request.url, datetime_tojson(page.updated))
        return send_sioc(sioc.to_str())

    # get all pages
    pages = all_pages(request.site._id)
    
    response = render_response('page/show.html', page=page, pages=pages, 
        lexers=LEXERS_CHOICE, redirect_from=redirect_from)
        
    return response