added admin page for review of recent link submissions

This commit is contained in:
lars 2013-02-23 18:37:00 +00:00
parent c0d3ec4341
commit 25de2207f7
1 changed files with 32 additions and 10 deletions

View File

@ -61,6 +61,9 @@ EXPORT_ENCODING = "utf-8"
EXPORT_CHARSET = "utf8"
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)
URL_DOMAIN_REGEX = r"(\A|\s|\()([a-zA-Z_\-\.]+\.[a-zA-Z]{2,4})(/|\)|\s|\Z)"
URL_PROTOCOL_REGEX = r"(\A|\s|\()(https?://[\w/\?\.\#=;,_\-\~&]*)(\)|\s|\Z)"
POLL_SETTINGS = {
"show_all_submissions": (bool, True),
@ -88,7 +91,7 @@ class ContentSubmission(sqlobject.SQLObject):
submitter = sqlobject.UnicodeCol()
content = sqlobject.UnicodeCol()
poll_id = sqlobject.ForeignKey("Poll", cascade=True)
timestamp_creation = sqlobject.DateTimeCol()
timestamp_creation = sqlobject.DateTimeCol(default=datetime.datetime.now)
def get_creation_time_string(self):
return str(self.timestamp_creation)
@ -157,7 +160,7 @@ class Poll(sqlobject.SQLObject):
admin_hash_key = sqlobject.StringCol()
title = sqlobject.UnicodeCol()
description = sqlobject.UnicodeCol()
timestamp_creation = sqlobject.DateTimeCol()
timestamp_creation = sqlobject.DateTimeCol(default=datetime.datetime.now)
def get_related_polls(self):
""" get all directly and indirectly connected polls up to a certain
@ -335,18 +338,25 @@ def get_markup_with_links(text):
return prefix + url + suffix
# surround all urls with html markup
text = genshi.escape(text)
text = re.sub(r"(\A|\s|\()([a-zA-Z_\-\.]+\.[a-zA-Z]{2,4})(/|\)|\s|\Z)",
expand_protocol, text)
text = re.sub(r"(\A|\s|\()(https?://[\w/\?\.\#=;,_\-\~&]*)(\)|\s|\Z)",
get_link_markup, text)
text = re.sub(URL_DOMAIN_REGEX, expand_protocol, text)
text = re.sub(URL_PROTOCOL_REGEX, get_link_markup, text)
return get_markup_with_formatted_linebreaks(text, "<br />")
def has_links(text):
if re.search(URL_DOMAIN_REGEX, text) or re.search(URL_PROTOCOL_REGEX, text):
return True
else:
return False
def get_markup_with_formatted_linebreaks(text, break_char):
text = text.replace("\r\n", "\n")
text = text.replace("\r", "\n")
text = text.replace("\n", break_char)
return text
def get_poll_setting_string(key, value):
if not key in POLL_SETTINGS.keys():
return ""
@ -770,10 +780,9 @@ def new_poll(bobo_request, submit=None, cancel=None, author=None, title=None,
# create the new poll
hash_key = get_new_hash_key()
admin_hash_key = get_new_hash_key()
now = datetime.datetime.now()
new_poll = Poll(hash_key=hash_key, admin_hash_key=admin_hash_key,
timestamp_creation=now, author=data["author"],
title=data["title"], description=data["description"])
author=data["author"], title=data["title"],
description=data["description"])
# apply the template settings
for key, value in template_settings.items():
new_poll.change_setting(key, value)
@ -896,7 +905,6 @@ def submit_content(bobo_request, hash_key=None, submitter=None, content=None):
return render("poll_details.html", input_data=data, **value_dict)
else:
# create the new submission content
data["timestamp_creation"] = datetime.datetime.now()
data["poll_id"] = poll.id
ContentSubmission(**data)
# remove "content" for the next input
@ -1230,6 +1238,20 @@ def admin_maintenance(age_days=60, keyword="viagra", keyword_submission="viagra"
return bobo.redirect("../admin")
@bobo.query('/admin/spam_test')
def show_spam_test_page(bobo_request, last_days=14):
try:
last_days = int(last_days)
except ValueError:
last_days = 7
now = datetime.datetime.now()
oldest = now - datetime.timedelta(days=last_days)
cs = ContentSubmission
submissions = [item for item in cs.select(cs.q.timestamp_creation >= oldest).orderBy("-timestamp_creation") if has_links(item.content)]
return render("admin_spam_test.html", submissions=submissions,
last_days=last_days, **get_default_values(bobo_request))
@bobo.query('/admin')
@bobo.query('/admin/')
@bobo.query('/admin/page/:page')