allow empty dates ("forever")
use dedicated checkboxes for "close" and "expose" dates
This commit is contained in:
parent
841be7d138
commit
1bc66d929f
2 changed files with 45 additions and 13 deletions
|
@ -8,8 +8,10 @@ class PollForm(formencode.Schema):
|
|||
|
||||
class PollSettingsForm(PollForm):
|
||||
settings = formencode.validators.Set()
|
||||
setting_expose_date = formencode.validators.UnicodeString(strip=True, not_empty=True)
|
||||
setting_close_date = formencode.validators.UnicodeString(strip=True, not_empty=True)
|
||||
setting_expose_date = formencode.validators.UnicodeString(strip=True)
|
||||
setting_expose_date_forever = formencode.validators.Set()
|
||||
setting_close_date = formencode.validators.UnicodeString(strip=True)
|
||||
setting_close_date_forever = formencode.validators.Set()
|
||||
|
||||
class SubmitForm(formencode.Schema):
|
||||
submitter = formencode.validators.UnicodeString(strip=True, not_empty=True)
|
||||
|
|
|
@ -217,9 +217,12 @@ def get_poll_setting_string(key, value):
|
|||
elif setting_type == bool:
|
||||
return str(value)
|
||||
elif setting_type == datetime.datetime:
|
||||
# some old entries are invalid
|
||||
# unset dates are None
|
||||
if value is None:
|
||||
return ""
|
||||
elif value == "":
|
||||
# value for "forever"
|
||||
return ""
|
||||
else:
|
||||
return value.strftime(DATE_FORMAT)
|
||||
else:
|
||||
|
@ -250,6 +253,9 @@ def validate_poll_setting(key, value):
|
|||
value = datetime.date.today() + datetime.timedelta(days=DEFAULT_DAYS_AHEAD)
|
||||
elif type(value) == datetime.datetime:
|
||||
pass
|
||||
elif value == "":
|
||||
# this is the value for "forever"
|
||||
return ""
|
||||
else:
|
||||
try:
|
||||
value = datetime.datetime.strptime(value, DATE_FORMAT)
|
||||
|
@ -421,8 +427,15 @@ def delete_poll(admin_hash_key=None):
|
|||
|
||||
@bobo.query('/:admin_hash_key/admin')
|
||||
def admin_poll(cancel=False, submit=None, admin_hash_key=None, author=None,
|
||||
title=None, description=None, settings=None, setting_expose_date=None,
|
||||
setting_close_date=None):
|
||||
title=None, description=None, settings=None,
|
||||
setting_expose_date=None, setting_expose_date_forever=None,
|
||||
setting_close_date=None, setting_close_date_forever=None):
|
||||
print "Eingaben"
|
||||
for value in (cancel, submit, admin_hash_key, author,
|
||||
title, description, settings,
|
||||
setting_expose_date, setting_expose_date_forever,
|
||||
setting_close_date, setting_close_date_forever):
|
||||
print value
|
||||
value_dict = get_default_values()
|
||||
data = {"author": author, "title": title, "description": description, "template": ""}
|
||||
poll_id = get_poll_admin_id(admin_hash_key)
|
||||
|
@ -438,10 +451,16 @@ def admin_poll(cancel=False, submit=None, admin_hash_key=None, author=None,
|
|||
data["title"] = poll.title
|
||||
if description is None:
|
||||
data["description"] = poll.description
|
||||
if setting_expose_date_forever is None:
|
||||
if setting_expose_date is None:
|
||||
setting_expose_date = poll.get_settings_strings()["expose_date"]
|
||||
else:
|
||||
setting_expose_date = ""
|
||||
if setting_close_date_forever is None:
|
||||
if setting_close_date is None:
|
||||
setting_close_date = poll.get_settings_strings()["close_date"]
|
||||
else:
|
||||
setting_close_date = ""
|
||||
poll_settings = poll.get_settings()
|
||||
# update the settings only after a submit (otherwise we clear all current settings)
|
||||
if submit:
|
||||
|
@ -461,12 +480,20 @@ def admin_poll(cancel=False, submit=None, admin_hash_key=None, author=None,
|
|||
data["settings"] = [key for key, value in poll_settings.items() if value is True]
|
||||
for key, value in (("expose_date", setting_expose_date), ("close_date", setting_close_date)):
|
||||
validated_value = validate_poll_setting(key, value)
|
||||
if value == "":
|
||||
data["setting_%s_forever" % key] = "yes"
|
||||
data["setting_%s" % key] = value
|
||||
else:
|
||||
data["setting_%s_forever" % key] = "no"
|
||||
if validated_value is None:
|
||||
# keep the entered value and report an error
|
||||
errors[key] = u"Ungültiges Datum"
|
||||
data["setting_%s" % key] = value
|
||||
else:
|
||||
data["setting_%s" % key] = get_poll_setting_string(key, validated_value)
|
||||
print "Vor Kontrolle:"
|
||||
for key, value in data.items():
|
||||
print " %s: %s" % (key, value)
|
||||
# use the validator to check for possible errors
|
||||
if submit:
|
||||
# check for errors only if the content is submitted (not just rendered)
|
||||
|
@ -474,6 +501,9 @@ def admin_poll(cancel=False, submit=None, admin_hash_key=None, author=None,
|
|||
data = forms.PollSettingsForm.to_python(data)
|
||||
except formencode.Invalid, errors_packed:
|
||||
errors = errors_packed.unpack_errors()
|
||||
print "Nach Kontrolle:"
|
||||
for key, value in data.items():
|
||||
print " %s: %s" % (key, value)
|
||||
# store the new settings
|
||||
if errors:
|
||||
value_dict["errors"] = errors
|
||||
|
|
Loading…
Reference in a new issue