admin: allow sorting polls by number of submissions
This commit is contained in:
parent
fa37629d2c
commit
88a7725d0f
1 changed files with 22 additions and 7 deletions
|
@ -38,7 +38,8 @@ CONFIG_FILE = os.path.join(BASE_DIR, "wortschlucker.conf")
|
||||||
config = ConfigParser.SafeConfigParser()
|
config = ConfigParser.SafeConfigParser()
|
||||||
config.read(CONFIG_FILE)
|
config.read(CONFIG_FILE)
|
||||||
db_uri = config.get("database", "uri")
|
db_uri = config.get("database", "uri")
|
||||||
sqlobject.sqlhub.processConnection = sqlobject.connectionForURI(db_uri)
|
connection = sqlobject.connectionForURI(db_uri)
|
||||||
|
sqlobject.sqlhub.processConnection = connection
|
||||||
loader = genshi.template.TemplateLoader(os.path.join(BASE_DIR, 'templates'), auto_reload=False)
|
loader = genshi.template.TemplateLoader(os.path.join(BASE_DIR, 'templates'), auto_reload=False)
|
||||||
|
|
||||||
BLOG_DIR = os.path.join(BASE_DIR, "blog")
|
BLOG_DIR = os.path.join(BASE_DIR, "blog")
|
||||||
|
@ -1109,7 +1110,7 @@ def serve_blog(bobo_request, blog_id=None):
|
||||||
value_dict["blog_list"] = blog_list
|
value_dict["blog_list"] = blog_list
|
||||||
return render("blog_list.html", **value_dict)
|
return render("blog_list.html", **value_dict)
|
||||||
|
|
||||||
def show_poll_list(bobo_request, render_file, page_size, page=None,
|
def show_poll_list(bobo_request, render_file, page_size, page=None, sort_by="time",
|
||||||
filter_private=True, value_dict=None):
|
filter_private=True, value_dict=None):
|
||||||
if value_dict is None:
|
if value_dict is None:
|
||||||
value_dict = {}
|
value_dict = {}
|
||||||
|
@ -1120,10 +1121,24 @@ def show_poll_list(bobo_request, render_file, page_size, page=None,
|
||||||
PollSetting.q.key == "public",
|
PollSetting.q.key == "public",
|
||||||
PollSetting.q.value == true_string,
|
PollSetting.q.value == true_string,
|
||||||
PollSetting.q.poll_id == Poll.q.id))
|
PollSetting.q.poll_id == Poll.q.id))
|
||||||
|
poll_count = polls.count()
|
||||||
else:
|
else:
|
||||||
|
if sort_by == "submissions":
|
||||||
|
# Nach Anzahl der Kommentare filtern
|
||||||
|
# das rohe SQL geht so: select poll.id FROM poll LEFT JOIN content_submission ON poll.id = content_submission.poll_id_id GROUP BY content_submission.poll_id_id, poll.id ORDER BY count(content_submission.id) desc;
|
||||||
|
# das liefert absteigend nach Beitragsmenge sortiert die polls zurueck. Allerdings fehlen aktuell noch die polls ohne Beitraege.
|
||||||
|
# fiese rohe SQL-Anfrage machen, weil mir das mit sqlobject zu kompliziert ist
|
||||||
|
rawpolls = connection.queryAll("""select poll.id FROM poll LEFT JOIN content_submission ON poll.id = content_submission.poll_id_id GROUP BY content_submission.poll_id_id, poll.id ORDER BY count(content_submission.id) desc;""")
|
||||||
|
polls = []
|
||||||
|
# jetzt noch aus den ids wieder eine SelectReturn-Liste machen:
|
||||||
|
for id in rawpolls:
|
||||||
|
polls.append(Poll.get(id[0]))
|
||||||
|
poll_count=len(polls)
|
||||||
|
else: #sort_by == time
|
||||||
polls = Poll.select()
|
polls = Poll.select()
|
||||||
polls = polls.orderBy("-timestamp_creation")
|
polls = polls.orderBy("-timestamp_creation")
|
||||||
poll_count = polls.count()
|
poll_count = polls.count()
|
||||||
|
|
||||||
if page is None:
|
if page is None:
|
||||||
page = 1
|
page = 1
|
||||||
else:
|
else:
|
||||||
|
@ -1205,7 +1220,7 @@ def admin_maintenance(age_days=60, keyword="viagra", keyword_submission="viagra"
|
||||||
@bobo.query('/admin')
|
@bobo.query('/admin')
|
||||||
@bobo.query('/admin/')
|
@bobo.query('/admin/')
|
||||||
@bobo.query('/admin/page/:page')
|
@bobo.query('/admin/page/:page')
|
||||||
def show_admin_page(bobo_request, page=None, page_size=50):
|
def show_admin_page(bobo_request, page=None, page_size=50,sort_by="time"):
|
||||||
try:
|
try:
|
||||||
page_size = int(page_size)
|
page_size = int(page_size)
|
||||||
except ValueError:
|
except ValueError:
|
||||||
|
@ -1213,7 +1228,7 @@ def show_admin_page(bobo_request, page=None, page_size=50):
|
||||||
value_dict = {}
|
value_dict = {}
|
||||||
value_dict["poll_table"] = Poll
|
value_dict["poll_table"] = Poll
|
||||||
value_dict["submission_table"] = ContentSubmission
|
value_dict["submission_table"] = ContentSubmission
|
||||||
return show_poll_list(bobo_request, "admin.html", page_size, page=page,
|
return show_poll_list(bobo_request, "admin.html", page_size, sort_by=sort_by, page=page,
|
||||||
filter_private=False, value_dict=value_dict)
|
filter_private=False, value_dict=value_dict)
|
||||||
|
|
||||||
@bobo.query('/')
|
@bobo.query('/')
|
||||||
|
|
Loading…
Reference in a new issue