From 79c516c90e5f9e2ba1ce081e7bd8e6749f127caf Mon Sep 17 00:00:00 2001 From: lars Date: Thu, 15 Apr 2010 18:17:05 +0000 Subject: [PATCH] added link markup added correct handling for the project's base dir simplified static request handling --- wortschlucker/database.sqlite | Bin 4096 -> 7168 bytes wortschlucker/templates/poll_details.html | 2 +- wortschlucker/wortschlucker.py | 92 ++++++++++------------ 3 files changed, 42 insertions(+), 52 deletions(-) diff --git a/wortschlucker/database.sqlite b/wortschlucker/database.sqlite index a4b7dddc78f53aa3bd36b2f0c9ff94e25f0e0a8e..ac96d5ec74ecbfa33f1d747bb6d7e4a3e4fa73dc 100644 GIT binary patch literal 7168 zcmeHL-EJF26yBdSN!yf?mJmWoJ55QGs6Uy%{cQu7bg9C|Y3mq?UPZGzv$3h|4ZCYx zkPu1{4}io)AAlD?757NJgM^s1L$Q;z^kQ$I9@+BDoa67D@0>leXLs|? zdOZ^$ijyYG08vI1RaM>rKv5JZzx_j(3$<^ff8Mu!aC$;+>1wR#L?iO&MIO5)eQbJu zUVY$YENF1{o(@>OwXs>Pl%#qOs4LkL_v>kvf{OQ^SMfGhz0Iz0vCfx359OZt z6jZ$rtG(4HtkD+T^|7Vh&$Y2>gw!wRyBxx}m5Elim9~RsJx%Lz>)?()z~`X+Iaqb! zvrHs?UhM((?G(d3t2afOvF6TJmigeRXVlYD#_3d6L82tTw)m+B!s#)w4z~DZM0dk%mcqr|0jJ)IFO_UYjG@yrO@j z1MQKV49746`y;S>d}LfXT`r$ygr!^yG?9r2G@T$~EDD8TTFl_owrxy}2r|S29z=o>5fQ@8E=XRke7oNm zbt!QToM_|9Y`J`4ifrcRTb8jXLY7IbfZ0|^naLQ#c4%-j40s4}7*G;Afn+H{%b`Tl z=iH0}Zdsuf5P_`?))cKYZHG0H$y27^CUL3hLi~|Bu1uB7(=%k9B`HCe$%rBnh0-3y zPDCsjOdAF!H(|sqgCZ&{%Ze;P2@mWLI*d4k6K+6e@v1a}TI~d+@t`f_xQ2B^=33K# z&oe%z|IwT5PycW|jKDAg|FZ~;o|S}-oXYS2vgsd=VFZQ|cmX4j*Z(O6Df-X)_xjiR zw(jZ^+Hcwq+C#0Sm9z=CM(|tRVYZsZw2AUH4WHg2=qKDL1i$ zx1HLy*|}4yz*6Z(`{R3+4n^1|G@uZh*g=*MP?&+Rg`kFInZf{9fZ?^1SnqFboV-tj z*6zaOf521A#dP-NQDyRE9??wgCt|pUBOBh?lg|?4xtB&2`8Y~C?c}pOC;K2Ebs@TN zVpN%yI^AYBR~iVI>~&4ofMh}{8GA~5X-#FXDrBpEHBPpd_y38yhH>e*w7#HrTh&$^ z)_|zXr)6jf#d+>8@(5DTNrqf%$7XS3bn;BPu2*{6+77aNz396~&k#1BzM ziz8C`{9u$0!Wu3%=k$LZJ&;Wz?YamqX)-u_X!z+~%EZ&Ns=Rh4RZ&xEG_3xjK2&|>Pvtu)C}8+!rMp5U@@QzpY1|Z9O}_5}*L!a(-l~a2 zfQ|s$@%81sEs%#l9jIyyWl6gT`LhLq$txcFZxjZGE&ohmV9@qoF9=MYA;_O842(ek zwSvHqOB{c?FfdH~R|^2kpNi!Tg!og%fg%5ug1~Iop#JHCz=(@*UjIjBu^&?Z1yueE z1>r9gkQaH(A?zaJUn~d=%6qgwUlsL0M?Tzfc?)_U8%%qtHKJ7#K8sP!O2y NQtF>82+VS+^B2__LHYmy delta 39 vcmZp$Xi%6S%_zB1<_SAHF9QRE0AuT9b^)c$LM$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__)