示例#1
0
def view_page(request, wiki, path):
    w = get_object_or_404(Wiki, slug=wiki)

    if not path:
        return {'REDIRECT': urljoin(request.path, settings.WIKI_INDEX)}

    # If path is a folder
    if w.repo.is_dir(path):
        if settings.WIKI_INDEX:
            return {'REDIRECT': urljoin(request.path, settings.WIKI_INDEX)}

        pages, name = r.get_tree(path)
        return {'wiki': {
            'name': name,
            'pages': pages,
            'obj': w
        }}

    real_path = u'{0}.md'.format(path)

    # If the page doesn't exist, redirect user to an edit page
    if not w.repo.exists(real_path):
        return {'REDIRECT': reverse('edit-page', args=[wiki, path])}

    # Generate markdown document
    extension = pompadourlinks.makeExtension([
        ('base_url', u'/wiki/{0}/'.format(wiki)),
        ('end_url', ''),
    ])

    md = markdown.Markdown(
        extensions = ['meta', 'codehilite', 'toc', extension],
        safe_mode = True
    )

    content, name, mimetype = w.repo.get_content(real_path)
    content = md.convert(content.decode('utf-8'))

    return {'wiki': {
        'name': os.path.splitext(name)[0],
        'path': path,
        'meta': md.Meta,
        'content': content,
        'history': w.repo.get_file_diffs(real_path),
        'obj': w,
        'attachments': Attachment.objects.filter(wiki=w, page=os.path.join(wiki, path)),
        'urls': {
            'edit': os.path.join(request.path, 'edit'),
            'remove': os.path.join(request.path, 'remove'),
        },
    }}
示例#2
0
def index(request, wiki, path):
    w = get_object_or_404(Wiki, slug=wiki)

    filelist = []

    # Get the folder path inside git repository
    if path:
        gitfolder = os.path.join('__media__', path)
    else:
        gitfolder = '__media__'

    # Check if the directory exists
    if w.repo.exists(gitfolder):
        # Get file list
        files = w.repo.get_folder_tree(gitfolder)

        # Append files to the list for the view
        for f in files:
            filelist.append({
                'url': urljoin(path, f['name']),
                'name': f['name'],
                'mimetype': f['type']
            })

    return {'wiki': {
        'files': filelist,
        'obj': w,
        'breadcrumbs': breadcrumbify(path),
        'forms': {
            'upload': UploadDocumentForm({})
        }
    }}
示例#3
0
def index(request, wiki, path):
    w = get_object_or_404(Wiki, slug=wiki)

    attach_page = request.GET.get('attach', settings.WIKI_INDEX)

    if not w.repo.exists(u'{0}.md'.format(attach_page)):
        attach_page = settings.WIKI_INDEX

    filelist = []

    # Get the folder path inside git repository
    if path:
        gitfolder = os.path.join('__media__', path)
    else:
        gitfolder = '__media__'

    # Check if the directory exists
    if w.repo.exists(gitfolder):
        # List directory
        directories, files = w.repo.listdir(gitfolder)

        # Append directories
        for d in directories:
            filelist.append({
                'url': urljoin(path, d.encode('utf-8')),
                'name': d,
                'mimetype': 'inode/directory'
            })

        # Append files
        for f in files:
            filelist.append({
                'url': urljoin(path, f.encode('utf-8')),
                'name': f,
                'mimetype': w.repo.mimetype(os.path.join(gitfolder, f))
            })

    return {'wiki': {
        'files': filelist,
        'obj': w,
        'attach_page': attach_page,
        'breadcrumbs': breadcrumbify(path),
        'forms': {
            'upload': UploadDocumentForm({})
        }
    }}
示例#4
0
    def test_for(mimetype):
        # Get the filename of the mimetype image
        filename = '{0}.png'.format('-'.join(mimetype.split('/')))

        path = os.path.join(settings.STATIC_ROOT, 'img', 'icons', filename)
        url = urljoin(settings.STATIC_URL, 'img', 'icons', filename)

        if os.path.exists(path):
            return redirect(url)
示例#5
0
    def test_for(mimetype):
        # Get the filename of the mimetype image
        filename = '{0}.png'.format('-'.join(mimetype.split('/')))

        path = os.path.join(settings.STATIC_ROOT, 'img', 'icons', filename)
        url = urljoin(settings.STATIC_URL, 'img', 'icons', filename)

        if os.path.exists(path):
            return redirect(url)
示例#6
0
def attach_doc(request, wiki=None, files=None, page=None):
    dajax = Dajax()

    if not wiki or not files or not page:
        return dajax.json()

    try:
        w = Wiki.objects.get(slug=wiki)
    except Wiki.DoesNotExist:
        return dajax.json()

    for f in files:
        a = Attachment()
        a.wiki = w
        a.page = urljoin(wiki, page)
        a.file = f
        a.mimetype = w.repo.get_file_mimetype(os.path.join('__media__', *f.split('/')))

        a.save()

    return dajax.json()
示例#7
0
def attach_doc(request, wiki=None, files=None, page=None):
    dajax = Dajax()

    if not wiki or not files or not page:
        return dajax.json()

    try:
        w = Wiki.objects.get(slug=wiki)
    except Wiki.DoesNotExist:
        return dajax.json()

    for f in files:
        a = Attachment()
        a.wiki = w
        a.page = urljoin(wiki, page)
        a.file = f
        a.mimetype = w.repo.get_file_mimetype(
            os.path.join('__media__', *f.split('/')))

        a.save()

    return dajax.json()
示例#8
0
def view_page(request, wiki, path):
    path = stripspecialchars(path)

    w = get_object_or_404(Wiki, slug=wiki)    

    if not path or w.repo.is_dir(path):
        return {'REDIRECT': urljoin(request.path, settings.WIKI_INDEX)}


    real_path = u'{0}.md'.format(path)

    # If the page doesn't exist, redirect user to an edit page
    if not w.repo.exists(real_path):
        return {'REDIRECT': reverse('edit-page', args=[wiki, path])}

    # Retrieve content from cache
    key = request.get_full_path()

    if not cache.has_key(key):
        # Generate markdown document
        extension = pompadourlinks.makeExtension([
            ('base_url', u'/wiki/{0}/'.format(wiki)),
            ('end_url', ''),
        ])

        md = markdown.Markdown(
            extensions = ['meta', 'codehilite', 'toc', extension],
            safe_mode = True
        )

        # Read content
        f = w.repo.open(real_path)
        content = f.read()
        f.close()

        name = real_path
        mimetype = w.repo.mimetype(real_path)

        f.close()

        content = md.convert(content.decode('utf-8'))
        meta = md.Meta

        cache.set(key, (content, name, mimetype, meta), cache.default_timeout)

    else:
        content, name, mimetype, meta = cache.get(key)

    # Retrieve diff history from cache
    key = u'diffs_{0}'.format(request.get_full_path())

    if not cache.has_key(key):
        diffs = w.repo.diffs(name=real_path, limit=-1)

        cache.set(key, diffs, cache.default_timeout)

    else:
        diffs = cache.get(key)

    return {'wiki': {
        'name': os.path.splitext(name)[0],
        'path': path,
        'meta': meta,
        'content': content,
        'history': diffs,
        'obj': w,
        'tags': Tag.objects.filter(page=os.path.join(wiki, path)),
        'attachments': Attachment.objects.filter(wiki=w, page=os.path.join(wiki, path)),
        'urls': {
            'edit': os.path.join(request.path, 'edit'),
            'remove': os.path.join(request.path, 'remove'),
        },
    }}