added poll deletion

This commit is contained in:
lars 2010-04-15 10:58:36 +00:00
parent 81df603ba2
commit 366b11d733
3 changed files with 21 additions and 0 deletions

Binary file not shown.

View file

@ -19,6 +19,7 @@
<li py:for="key, value in poll.get_settings().items()">${key}: ${value}</li>
</ul></li>
<li><a href="${poll.get_edit_url()}" title="edit this poll">Edit this poll</a></li>
<li><a href="${poll.get_delete_url()}" title="delete this poll">Delete this poll</a></li>
</ul>
</body>
</html>

View file

@ -77,6 +77,15 @@ class Poll(sqlobject.SQLObject):
def get_num_of_submissions(self):
return WordSubmission.selectBy(poll_id=self.id).count()
def delete_poll(self):
submissions = WordSubmission.selectBy(poll_id=self.id)
settings = PollSetting.selectBy(poll_id=self.id)
for submission in submissions:
submission.destroySelf()
for setting in settings:
setting.destroySelf()
self.destroySelf()
def get_url(self):
return "%spolls/%s" % (BASE_DICT["base_url"], self.hash_key)
@ -86,6 +95,9 @@ class Poll(sqlobject.SQLObject):
def get_edit_url(self):
return "%spolls/%s/admin" % (BASE_DICT["base_url"], self.admin_hash_key)
def get_delete_url(self):
return "%spolls/%s/delete" % (BASE_DICT["base_url"], self.admin_hash_key)
def get_creation_time_string(self):
return str(self.timestamp_creation)
@ -171,6 +183,14 @@ def new_poll(submit=None, cancel=None, author=None, title=None, description=None
new_poll = Poll(hash_key=hash_key, admin_hash_key=admin_hash_key, timestamp_creation=now, **data)
return bobo.redirect(new_poll.get_admin_url())
@bobo.query('/polls/:admin_hash_key/delete')
def delete_poll(admin_hash_key=None):
admin_poll_id = get_poll_admin_id(admin_hash_key)
if not admin_poll_id is None:
poll = Poll.get(admin_poll_id)
poll.delete_poll()
return bobo.redirect(BASE_DICT["base_url"])
@bobo.query('/polls/:admin_hash_key/admin')
def admin_poll(cancel=False, submit=None, admin_hash_key=None, author=None, title=None, description=None, **kwargs):
value_dict = get_default_values()