fixed order of query definitions to avoid wrong routing ("/:admin_hash_key" must follow other queries with a constant string)

added "vote_open" setting to the list of supported PollSetting keys
This commit is contained in:
lars 2012-06-03 22:38:02 +00:00
parent 20a6b713f6
commit 24598be805

View file

@ -65,6 +65,7 @@ POLL_SETTINGS = {
"public": (bool, False), "public": (bool, False),
"expose_date": (datetime.datetime, DEFAULT_DATE), "expose_date": (datetime.datetime, DEFAULT_DATE),
"close_date": (datetime.datetime, DEFAULT_DATE), "close_date": (datetime.datetime, DEFAULT_DATE),
"vote_open": (bool, False),
} }
POLL_SETTING_TEMPLATES = { POLL_SETTING_TEMPLATES = {
@ -97,7 +98,10 @@ class ContentSubmission(sqlobject.SQLObject):
def get_delete_url(self, absolute=False): def get_delete_url(self, absolute=False):
return self.poll_id.get_admin_url(absolute=absolute, return self.poll_id.get_admin_url(absolute=absolute,
suffix="/delete/%s" % self.get_obfuscated_digest()) suffix="/delete/%s" % self.get_obfuscated_digest())
def get_vote_toggle_url(self, absolute=False):
return self.poll_id.get_admin_url(absolute=absolute,
suffix="/vote_toggle/%s" % self.get_obfuscated_digest())
def get_obfuscated_digest(self): def get_obfuscated_digest(self):
return hashlib.md5(str(self.id)).hexdigest() return hashlib.md5(str(self.id)).hexdigest()
@ -251,9 +255,15 @@ class Poll(sqlobject.SQLObject):
def get_delete_url(self, absolute=False): def get_delete_url(self, absolute=False):
return get_url_string("%s%s/delete" % (BASE_DICT["base_url"], self.admin_hash_key), absolute) return get_url_string("%s%s/delete" % (BASE_DICT["base_url"], self.admin_hash_key), absolute)
def get_vote_toggle_url(self, absolute=False):
return get_url_string("%s%s/vote_toggle" % (BASE_DICT["base_url"], self.admin_hash_key), absolute)
def get_creation_time_string(self): def get_creation_time_string(self):
return str(self.timestamp_creation) return str(self.timestamp_creation)
def is_vote_open(self):
return self.get_settings()["vote_open"]
def get_submissions_visibility(self): def get_submissions_visibility(self):
settings = self.get_settings() settings = self.get_settings()
return bool(settings["show_all_submissions"] or (settings["expose_date"] and \ return bool(settings["show_all_submissions"] or (settings["expose_date"] and \
@ -432,6 +442,11 @@ def get_default_values(request, **kwargs):
except ConfigParser.Error: except ConfigParser.Error:
enable_users = False enable_users = False
value_dict["enable_users"] = enable_users value_dict["enable_users"] = enable_users
try:
enable_voting = config.get("voting", "enabled")
except ConfigParser.Error:
enable_voting = False
value_dict["enable_voting"] = enable_voting
# read the user's hash key from the cookie # read the user's hash key from the cookie
if enable_users and ("user_hash_key" in request.cookies): if enable_users and ("user_hash_key" in request.cookies):
value_dict["user_hash_key"] = str(request.cookies["user_hash_key"]) value_dict["user_hash_key"] = str(request.cookies["user_hash_key"])
@ -767,6 +782,17 @@ def delete_poll(bobo_request, admin_hash_key=None):
poll.delete_poll() poll.delete_poll()
return bobo.redirect(BASE_DICT["base_url"]) return bobo.redirect(BASE_DICT["base_url"])
@bobo.query('/:admin_hash_key/vote_toggle')
def vote_toggle_poll(bobo_request, admin_hash_key=None, vote_radio=None):
# vote_radio: open/closed
admin_poll_id = get_poll_admin_id(admin_hash_key)
if not admin_poll_id is None:
poll = Poll.get(admin_poll_id)
poll.change_setting("vote_open", vote_radio == "open")
return bobo.redirect(poll.get_admin_url())
else:
return bobo.redirect(BASE_DICT["base_url"])
@bobo.query('/:admin_hash_key/delete/:submission_id_digest') @bobo.query('/:admin_hash_key/delete/:submission_id_digest')
def delete_submission(bobo_request, admin_hash_key=None, submission_id_digest=None): def delete_submission(bobo_request, admin_hash_key=None, submission_id_digest=None):
admin_poll_id = get_poll_admin_id(admin_hash_key) admin_poll_id = get_poll_admin_id(admin_hash_key)
@ -963,17 +989,6 @@ 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)
@bobo.query('')
def base():
return bobo.redirect(BASE_DICT["base_url"])
@bobo.query('/')
@bobo.query('/public')
@bobo.query('/public/')
@bobo.query('/public/page/:page')
def show_frontpage(bobo_request, page=None):
return show_poll_list(bobo_request, "frontpage.html", 20, page)
def show_poll_list(bobo_request, render_file, page_size, page=None, filter_private=True): def show_poll_list(bobo_request, render_file, page_size, page=None, filter_private=True):
value_dict = get_default_values(bobo_request) value_dict = get_default_values(bobo_request)
polls = Poll.select().orderBy("-timestamp_creation") polls = Poll.select().orderBy("-timestamp_creation")
@ -1038,6 +1053,27 @@ def render_poll_admin(bobo_request, poll, add_related, del_related, count, page,
value_dict["errors"] = errors value_dict["errors"] = errors
return render("poll_admin_details.html", **value_dict) return render("poll_admin_details.html", **value_dict)
@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)
@bobo.query('/')
@bobo.query('/public')
@bobo.query('/public/')
@bobo.query('/public/page/:page')
def show_frontpage(bobo_request, page=None):
return show_poll_list(bobo_request, "frontpage.html", 20, page)
@bobo.query('')
def base():
return bobo.redirect(BASE_DICT["base_url"])
@bobo.query('/:poll_hash') @bobo.query('/:poll_hash')
@bobo.query('/:poll_hash/') @bobo.query('/:poll_hash/')
@bobo.query('/admin/poll/:poll_hash_for_admin') @bobo.query('/admin/poll/:poll_hash_for_admin')
@ -1080,16 +1116,6 @@ def show_one_poll(bobo_request, poll_hash_for_admin=None, poll_hash=None,
else: else:
return bobo.redirect(BASE_DICT["base_url"]) 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') @bobo.query('/node/:pagename')
def show_static_nodes(bobo_request, pagename=None): def show_static_nodes(bobo_request, pagename=None):
""" meant for serving hand-changed, automatically styled content. """ """ meant for serving hand-changed, automatically styled content. """
@ -1120,11 +1146,21 @@ def static_files(p1=None, p2=None, p3=None):
pathname = os.path.join(pathname, subdir) pathname = os.path.join(pathname, subdir)
return get_static_file(pathname) return get_static_file(pathname)
for table in (Poll, ContentSubmission, PollSetting, PollRelation, Profile, ProfilePolls): for table in (Poll, ContentSubmission, PollSetting, PollRelation, Profile, ProfilePolls):
#table.dropTable() #table.dropTable()
if not table.tableExists(): if not table.tableExists():
table.createTable() table.createTable()
# how to add new columns to the database:
# * uncomment the line below and change it according to your needs
# * run this script once (manually)
# * disable the line below
# * add the column specification to the object definition
# -> done!
#Poll.sqlmeta.addColumn(sqlobject.BoolCol("vote_open", default=False), changeSchema=True)
# this line allows to use wortschlucker with mod_wsgi # this line allows to use wortschlucker with mod_wsgi
# see: http://groups.google.com/group/bobo-web/msg/2ba55fc381658cd1 # see: http://groups.google.com/group/bobo-web/msg/2ba55fc381658cd1
# see: http://blog.dscpl.com.au/2009/08/using-bobo-on-top-of-modwsgi.html # see: http://blog.dscpl.com.au/2009/08/using-bobo-on-top-of-modwsgi.html