Ejemplo n.º 1
0
def wiki_create_page(request):
    
    project = request.matchdict['project']
    page = request.matchdict['page']
    wikiroot = request.registry.settings['wiki.root']
    
    #determine the new page path:
    rootpath = os.path.join(wikiroot, project)
    filepath = os.path.join(rootpath,page)
    filepath += ".md"  #TODO: markdown only for the moment
    
    #create the new page, and parent directories if needed
    
    if "/" in page:
        dirname = os.path.split(page)[0]
        dirpath = os.path.join(rootpath, dirname)
        log.debug("creating directory %s"%dirpath)
        mkdir_p(dirpath)
    
    log.debug("creating file %s"%filepath)
    f = open(filepath, "w")
    f.write("please set some content here")
    f.close()
    
    return HTTPFound(custom_route_path(request, "edit", project=project, page=page))
Ejemplo n.º 2
0
def view_wiki(request):
    """this view returns the wiki page content
    """
    pagename = request.matchdict["page"]
    project = request.matchdict["project"]
    
    if pagename=='':
        return HTTPFound(request.route_path('view_wiki', project=project, page='Home'))
    
    try:
        content, ext = getPage(request, project, pagename)
    except RuntimeError:
        raise  #url contained unauthorized pattern (ie '../')
    except:  #the page could not be found
        mydict = dict(pagename = pagename, url="/createwiki/%s/%s"%(project, pagename) )
        raise HTTPNotFound()
    
    html = renderers[ext](unicode(content, 'utf-8'))
    
    #create list of wikis:
    wikiroot = request.registry.settings['wiki.root']  #from settings in .ini file.
    wikis = os.listdir(wikiroot)
    
    edit_url = custom_route_path(request, "edit", project=project, page=pagename)
        
    return {"wikis": wikis, "content": html, "format": formats[ext], "edit_url": edit_url, "project":project}
Ejemplo n.º 3
0
def edit_wiki(request):
    """this view displays the raw content of the edited file for editing
    """ 
    log.debug("calling edit_wiki")
    project = request.matchdict["project"]
    page = request.matchdict["page"]
    
    #construction of the wiki path
    wikiroot = request.registry.settings['wiki.root']  #from settings in .ini file.
    wikipath = os.path.join(wikiroot, project) #project name is the name of the git repository
    rootfilepath = os.path.join(wikipath, page) #we want one specific file into this directory

    files = glob.glob(rootfilepath+".*")  #list files with any extension
    log.debug(files)
    f = files[0]   #we take the first matching file, undertermined results if two files only differs by extension

    repo = Repo(wikipath)
    strfilename = str(os.path.split(f)[1])
        
    #create list of wikis:
    wikiroot = request.registry.settings['wiki.root']  #from settings in .ini file.
    wikis = os.listdir(wikiroot)
    
    f = os.path.relpath(f, wikipath).encode("ascii")
    commit_id = get_last_commit_id(repo, f)
    
    
    if "content" in request.POST:
        try:
           do_commit(request)
           return HTTPFound(custom_route_path(request, 'view_wiki', project=project, page=page) )
        except RuntimeError:
            request.session.flash("someone else seems to be edition the same file."
                                  "we don't support concurrent editing",
                                  queue="error")
            content = request.POST["content"]
        
    else:
        content,ext = getPage(request, project, page)
        content = unicode(content, 'utf-8')
    
    return {"wikis": wikis, "project": project, "content": content, "commit_id": commit_id}