fixed unicode error
deliver content with multiple pages (if necessary) delete multiple submissions on demand
This commit is contained in:
parent
16b41e3dec
commit
962c560ed0
1 changed files with 49 additions and 15 deletions
|
@ -767,7 +767,11 @@ def export_poll(bobo_request, admin_hash_key=None):
|
|||
content = get_markup_with_formatted_linebreaks(submission.content, os.linesep)
|
||||
items = [timestamp, author, content]
|
||||
for index in range(len(items)):
|
||||
try:
|
||||
items[index] = items[index].encode(EXPORT_ENCODING, "ignore")
|
||||
except UnicodeDecodeError:
|
||||
# any other conversion error
|
||||
pass
|
||||
writer.writerow(items)
|
||||
try:
|
||||
export_prefix = config.get("misc", "export_prefix")
|
||||
|
@ -938,16 +942,6 @@ def base():
|
|||
def show_frontpage(bobo_request, page=None):
|
||||
return show_poll_list(bobo_request, "frontpage.html", 20, page)
|
||||
|
||||
@bobo.query('/admin')
|
||||
@bobo.query('/admin/')
|
||||
@bobo.query('/admin/page/:page')
|
||||
def show_admin_page(bobo_request, page=None, page_size=20):
|
||||
try:
|
||||
page_size = int(page_size)
|
||||
except ValueError:
|
||||
page_size = 30
|
||||
return show_poll_list(bobo_request, "admin.html", page_size, page, filter_private=False)
|
||||
|
||||
def show_poll_list(bobo_request, render_file, page_size, page=None, filter_private=True):
|
||||
value_dict = get_default_values(bobo_request)
|
||||
polls = Poll.select().orderBy("-timestamp_creation")
|
||||
|
@ -978,7 +972,7 @@ def show_poll_list(bobo_request, render_file, page_size, page=None, filter_priva
|
|||
value_dict["page"] = page
|
||||
return render(render_file, **value_dict)
|
||||
|
||||
def render_poll_admin(bobo_request, poll, add_related, del_related):
|
||||
def render_poll_admin(bobo_request, poll, add_related, del_related, count, page, show_delete):
|
||||
value_dict = get_default_values(bobo_request)
|
||||
errors = {}
|
||||
if not add_related is None:
|
||||
|
@ -1006,24 +1000,64 @@ def render_poll_admin(bobo_request, poll, add_related, del_related):
|
|||
PollRelation.deleteBy(first=poll.id, second=other_poll_id)
|
||||
PollRelation.deleteBy(first=other_poll_id, second=poll.id)
|
||||
value_dict["poll"] = poll
|
||||
value_dict["page"] = page
|
||||
value_dict["count"] = count
|
||||
value_dict["show_delete"] = show_delete
|
||||
value_dict["errors"] = errors
|
||||
return render("poll_admin_details.html", **value_dict)
|
||||
|
||||
@bobo.query('/:poll_hash')
|
||||
@bobo.query('/:poll_hash/')
|
||||
def show_one_poll(bobo_request, poll_hash=None, add_related=None, del_related=None):
|
||||
@bobo.query('/admin/poll/:poll_hash_for_admin')
|
||||
def show_one_poll(bobo_request, poll_hash_for_admin=None, poll_hash=None,
|
||||
add_related=None, del_related=None, delete_multiple=None,
|
||||
delete_submission_id_list=None, count=50, page=1, show_delete=False):
|
||||
if poll_hash_for_admin:
|
||||
# shortcut for admins
|
||||
admin_poll_id = get_poll_id(poll_hash_for_admin)
|
||||
if admin_poll_id:
|
||||
poll_hash = Poll.get(admin_poll_id).admin_hash_key
|
||||
try:
|
||||
count = int(count)
|
||||
except ValueError:
|
||||
count = 100
|
||||
count = max(1, min(count, 1000))
|
||||
try:
|
||||
page = int(page)
|
||||
except ValueError:
|
||||
page = 1
|
||||
page = max(1, page)
|
||||
value_dict = get_default_values(bobo_request)
|
||||
poll_id = get_poll_id(poll_hash)
|
||||
if not poll_id is None:
|
||||
value_dict["poll"] = Poll.get(poll_id)
|
||||
poll = Poll.get(poll_id)
|
||||
page = min(page, (poll.get_num_of_submissions() - 1) / count)
|
||||
value_dict["poll"] = poll
|
||||
value_dict["page"] = page
|
||||
value_dict["count"] = count
|
||||
return render("poll_details.html", **value_dict)
|
||||
else:
|
||||
admin_poll_id = get_poll_admin_id(poll_hash)
|
||||
if not admin_poll_id is None:
|
||||
return render_poll_admin(bobo_request, Poll.get(admin_poll_id), add_related, del_related)
|
||||
if delete_multiple and delete_submission_id_list:
|
||||
if not isinstance(delete_submission_id_list, list):
|
||||
delete_submission_id_list = [delete_submission_id_list]
|
||||
for delete_id in delete_submission_id_list:
|
||||
ContentSubmission.get(int(delete_id)).destroySelf()
|
||||
return render_poll_admin(bobo_request, Poll.get(admin_poll_id), add_related, del_related, count, page, bool(show_delete))
|
||||
else:
|
||||
return bobo.redirect(BASE_DICT["base_url"])
|
||||
|
||||
@bobo.query('/admin')
|
||||
@bobo.query('/admin/')
|
||||
@bobo.query('/admin/page/:page')
|
||||
def show_admin_page(bobo_request, poll_hash, page=None, page_size=20):
|
||||
try:
|
||||
page_size = int(page_size)
|
||||
except ValueError:
|
||||
page_size = 30
|
||||
return show_poll_list(bobo_request, "admin.html", page_size, page, filter_private=False)
|
||||
|
||||
@bobo.query('/node/:pagename')
|
||||
def show_static_nodes(bobo_request, pagename=None):
|
||||
""" meant for serving hand-changed, automatically styled content. """
|
||||
|
|
Loading…
Reference in a new issue