diff --git a/wortschlucker/database.sqlite b/wortschlucker/database.sqlite index a4b7ddd..ac96d5e 100644 Binary files a/wortschlucker/database.sqlite and b/wortschlucker/database.sqlite differ diff --git a/wortschlucker/templates/poll_details.html b/wortschlucker/templates/poll_details.html index e2a5457..56c1688 100644 --- a/wortschlucker/templates/poll_details.html +++ b/wortschlucker/templates/poll_details.html @@ -36,7 +36,7 @@ SubmitterContentTimestamp ${one_submission.submitter} - ${one_submission.content} + ${one_submission.get_markup_content()} ${one_submission.get_creation_time_string()} diff --git a/wortschlucker/wortschlucker.py b/wortschlucker/wortschlucker.py index 905703c..9308d0f 100755 --- a/wortschlucker/wortschlucker.py +++ b/wortschlucker/wortschlucker.py @@ -1,27 +1,29 @@ #!/usr/bin/env python2.6 -# add the current directory to the python search path +import os +BASE_DIR = os.path.dirname(os.path.abspath(__file__)) +# add the project directory to the python search path import sys -sys.path.insert(0, "./") +sys.path.insert(0, BASE_DIR) import forms import sqlobject import bobo from genshi.template import TemplateLoader import genshi.filters +import genshi.input import genshi import formencode -import uuid import datetime -import os -import mimetypes import webob +import mimetypes +import uuid +import re -db_filename = "database.sqlite" -db_filename = os.path.abspath(db_filename) +db_filename = os.path.join(BASE_DIR, "database.sqlite") database = sqlobject.connectionForURI("sqlite://" + db_filename) sqlobject.sqlhub.processConnection = database -loader = TemplateLoader(os.path.join(os.path.dirname(__file__), 'templates'), auto_reload=True) +loader = TemplateLoader(os.path.join(BASE_DIR, 'templates'), auto_reload=True) BASE_DICT = { "base_url": "/", # the trailing slash is necessary @@ -42,6 +44,18 @@ class ContentSubmission(sqlobject.SQLObject): def get_creation_time_string(self): return str(self.timestamp_creation) + def get_markup_content(self): + def get_link_markup(match): + prefix, url, suffix = match.groups() + # only take the TLD part of the url + short_name = url.split("/")[2] + return """%s%s%s""" % (prefix, url, short_name, suffix) + # surround all urls with html markup + mark_links = re.sub(r"(\A|\s)(https?://[\w/\?\.\#=;,]*)(\s|\Z)", get_link_markup, self.content) + markup = genshi.input.HTML(mark_links) | genshi.filters.HTMLSanitizer() + # the markup is now marked as "safe" -> genshi will output it literally + return markup + class PollSetting(sqlobject.SQLObject): poll_id = sqlobject.ForeignKey("Poll") @@ -124,7 +138,7 @@ def validate_poll_setting(key, value): return value elif setting_type == bool: text = value.tolower() - if text in ("0", "false", "no", "off", "disabled"): + if text in ("0", "false", "no", "off", "disabled", ""): return False elif text in ("1", "true", "yes", "on", "enabled"): return True @@ -328,49 +342,25 @@ for table in (Poll, ContentSubmission, PollSetting): for poll in Poll.select(): print poll -####### Ab hier hat m rumgesaut -### das ist natuerlich voellig falsch, aber so kann ich schnell mit dem Layout anfangen. -### Aender es also ruhig ab! - -@bobo.query('/media/:pathname') -def statische_sachen(pathname): - response = webob.Response() - content_type = mimetypes.guess_type(pathname)[0] - if content_type is not None: - response.content_type = content_type - try: - response.body = open("templates/media/"+pathname).read() - - except IOError: - - raise bobo.NotFound - return response +@bobo.query('/media/:p1') +@bobo.query('/media/:p1/:p2') +@bobo.query('/media/:p1/:p2/:p3') +def static_files(p1=None, p2=None, p3=None): + pathlist = [p1, p2, p3] + pathname = os.path.join(BASE_DIR, "templates", "media") + for subdir in pathlist: + if not subdir is None: + pathname = os.path.join(pathname, subdir) + response = webob.Response() + content_type = mimetypes.guess_type(pathname)[0] + if content_type is not None: + response.content_type = content_type + try: + response.body = open(pathname).read() + except IOError: + raise bobo.NotFound + return response - -@bobo.query('/media/images/:pathname') -def statische_sachen2(pathname): - response = webob.Response() - content_type = mimetypes.guess_type(pathname)[0] - if content_type is not None: - response.content_type = content_type - try: - response.body = open("templates/media/images/"+pathname).read() - - except IOError: - - raise bobo.NotFound - return response - - - - - - - - - -####### bis hier hier hat m rumgesaut - # this line allows to use wortschlucker with mod_wsgi # see: http://groups.google.com/group/bobo-web/msg/2ba55fc381658cd1 #application = bobo.Application(bobo_resources=__name__)