def personal_wiki(request, page_name="home"): username = request.user.username wiki_exists = True try: content, repo, dirent = get_personal_wiki_page(username, page_name) except WikiDoesNotExist: wiki_exists = False owned_repos = seafile_api.get_owned_repo_list(username) owned_repos = [r for r in owned_repos if not r.encrypted] return render_to_response("wiki/personal_wiki.html", { "wiki_exists": wiki_exists, "owned_repos": owned_repos, }, context_instance=RequestContext(request)) except WikiPageMissing: repo = get_personal_wiki_repo(username) filename = clean_page_name(page_name) + '.md' if not seaserv.post_empty_file(repo.id, "/", filename, username): return render_error( request, _("Failed to create wiki page. Please retry later.")) return HttpResponseRedirect(reverse('personal_wiki', args=[page_name])) else: url_prefix = reverse('personal_wiki', args=[]) content = convert_wiki_link(content, url_prefix, repo.id, username) # fetch file latest contributor and last modified path = '/' + dirent.obj_name file_path_hash = hashlib.md5(urllib2.quote( path.encode('utf-8'))).hexdigest()[:12] contributors, last_modified, last_commit_id = \ FileContributors.objects.get_file_contributors( repo.id, path.encode('utf-8'), file_path_hash, dirent.obj_id) latest_contributor = contributors[0] if contributors else None wiki_index_exists = True index_pagename = 'index' index_content = None try: index_content, index_repo, index_dirent = get_personal_wiki_page( username, index_pagename) except (WikiDoesNotExist, WikiPageMissing) as e: wiki_index_exists = False else: index_content = convert_wiki_link(index_content, url_prefix, index_repo.id, username) return render_to_response("wiki/personal_wiki.html", { "wiki_exists": wiki_exists, "content": content, "page": os.path.splitext(dirent.obj_name)[0], "last_modified": last_modified, "latest_contributor": latest_contributor, "path": path, "repo_id": repo.id, "search_repo_id": repo.id, "search_wiki": True, "wiki_index_exists": wiki_index_exists, "index_content": index_content, }, context_instance=RequestContext(request))
def group_wiki_page_new(request, group, page_name="home"): if group.view_perm == "pub": raise Http404 if request.method == 'POST': form = MessageForm(request.POST) page_name = request.POST.get('page_name', '') if not page_name: return HttpResponseRedirect(request.META.get('HTTP_REFERER')) page_name = clean_page_name(page_name) try: repo = get_group_wiki_repo(group, request.user.username) except WikiDoesNotExist: return render_error(request, _('Wiki is not found.')) filename = page_name + ".md" filepath = "/" + page_name + ".md" # check whether file exists if get_file_id_by_path(repo.id, filepath): return render_error(request, _('Page "%s" already exists.') % filename) if not post_empty_file(repo.id, "/", filename, request.user.username): return render_error( request, _('Failed to create wiki page. Please retry later.')) url = "%s?p=%s&from=wiki_page_new&gid=%s" % (reverse( 'file_edit', args=[repo.id]), urllib2.quote(filepath.encode('utf-8')), group.id) return HttpResponseRedirect(url)
def personal_wiki(request, page_name="home"): username = request.user.username wiki_exists = True try: content, repo, dirent = get_personal_wiki_page(username, page_name) except WikiDoesNotExist: wiki_exists = False owned_repos = seafile_api.get_owned_repo_list(username) owned_repos = [r for r in owned_repos if not r.encrypted] return render_to_response("wiki/personal_wiki.html", { "wiki_exists": wiki_exists, "owned_repos": owned_repos, }, context_instance=RequestContext(request)) except WikiPageMissing: repo = get_personal_wiki_repo(username) filename = page_name_to_file_name(clean_page_name(page_name)) if not seaserv.post_empty_file(repo.id, "/", filename, username): return render_error( request, _("Failed to create wiki page. Please retry later.")) return HttpResponseRedirect(reverse('personal_wiki', args=[page_name])) else: url_prefix = reverse('personal_wiki', args=[]) # fetch file modified time and modifier path = '/' + dirent.obj_name try: dirent = seafile_api.get_dirent_by_path(repo.id, path) if dirent: latest_contributor, last_modified = dirent.modifier, dirent.mtime else: latest_contributor, last_modified = None, 0 except SearpcError as e: logger.error(e) latest_contributor, last_modified = None, 0 wiki_index_exists = True index_pagename = 'index' index_content = None try: index_content, index_repo, index_dirent = get_personal_wiki_page( username, index_pagename) except (WikiDoesNotExist, WikiPageMissing) as e: wiki_index_exists = False return render_to_response( "wiki/personal_wiki.html", { "wiki_exists": wiki_exists, "content": content, "page": os.path.splitext(dirent.obj_name)[0], "last_modified": last_modified, "latest_contributor": latest_contributor or _("Unknown"), "path": path, "repo_id": repo.id, "search_repo_id": repo.id, "search_wiki": True, "wiki_index_exists": wiki_index_exists, "index_content": index_content, }, context_instance=RequestContext(request))
def personal_wiki_page_new(request, page_name="home"): if request.method == 'POST': page_name = request.POST.get('page_name', '') if not page_name: return HttpResponseRedirect(request.META.get('HTTP_REFERER')) page_name = clean_page_name(page_name) try: repo = get_personal_wiki_repo(request.user.username) except WikiDoesNotExist: return render_error(request, _('Wiki is not found.')) filename = page_name + ".md" filepath = "/" + page_name + ".md" # check whether file exists if seaserv.get_file_id_by_path(repo.id, filepath): return render_error(request, _('Page "%s" already exists.') % filename) if not seaserv.post_empty_file(repo.id, "/", filename, request.user.username): return render_error(request, _('Failed to create wiki page. Please retry later.')) url = "%s?p=%s&from=personal_wiki_page_new" % ( reverse('file_edit', args=[repo.id]), urlquote(filepath.encode('utf-8'))) return HttpResponseRedirect(url)
def group_wiki_page_new(request, group, page_name="home"): if group.view_perm == "pub": raise Http404 if request.method == "POST": form = MessageForm(request.POST) page_name = request.POST.get("page_name", "") if not page_name: return HttpResponseRedirect(request.META.get("HTTP_REFERER")) page_name = clean_page_name(page_name) try: repo = get_group_wiki_repo(group, request.user.username) except WikiDoesNotExist: return render_error(request, _("Wiki is not found.")) filename = page_name + ".md" filepath = "/" + page_name + ".md" # check whether file exists if get_file_id_by_path(repo.id, filepath): return render_error(request, _('Page "%s" already exists.') % filename) if not post_empty_file(repo.id, "/", filename, request.user.username): return render_error(request, _("Failed to create wiki page. Please retry later.")) url = "%s?p=%s&from=wiki_page_new&gid=%s" % ( reverse("file_edit", args=[repo.id]), urllib2.quote(filepath.encode("utf-8")), group.id, ) return HttpResponseRedirect(url)
def personal_wiki(request, page_name="home"): username = request.user.username wiki_exists = True try: content, repo, dirent = get_personal_wiki_page(username, page_name) except WikiDoesNotExist: wiki_exists = False owned_repos = seafile_api.get_owned_repo_list(username) owned_repos = [r for r in owned_repos if not r.encrypted] return render_to_response( "wiki/personal_wiki.html", {"wiki_exists": wiki_exists, "owned_repos": owned_repos}, context_instance=RequestContext(request), ) except WikiPageMissing: repo = get_personal_wiki_repo(username) filename = clean_page_name(page_name) + ".md" if not seaserv.post_empty_file(repo.id, "/", filename, username): return render_error(request, _("Failed to create wiki page. Please retry later.")) return HttpResponseRedirect(reverse("personal_wiki", args=[page_name])) else: url_prefix = reverse("personal_wiki", args=[]) content = convert_wiki_link(content, url_prefix, repo.id, username) # fetch file latest contributor and last modified path = "/" + dirent.obj_name file_path_hash = hashlib.md5(urllib2.quote(path.encode("utf-8"))).hexdigest()[:12] contributors, last_modified, last_commit_id = FileContributors.objects.get_file_contributors( repo.id, path.encode("utf-8"), file_path_hash, dirent.obj_id ) latest_contributor = contributors[0] if contributors else None wiki_index_exists = True index_pagename = "index" index_content = None try: index_content, index_repo, index_dirent = get_personal_wiki_page(username, index_pagename) except (WikiDoesNotExist, WikiPageMissing) as e: wiki_index_exists = False else: index_content = convert_wiki_link(index_content, url_prefix, index_repo.id, username) return render_to_response( "wiki/personal_wiki.html", { "wiki_exists": wiki_exists, "content": content, "page": os.path.splitext(dirent.obj_name)[0], "last_modified": last_modified, "latest_contributor": latest_contributor, "path": path, "repo_id": repo.id, "search_repo_id": repo.id, "search_wiki": True, "wiki_index_exists": wiki_index_exists, "index_content": index_content, }, context_instance=RequestContext(request), )
def personal_wiki(request, page_name="home"): username = request.user.username wiki_exists = True try: content, repo, dirent = get_personal_wiki_page(username, page_name) except WikiDoesNotExist: wiki_exists = False owned_repos = seafile_api.get_owned_repo_list(username) owned_repos = [r for r in owned_repos if not r.encrypted] return render_to_response("wiki/personal_wiki.html", { "wiki_exists": wiki_exists, "owned_repos": owned_repos, }, context_instance=RequestContext(request)) except WikiPageMissing: repo = get_personal_wiki_repo(username) filename = clean_page_name(page_name) + '.md' if not seaserv.post_empty_file(repo.id, "/", filename, username): return render_error(request, _("Failed to create wiki page. Please retry later.")) return HttpResponseRedirect(reverse('personal_wiki', args=[page_name])) else: url_prefix = reverse('personal_wiki', args=[]) content = convert_wiki_link(content, url_prefix, repo.id, username) # fetch file modified time and modifier path = '/' + dirent.obj_name try: dirent = seafile_api.get_dirent_by_path(repo.id, path) if dirent: latest_contributor, last_modified = dirent.modifier, dirent.mtime else: latest_contributor, last_modified = None, 0 except SearpcError as e: logger.error(e) latest_contributor, last_modified = None, 0 wiki_index_exists = True index_pagename = 'index' index_content = None try: index_content, index_repo, index_dirent = get_personal_wiki_page(username, index_pagename) except (WikiDoesNotExist, WikiPageMissing) as e: wiki_index_exists = False else: index_content = convert_wiki_link(index_content, url_prefix, index_repo.id, username) return render_to_response("wiki/personal_wiki.html", { "wiki_exists": wiki_exists, "content": content, "page": os.path.splitext(dirent.obj_name)[0], "last_modified": last_modified, "latest_contributor": latest_contributor or _("Unknown"), "path": path, "repo_id": repo.id, "search_repo_id": repo.id, "search_wiki": True, "wiki_index_exists": wiki_index_exists, "index_content": index_content, }, context_instance=RequestContext(request))
def personal_wiki(request, page_name="home"): username = request.user.username wiki_exists = True try: content, repo, dirent = get_personal_wiki_page(username, page_name) except WikiDoesNotExist: wiki_exists = False # get available modules(wiki, etc) mods_available = get_available_mods_by_user(username) mods_enabled = get_enabled_mods_by_user(username) return render_to_response("wiki/personal_wiki.html", { "wiki_exists": wiki_exists, "mods_enabled": mods_enabled, "mods_available": mods_available, }, context_instance=RequestContext(request)) except WikiPageMissing: repo = get_personal_wiki_repo(username) filename = clean_page_name(page_name) + '.md' if not seaserv.post_empty_file(repo.id, "/", filename, username): return render_error( request, _("Failed to create wiki page. Please retry later.")) return HttpResponseRedirect(reverse('personal_wiki', args=[page_name])) else: url_prefix = reverse('personal_wiki', args=[]) content = convert_wiki_link(content, url_prefix, repo.id, username) # fetch file latest contributor and last modified path = '/' + dirent.obj_name file_path_hash = hashlib.md5(urllib2.quote( path.encode('utf-8'))).hexdigest()[:12] contributors, last_modified, last_commit_id = get_file_contributors(\ repo.id, path.encode('utf-8'), file_path_hash, dirent.obj_id) latest_contributor = contributors[0] if contributors else None # get available modules(wiki, etc) mods_available = get_available_mods_by_user(username) mods_enabled = get_enabled_mods_by_user(username) return render_to_response("wiki/personal_wiki.html", { "wiki_exists": wiki_exists, "content": content, "page": os.path.splitext(dirent.obj_name)[0], "last_modified": last_modified, "latest_contributor": latest_contributor, "path": path, "repo_id": repo.id, "search_repo_id": repo.id, "search_wiki": True, "mods_enabled": mods_enabled, "mods_available": mods_available, }, context_instance=RequestContext(request))
def personal_wiki(request, page_name="home"): username = request.user.username wiki_exists = True try: content, repo, dirent = get_personal_wiki_page(username, page_name) except WikiDoesNotExist: wiki_exists = False # get available modules(wiki, etc) mods_available = get_available_mods_by_user(username) mods_enabled = get_enabled_mods_by_user(username) return render_to_response("wiki/personal_wiki.html", { "wiki_exists": wiki_exists, "mods_enabled": mods_enabled, "mods_available": mods_available, }, context_instance=RequestContext(request)) except WikiPageMissing: repo = get_personal_wiki_repo(username) filename = clean_page_name(page_name) + '.md' if not seaserv.post_empty_file(repo.id, "/", filename, username): return render_error(request, _("Failed to create wiki page. Please retry later.")) return HttpResponseRedirect(reverse('personal_wiki', args=[page_name])) else: url_prefix = reverse('personal_wiki', args=[]) content = convert_wiki_link(content, url_prefix, repo.id, username) # fetch file latest contributor and last modified path = '/' + dirent.obj_name file_path_hash = hashlib.md5(urllib2.quote(path.encode('utf-8'))).hexdigest()[:12] contributors, last_modified, last_commit_id = \ FileContributors.objects.get_file_contributors( repo.id, path.encode('utf-8'), file_path_hash, dirent.obj_id) latest_contributor = contributors[0] if contributors else None # get available modules(wiki, etc) mods_available = get_available_mods_by_user(username) mods_enabled = get_enabled_mods_by_user(username) return render_to_response("wiki/personal_wiki.html", { "wiki_exists": wiki_exists, "content": content, "page": os.path.splitext(dirent.obj_name)[0], "last_modified": last_modified, "latest_contributor": latest_contributor, "path": path, "repo_id": repo.id, "search_repo_id": repo.id, "search_wiki": True, "mods_enabled": mods_enabled, "mods_available": mods_available, }, context_instance=RequestContext(request))
def post(self, request, slug): """ Add a page in a wiki """ try: wiki = Wiki.objects.get(slug=slug) except Wiki.DoesNotExist: error_msg = "Wiki not found." return api_error(status.HTTP_404_NOT_FOUND, error_msg) # perm check username = request.user.username if wiki.username != username: error_msg = _('Permission denied.') return api_error(status.HTTP_403_FORBIDDEN, error_msg) page_name = request.POST.get('name', '') if not page_name: error_msg = 'name invalid' return api_error(status.HTTP_400_BAD_REQUEST, error_msg) page_name = clean_page_name(page_name) filename = page_name + ".md" filepath = "/" + page_name + ".md" try: repo = seafile_api.get_repo(wiki.repo_id) if not repo: error_msg = "Wiki library not found." return api_error(status.HTTP_404_NOT_FOUND, error_msg) except SearpcError: error_msg = _("Internal Server Error") return api_error(status.HTTP_500_INTERNAL_SERVER_ERROR, error_msg) # check whether file exists if get_file_id_by_path(repo.id, filepath): error_msg = _('Page "%s" already exists.') % filename return api_error(status.HTTP_400_BAD_REQUEST, error_msg) try: seafile_api.post_empty_file(repo.id, '/', filename, request.user.username) except SearpcError as e: logger.error(e) error_msg = _('Internal Server Error') return api_error(status.HTTP_500_INTERNAL_SERVER_ERROR, error_msg) wiki_page_object = get_wiki_page_object(wiki, page_name) return Response(wiki_page_object)
def get(self, request, slug, page_name="home"): """Get content of a wiki """ try: wiki = Wiki.objects.get(slug=slug) except Wiki.DoesNotExist: error_msg = "Wiki not found." return api_error(status.HTTP_404_NOT_FOUND, error_msg) # perm check if not wiki.has_read_perm(request): error_msg = 'Permission denied.' return api_error(status.HTTP_403_FORBIDDEN, error_msg) page_name = clean_page_name(page_name) try: repo = seafile_api.get_repo(wiki.repo_id) if not repo: error_msg = "Wiki library not found." return api_error(status.HTTP_404_NOT_FOUND, error_msg) except SearpcError: error_msg = _("Internal Server Error") return api_error(status.HTTP_500_INTERNAL_SERVER_ERROR, error_msg) try: wiki_dirent = get_wiki_dirent(repo.id, page_name) except WikiPageMissing: error_msg = _("Page %s not found.") % page_name return api_error(status.HTTP_404_NOT_FOUND, error_msg) url = get_inner_file_url(repo, wiki_dirent.obj_id, wiki_dirent.obj_name) file_response = urllib2.urlopen(url) content = file_response.read() wiki_page_object = get_wiki_page_object(wiki, page_name) return Response({ "meta": wiki_page_object, "content": content })
def get(self, request, slug, page_name="home"): """Get content of a wiki """ try: wiki = Wiki.objects.get(slug=slug) except Wiki.DoesNotExist: error_msg = "Wiki not found." return api_error(status.HTTP_404_NOT_FOUND, error_msg) # perm check if not wiki.has_read_perm(request.user): error_msg = 'Permission denied.' return api_error(status.HTTP_403_FORBIDDEN, error_msg) page_name = clean_page_name(page_name) try: repo = seafile_api.get_repo(wiki.repo_id) if not repo: error_msg = "Wiki library not found." return api_error(status.HTTP_404_NOT_FOUND, error_msg) except SearpcError: error_msg = _("Internal Server Error") return api_error(status.HTTP_500_INTERNAL_SERVER_ERROR, error_msg) try: wiki_dirent = get_wiki_dirent(repo.id, page_name) except WikiPageMissing: error_msg = _("Page %s not found.") % page_name return api_error(status.HTTP_404_NOT_FOUND, error_msg) url = get_inner_file_url(repo, wiki_dirent.obj_id, wiki_dirent.obj_name) file_response = urllib2.urlopen(url) content = file_response.read() wiki_page_object = get_wiki_page_object(wiki, page_name) return Response({ "meta": wiki_page_object, "content": content })
def group_wiki(request, group, page_name="home"): username = request.user.username # get available modules(wiki, etc) mods_available = get_available_mods_by_group(group.id) mods_enabled = get_enabled_mods_by_group(group.id) wiki_exists = True try: content, repo, dirent = get_group_wiki_page(username, group, page_name) except WikiDoesNotExist: wiki_exists = False group_repos = get_group_repos(group.id, username) group_repos = [r for r in group_repos if not r.encrypted] return render_to_response("group/group_wiki.html", { "group": group, "is_staff": group.is_staff, "wiki_exists": wiki_exists, "mods_enabled": mods_enabled, "mods_available": mods_available, "group_repos": group_repos, }, context_instance=RequestContext(request)) except WikiPageMissing: '''create that page for user if he/she is a group member''' if not is_group_user(group.id, username): raise Http404 repo = get_group_wiki_repo(group, username) # No need to check whether repo is none, since repo is already created filename = page_name_to_file_name(clean_page_name(page_name)) if not post_empty_file(repo.id, "/", filename, username): return render_error( request, _("Failed to create wiki page. Please retry later.")) return HttpResponseRedirect( reverse('group_wiki', args=[group.id, page_name])) else: # fetch file modified time and modifier path = '/' + dirent.obj_name try: dirent = seafile_api.get_dirent_by_path(repo.id, path) if dirent: latest_contributor, last_modified = dirent.modifier, dirent.mtime else: latest_contributor, last_modified = None, 0 except SearpcError as e: logger.error(e) latest_contributor, last_modified = None, 0 if is_registered_user(username): repo_perm = seafile_api.check_permission_by_path( repo.id, '/', username) else: # when anonymous user visit public group wiki, set permission as 'r' repo_perm = 'r' wiki_index_exists = True index_pagename = 'index' index_content = None try: index_content, index_repo, index_dirent = get_group_wiki_page( username, group, index_pagename) except (WikiDoesNotExist, WikiPageMissing) as e: wiki_index_exists = False return render_to_response( "group/group_wiki.html", { "group": group, "is_staff": group.is_staff, "wiki_exists": wiki_exists, "content": content, "page": os.path.splitext(dirent.obj_name)[0], "last_modified": last_modified, "latest_contributor": latest_contributor or _("Unknown"), "path": path, "repo_id": repo.id, "search_repo_id": repo.id, "search_wiki": True, "mods_enabled": mods_enabled, "mods_available": mods_available, "repo_perm": repo_perm, "wiki_index_exists": wiki_index_exists, "index_content": index_content, }, context_instance=RequestContext(request))
def group_wiki(request, group, page_name="home"): username = request.user.username # get available modules(wiki, etc) mods_available = get_available_mods_by_group(group.id) mods_enabled = get_enabled_mods_by_group(group.id) wiki_exists = True try: content, repo, dirent = get_group_wiki_page(username, group, page_name) except WikiDoesNotExist: wiki_exists = False group_repos = get_group_repos(group.id, username) group_repos = [r for r in group_repos if not r.encrypted] return render_to_response( "group/group_wiki.html", { "group": group, "is_staff": group.is_staff, "wiki_exists": wiki_exists, "mods_enabled": mods_enabled, "mods_available": mods_available, "group_repos": group_repos, }, context_instance=RequestContext(request), ) except WikiPageMissing: """create that page for user if he/she is a group member""" if not is_group_user(group.id, username): raise Http404 repo = get_group_wiki_repo(group, username) # No need to check whether repo is none, since repo is already created filename = page_name_to_file_name(clean_page_name(page_name)) if not post_empty_file(repo.id, "/", filename, username): return render_error(request, _("Failed to create wiki page. Please retry later.")) return HttpResponseRedirect(reverse("group_wiki", args=[group.id, page_name])) else: url_prefix = reverse("group_wiki", args=[group.id]) # fetch file modified time and modifier path = "/" + dirent.obj_name try: dirent = seafile_api.get_dirent_by_path(repo.id, path) if dirent: latest_contributor, last_modified = dirent.modifier, dirent.mtime else: latest_contributor, last_modified = None, 0 except SearpcError as e: logger.error(e) latest_contributor, last_modified = None, 0 repo_perm = seafile_api.check_repo_access_permission(repo.id, username) wiki_index_exists = True index_pagename = "index" index_content = None try: index_content, index_repo, index_dirent = get_group_wiki_page(username, group, index_pagename) except (WikiDoesNotExist, WikiPageMissing) as e: wiki_index_exists = False return render_to_response( "group/group_wiki.html", { "group": group, "is_staff": group.is_staff, "wiki_exists": wiki_exists, "content": content, "page": os.path.splitext(dirent.obj_name)[0], "last_modified": last_modified, "latest_contributor": latest_contributor or _("Unknown"), "path": path, "repo_id": repo.id, "search_repo_id": repo.id, "search_wiki": True, "mods_enabled": mods_enabled, "mods_available": mods_available, "repo_perm": repo_perm, "wiki_index_exists": wiki_index_exists, "index_content": index_content, }, context_instance=RequestContext(request), )
def personal_wiki(request, page_name="home"): username = request.user.username if request.cloud_mode and request.user.org is not None: org_id = request.user.org.org_id joined_groups = seaserv.get_org_groups_by_user(org_id, username) else: joined_groups = seaserv.get_personal_groups_by_user(username) if joined_groups: joined_groups.sort(lambda x, y: cmp(x.group_name.lower(), y.group_name.lower())) wiki_exists = True try: content, repo, dirent = get_personal_wiki_page(username, page_name) except WikiDoesNotExist: wiki_exists = False owned_repos = seafile_api.get_owned_repo_list(username) owned_repos = [r for r in owned_repos if not r.encrypted] return render_to_response("wiki/personal_wiki.html", { "wiki_exists": wiki_exists, "owned_repos": owned_repos, "grps": joined_groups, }, context_instance=RequestContext(request)) except WikiPageMissing: repo = get_personal_wiki_repo(username) filename = page_name_to_file_name(clean_page_name(page_name)) if not seaserv.post_empty_file(repo.id, "/", filename, username): return render_error(request, _("Failed to create wiki page. Please retry later.")) return HttpResponseRedirect(reverse('personal_wiki', args=[page_name])) else: # fetch file modified time and modifier path = '/' + dirent.obj_name try: dirent = seafile_api.get_dirent_by_path(repo.id, path) if dirent: latest_contributor, last_modified = dirent.modifier, dirent.mtime else: latest_contributor, last_modified = None, 0 except SearpcError as e: logger.error(e) latest_contributor, last_modified = None, 0 wiki_index_exists = True index_pagename = 'index' index_content = None try: index_content, index_repo, index_dirent = get_personal_wiki_page(username, index_pagename) except (WikiDoesNotExist, WikiPageMissing) as e: wiki_index_exists = False return render_to_response("wiki/personal_wiki.html", { "wiki_exists": wiki_exists, "content": content, "page": os.path.splitext(dirent.obj_name)[0], "last_modified": last_modified, "latest_contributor": latest_contributor or _("Unknown"), "path": path, "repo_id": repo.id, "search_repo_id": repo.id, "search_wiki": True, "wiki_index_exists": wiki_index_exists, "index_content": index_content, "grps": joined_groups, }, context_instance=RequestContext(request))
def personal_wiki(request, page_name="home"): username = request.user.username if request.cloud_mode and request.user.org is not None: org_id = request.user.org.org_id joined_groups = seaserv.get_org_groups_by_user(org_id, username) else: joined_groups = seaserv.get_personal_groups_by_user(username) if joined_groups: joined_groups.sort( lambda x, y: cmp(x.group_name.lower(), y.group_name.lower())) wiki_exists = True try: content, repo, dirent = get_personal_wiki_page(username, page_name) except WikiDoesNotExist: wiki_exists = False owned_repos = seafile_api.get_owned_repo_list(username) owned_repos = [r for r in owned_repos if not r.encrypted] return render( request, "wiki/personal_wiki.html", { "wiki_exists": wiki_exists, "owned_repos": owned_repos, "grps": joined_groups, }) except WikiPageMissing: repo = get_personal_wiki_repo(username) filename = page_name_to_file_name(clean_page_name(page_name)) if not seaserv.post_empty_file(repo.id, "/", filename, username): return render_error( request, _("Failed to create wiki page. Please retry later.")) return HttpResponseRedirect(reverse('personal_wiki', args=[page_name])) else: # fetch file modified time and modifier path = '/' + dirent.obj_name try: dirent = seafile_api.get_dirent_by_path(repo.id, path) if dirent: latest_contributor, last_modified = dirent.modifier, dirent.mtime else: latest_contributor, last_modified = None, 0 except SearpcError as e: logger.error(e) latest_contributor, last_modified = None, 0 wiki_index_exists = True index_pagename = 'index' index_content = None try: index_content, index_repo, index_dirent = get_personal_wiki_page( username, index_pagename) except (WikiDoesNotExist, WikiPageMissing) as e: wiki_index_exists = False return render( request, "wiki/personal_wiki.html", { "wiki_exists": wiki_exists, "content": content, "page": os.path.splitext(dirent.obj_name)[0], "last_modified": last_modified, "latest_contributor": latest_contributor or _("Unknown"), "path": path, "repo_id": repo.id, "search_repo_id": repo.id, "search_wiki": True, "wiki_index_exists": wiki_index_exists, "index_content": index_content, "grps": joined_groups, })