本文整理汇总了Python中seaserv.post_empty_file函数的典型用法代码示例。如果您正苦于以下问题:Python post_empty_file函数的具体用法?Python post_empty_file怎么用?Python post_empty_file使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了post_empty_file函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: group_wiki_page_new
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)
示例2: test_home_page
def test_home_page(self):
self.login_as(self.user)
PersonalWiki.objects.save_personal_wiki(self.user.username,
self.repo.id)
assert len(PersonalWiki.objects.all()) == 1
seaserv.post_empty_file(self.repo.id, "/", "home.md",
self.user.username)
for page_name in ["home", "home.md"]:
resp = self.client.get(reverse('personal_wiki', args=[page_name]))
self.assertEqual(200, resp.status_code)
self.assertTemplateUsed('wiki/personal_wiki.html')
self.assertEqual(True, resp.context['wiki_exists'])
self.assertEqual("home", resp.context['page'])
self.assertEqual("/home.md", resp.context['path'])
示例3: personal_wiki_create
def personal_wiki_create(request):
if request.method != 'POST':
raise Http404
content_type = 'application/json; charset=utf-8'
def json_error(err_msg, status=400):
result = {'error': err_msg}
return HttpResponse(json.dumps(result), status=status,
content_type=content_type)
form = WikiCreateForm(request.POST)
if not form.is_valid():
return json_error(str(form.errors.values()[0]))
# create group repo in user context
repo_name = form.cleaned_data['repo_name']
repo_desc = form.cleaned_data['repo_desc']
username = request.user.username
passwd = None
permission = "rw"
repo_id = seaserv.create_repo(repo_name, repo_desc, username, passwd)
if not repo_id:
return json_error(_(u'Failed to create'), 500)
PersonalWiki.objects.save_personal_wiki(username=username, repo_id=repo_id)
# create home page
page_name = "home.md"
if not seaserv.post_empty_file(repo_id, "/", page_name, username):
return json_error(_(u'Failed to create home page. Please retry later'), 500)
next = reverse('personal_wiki', args=[])
return HttpResponse(json.dumps({'href': next}), content_type=content_type)
示例4: personal_wiki_page_new
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)
示例5: personal_wiki
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),
)
示例6: personal_wiki
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))
示例7: personal_wiki
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))
示例8: group_wiki_create
def group_wiki_create(request, group):
if group.view_perm == "pub":
raise Http404
if request.method != 'POST':
raise Http404
content_type = 'application/json; charset=utf-8'
def json_error(err_msg, status=400):
result = {'error': err_msg}
return HttpResponse(json.dumps(result), status=status,
content_type=content_type)
form = WikiCreateForm(request.POST)
if not form.is_valid():
return json_error(str(form.errors.values()[0]))
# create group repo in user context
repo_name = form.cleaned_data['repo_name']
repo_desc = form.cleaned_data['repo_desc']
user = request.user.username
passwd = None
permission = "rw"
repo_id = create_repo(repo_name, repo_desc, user, passwd)
if not repo_id:
return json_error(_(u'Failed to create'), 500)
try:
seafile_api.set_group_repo(repo_id, group.id, user, permission)
except SearpcError as e:
remove_repo(repo_id)
return json_error(_(u'Failed to create: internal error.'), 500)
GroupWiki.objects.save_group_wiki(group_id=group.id, repo_id=repo_id)
# create home page
page_name = "home.md"
if not post_empty_file(repo_id, "/", page_name, user):
return json_error(_(u'Failed to create home page. Please retry later'), 500)
next = reverse('group_wiki', args=[group.id])
return HttpResponse(json.dumps({'href': next}), content_type=content_type)
示例9: personal_wiki_use_lib
def personal_wiki_use_lib(request):
if request.method != "POST":
raise Http404
repo_id = request.POST.get("dst_repo", "")
username = request.user.username
next = reverse("personal_wiki", args=[])
repo = seafile_api.get_repo(repo_id)
if repo is None:
messages.error(request, _("Failed to set wiki library."))
return HttpResponseRedirect(next)
PersonalWiki.objects.save_personal_wiki(username=username, repo_id=repo_id)
# create home page if not exist
page_name = "home.md"
if not seaserv.get_file_id_by_path(repo_id, "/" + page_name):
if not seaserv.post_empty_file(repo_id, "/", page_name, username):
messages.error(request, _("Failed to create home page. Please retry later"))
return HttpResponseRedirect(next)
示例10: group_wiki_page_new
def group_wiki_page_new(request, group, page_name="home"):
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 = normalize_page_name(page_name) # normalize page name
repo = find_wiki_repo(request, group)
if not repo:
return render_error(request, _('Wiki is not found.'))
filename = page_name + ".md"
filepath = "/" + page_name + ".md"
if not post_empty_file(repo.id, "/", filename, request.user.username):
return render_error(request, _('Failed to create wiki page. Please retry later.'))
url = "%srepo/%s/file/edit/?p=%s&from=wiki_page_new&gid=%s" % \
(SITE_ROOT, repo.id, filepath, group.id)
return HttpResponseRedirect(url)
示例11: group_wiki_use_lib
def group_wiki_use_lib(request, group):
if group.view_perm == "pub":
raise Http404
if request.method != 'POST':
raise Http404
repo_id = request.POST.get('dst_repo', '')
username = request.user.username
next = reverse('group_wiki', args=[group.id])
repo = seafile_api.get_repo(repo_id)
if repo is None:
messages.error(request, _('Failed to set wiki library.'))
return HttpResponseRedirect(next)
GroupWiki.objects.save_group_wiki(group_id=group.id, repo_id=repo_id)
# create home page if not exist
page_name = "home.md"
if not seaserv.get_file_id_by_path(repo_id, "/" + page_name):
if not seaserv.post_empty_file(repo_id, "/", page_name, username):
messages.error(request, _('Failed to create home page. Please retry later'))
return HttpResponseRedirect(next)
示例12: group_wiki
def group_wiki(request, group, page_name="home"):
is_staff = True if check_group_staff(group.id, request.user) else False
username = request.user.username
content = ''
wiki_exists = True
last_modified, latest_contributor = None, None
try:
content, repo_id, obj_id = get_wiki_page(request, group, page_name)
except WikiDoesNotExist:
wiki_exists = False
except WikiPageMissing:
'''create that page for user'''
repo = find_wiki_repo(request, group)
# No need to check whether repo is none, since repo is already created
filename = normalize_page_name(page_name) + '.md'
if not post_empty_file(repo.id, "/", filename, username):
return render_error(request, _("Faied to create wiki page. Please retry later."))
return HttpResponseRedirect(reverse('group_wiki', args=[group.id, page_name]))
else:
content = convert_wiki_link(content, group, repo_id, username)
# fetch file latest contributor and last modified
path = '/' + page_name + '.md'
file_path_hash = md5_constructor(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, obj_id)
latest_contributor = contributors[0] if contributors else None
return render_to_response("group/group_wiki.html", {
"group_id": group.id,
"group" : group,
"is_staff": is_staff,
"content": content,
"page": page_name,
"wiki_exists": wiki_exists,
"last_modified": last_modified,
"latest_contributor": latest_contributor,
}, context_instance=RequestContext(request))
示例13: personal_wiki_create
def personal_wiki_create(request):
if request.method != "POST":
raise Http404
content_type = "application/json; charset=utf-8"
def json_error(err_msg, status=400):
result = {"error": err_msg}
return HttpResponse(json.dumps(result), status=status, content_type=content_type)
if not request.user.permissions.can_add_repo():
return json_error(_("You do not have permission to create wiki"), 403)
form = WikiCreateForm(request.POST)
if not form.is_valid():
return json_error(str(form.errors.values()[0]))
# create group repo in user context
repo_name = form.cleaned_data["repo_name"]
repo_desc = form.cleaned_data["repo_desc"]
username = request.user.username
passwd = None
permission = "rw"
repo_id = seaserv.create_repo(repo_name, repo_desc, username, passwd)
if not repo_id:
return json_error(_(u"Failed to create"), 500)
PersonalWiki.objects.save_personal_wiki(username=username, repo_id=repo_id)
# create home page
page_name = "home.md"
if not seaserv.post_empty_file(repo_id, "/", page_name, username):
return json_error(_(u"Failed to create home page. Please retry later"), 500)
next = reverse("personal_wiki", args=[])
return HttpResponse(json.dumps({"href": next}), content_type=content_type)
示例14: json_error
return json_error(_(u'Failed to create'), 500)
try:
status = seafserv_threaded_rpc.group_share_repo(repo_id,
group.id,
user,
permission)
except SearpcError, e:
remove_repo(repo_id)
return json_error(_(u'Failed to create: internal error.'), 500)
GroupWiki.objects.save_group_wiki(group_id=group.id, repo_id=repo_id)
# create home page
page_name = "home.md"
if not post_empty_file(repo_id, "/", page_name, user):
return json_error(_(u'Failed to create home page. Please retry later'), 500)
next = reverse('group_wiki', args=[group.id])
return HttpResponse(json.dumps({'href': next}), content_type=content_type)
def normalize_page_name(page_name):
# Replace special characters to '-'.
# Do not lower page name and spaces are allowed.
return slugify(page_name, lower=False, spaces=True)
@login_required
@group_check
def group_wiki_page_new(request, group, page_name="home"):
if request.method == 'POST':
form = MessageForm(request.POST)
示例15: group_wiki
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),
)