implemented functions for checking "exposed" and "closed" status of a poll
export filename prefix is now configurable (default: wortschlucker)
This commit is contained in:
parent
7281b0f147
commit
ffbdaa4351
1 changed files with 16 additions and 3 deletions
|
@ -53,7 +53,7 @@ DATE_FORMAT = "%d.%m.%Y"
|
||||||
EXPORT_DATE_FORMAT = "%d.%m.%Y %H:%M:%S"
|
EXPORT_DATE_FORMAT = "%d.%m.%Y %H:%M:%S"
|
||||||
EXPORT_ENCODING = "utf-8"
|
EXPORT_ENCODING = "utf-8"
|
||||||
EXPORT_CHARSET = "utf8"
|
EXPORT_CHARSET = "utf8"
|
||||||
EXPORT_FILENAME_TEMPLATE = "wortschlucker_%%s_%s.csv" % datetime.datetime.now().strftime("%Y-%m-%d")
|
EXPORT_FILENAME_TEMPLATE = "%%(prefix)s_%%(title)s_%s.csv" % datetime.datetime.now().strftime("%Y-%m-%d")
|
||||||
DEFAULT_DATE = datetime.datetime.now() + datetime.timedelta(days=DEFAULT_DAYS_AHEAD)
|
DEFAULT_DATE = datetime.datetime.now() + datetime.timedelta(days=DEFAULT_DAYS_AHEAD)
|
||||||
|
|
||||||
POLL_SETTINGS = {
|
POLL_SETTINGS = {
|
||||||
|
@ -224,6 +224,15 @@ class Poll(sqlobject.SQLObject):
|
||||||
def get_creation_time_string(self):
|
def get_creation_time_string(self):
|
||||||
return str(self.timestamp_creation)
|
return str(self.timestamp_creation)
|
||||||
|
|
||||||
|
def get_submissions_visibility(self):
|
||||||
|
settings = self.get_settings()
|
||||||
|
return bool(settings["show_all_submissions"] or (settings["expose_date"] and \
|
||||||
|
(settings["expose_date"].date() <= datetime.datetime.now().date())))
|
||||||
|
|
||||||
|
def is_closed(self):
|
||||||
|
return bool(self.get_settings()["close_date"] and \
|
||||||
|
(self.get_settings()["close_date"].date() < datetime.datetime.now().date()))
|
||||||
|
|
||||||
|
|
||||||
class PollMesh:
|
class PollMesh:
|
||||||
""" generate a mesh of directly or indirectly related polls
|
""" generate a mesh of directly or indirectly related polls
|
||||||
|
@ -492,7 +501,7 @@ def submit_content(hash_key=None, submitter=None, content=None):
|
||||||
data = forms.SubmitForm.to_python(data)
|
data = forms.SubmitForm.to_python(data)
|
||||||
except formencode.Invalid, errors_packed:
|
except formencode.Invalid, errors_packed:
|
||||||
errors = errors_packed.unpack_errors()
|
errors = errors_packed.unpack_errors()
|
||||||
if errors:
|
if errors or poll.is_closed():
|
||||||
value_dict["errors"] = errors
|
value_dict["errors"] = errors
|
||||||
return render("poll_details.html", input_data=data, **value_dict)
|
return render("poll_details.html", input_data=data, **value_dict)
|
||||||
else:
|
else:
|
||||||
|
@ -547,7 +556,11 @@ def export_poll(admin_hash_key=None):
|
||||||
for index in range(len(items)):
|
for index in range(len(items)):
|
||||||
items[index] = items[index].encode(EXPORT_ENCODING, "ignore")
|
items[index] = items[index].encode(EXPORT_ENCODING, "ignore")
|
||||||
writer.writerow(items)
|
writer.writerow(items)
|
||||||
filename = EXPORT_FILENAME_TEMPLATE % poll.title
|
try:
|
||||||
|
export_prefix = config.get("misc", "export_prefix")
|
||||||
|
except ConfigParser.Error:
|
||||||
|
export_prefix = "wortschlucker"
|
||||||
|
filename = EXPORT_FILENAME_TEMPLATE % {"title": poll.title, "prefix": export_prefix}
|
||||||
filename = filename.replace(" ", "_")
|
filename = filename.replace(" ", "_")
|
||||||
filename = re.sub(r"[^a-zA-Z0-9_\-\.]", "", filename)
|
filename = re.sub(r"[^a-zA-Z0-9_\-\.]", "", filename)
|
||||||
response.content_disposition = 'attachment; filename=%s' % filename
|
response.content_disposition = 'attachment; filename=%s' % filename
|
||||||
|
|
Loading…
Reference in a new issue