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'), }, }}
def edit_preview(request, dform=None, wiki=None): dajax = Dajax() if not dform or not wiki: return dajax.json() content = dform['content'] # 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 = md.convert(content) dajax.assign('#edit-preview', 'innerHTML', content) return dajax.json()
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'), }, }}