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):
|
class PollSettingsForm(PollForm):
|
||||||
settings = formencode.validators.Set()
|
settings = formencode.validators.Set()
|
||||||
setting_expose_date = formencode.validators.UnicodeString(strip=True, not_empty=True)
|
setting_expose_date = formencode.validators.UnicodeString(strip=True)
|
||||||
setting_close_date = formencode.validators.UnicodeString(strip=True, not_empty=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):
|
class SubmitForm(formencode.Schema):
|
||||||
submitter = formencode.validators.UnicodeString(strip=True, not_empty=True)
|
submitter = formencode.validators.UnicodeString(strip=True, not_empty=True)
|
||||||
|
|
|
@ -217,9 +217,12 @@ def get_poll_setting_string(key, value):
|
||||||
elif setting_type == bool:
|
elif setting_type == bool:
|
||||||
return str(value)
|
return str(value)
|
||||||
elif setting_type == datetime.datetime:
|
elif setting_type == datetime.datetime:
|
||||||
# some old entries are invalid
|
# unset dates are None
|
||||||
if value is None:
|
if value is None:
|
||||||
return ""
|
return ""
|
||||||
|
elif value == "":
|
||||||
|
# value for "forever"
|
||||||
|
return ""
|
||||||
else:
|
else:
|
||||||
return value.strftime(DATE_FORMAT)
|
return value.strftime(DATE_FORMAT)
|
||||||
else:
|
else:
|
||||||
|
@ -250,6 +253,9 @@ def validate_poll_setting(key, value):
|
||||||
value = datetime.date.today() + datetime.timedelta(days=DEFAULT_DAYS_AHEAD)
|
value = datetime.date.today() + datetime.timedelta(days=DEFAULT_DAYS_AHEAD)
|
||||||
elif type(value) == datetime.datetime:
|
elif type(value) == datetime.datetime:
|
||||||
pass
|
pass
|
||||||
|
elif value == "":
|
||||||
|
# this is the value for "forever"
|
||||||
|
return ""
|
||||||
else:
|
else:
|
||||||
try:
|
try:
|
||||||
value = datetime.datetime.strptime(value, DATE_FORMAT)
|
value = datetime.datetime.strptime(value, DATE_FORMAT)
|
||||||
|
@ -421,8 +427,15 @@ def delete_poll(admin_hash_key=None):
|
||||||
|
|
||||||
@bobo.query('/:admin_hash_key/admin')
|
@bobo.query('/:admin_hash_key/admin')
|
||||||
def admin_poll(cancel=False, submit=None, admin_hash_key=None, author=None,
|
def admin_poll(cancel=False, submit=None, admin_hash_key=None, author=None,
|
||||||
title=None, description=None, settings=None, setting_expose_date=None,
|
title=None, description=None, settings=None,
|
||||||
setting_close_date=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()
|
value_dict = get_default_values()
|
||||||
data = {"author": author, "title": title, "description": description, "template": ""}
|
data = {"author": author, "title": title, "description": description, "template": ""}
|
||||||
poll_id = get_poll_admin_id(admin_hash_key)
|
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
|
data["title"] = poll.title
|
||||||
if description is None:
|
if description is None:
|
||||||
data["description"] = poll.description
|
data["description"] = poll.description
|
||||||
if setting_expose_date is None:
|
if setting_expose_date_forever is None:
|
||||||
setting_expose_date = poll.get_settings_strings()["expose_date"]
|
if setting_expose_date is None:
|
||||||
if setting_close_date is None:
|
setting_expose_date = poll.get_settings_strings()["expose_date"]
|
||||||
setting_close_date = poll.get_settings_strings()["close_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()
|
poll_settings = poll.get_settings()
|
||||||
# update the settings only after a submit (otherwise we clear all current settings)
|
# update the settings only after a submit (otherwise we clear all current settings)
|
||||||
if submit:
|
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]
|
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)):
|
for key, value in (("expose_date", setting_expose_date), ("close_date", setting_close_date)):
|
||||||
validated_value = validate_poll_setting(key, value)
|
validated_value = validate_poll_setting(key, value)
|
||||||
if validated_value is None:
|
if value == "":
|
||||||
# keep the entered value and report an error
|
data["setting_%s_forever" % key] = "yes"
|
||||||
errors[key] = u"Ungültiges Datum"
|
|
||||||
data["setting_%s" % key] = value
|
data["setting_%s" % key] = value
|
||||||
else:
|
else:
|
||||||
data["setting_%s" % key] = get_poll_setting_string(key, validated_value)
|
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
|
# use the validator to check for possible errors
|
||||||
if submit:
|
if submit:
|
||||||
# check for errors only if the content is submitted (not just rendered)
|
# 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)
|
data = forms.PollSettingsForm.to_python(data)
|
||||||
except formencode.Invalid, errors_packed:
|
except formencode.Invalid, errors_packed:
|
||||||
errors = errors_packed.unpack_errors()
|
errors = errors_packed.unpack_errors()
|
||||||
|
print "Nach Kontrolle:"
|
||||||
|
for key, value in data.items():
|
||||||
|
print " %s: %s" % (key, value)
|
||||||
# store the new settings
|
# store the new settings
|
||||||
if errors:
|
if errors:
|
||||||
value_dict["errors"] = errors
|
value_dict["errors"] = errors
|
||||||
|
|
Loading…
Reference in a new issue