From 20d5e087cb3caac5b6c7c1944dcacbdc0c02ca74 Mon Sep 17 00:00:00 2001 From: ville rantanen Date: Mon, 4 Jul 2016 09:03:55 +0300 Subject: [PATCH] urlify --- shop.py | 7 ++++++- templates/layout.html | 2 +- templates/show_shop.html | 2 +- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/shop.py b/shop.py index 8e4bcce..12890f3 100644 --- a/shop.py +++ b/shop.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- # all the imports -import sqlite3, time, datetime, hashlib, os +import sqlite3, time, datetime, hashlib, os,re from shutil import copyfile from flask import Flask, request, session, g, redirect, url_for, \ abort, render_template, flash @@ -13,6 +13,7 @@ DEBUG = False SECRET_KEY = 'development key' USERNAME = 'admin' PASSWORD = 'default' +URLFINDER = re.compile("((news|telnet|nttp|file|http|ftp|https)://[^ ]+)") # create our little application :) app = Flask(__name__) @@ -85,6 +86,9 @@ def scan_for_new_documents(id): [shop, id]) g.db.commit() +def urlify(s): + return URLFINDER.sub(r'\1', s) + @app.before_request def before_request(): g.db = connect_db() @@ -126,6 +130,7 @@ def show_shop(shopid): if "[ ]" in row or "[x]" in row: icon=u"\u2714" extra_class="" + row=urlify(row) entries.append( dict(row=i, text=row, icon=icon, extra_class=extra_class) ) shared_to=[] cur = g.db.execute('select * from shares') diff --git a/templates/layout.html b/templates/layout.html index 3ae098a..6f34231 100644 --- a/templates/layout.html +++ b/templates/layout.html @@ -2,7 +2,7 @@ -Shop +MDShop diff --git a/templates/show_shop.html b/templates/show_shop.html index d5253e6..9f516ce 100644 --- a/templates/show_shop.html +++ b/templates/show_shop.html @@ -6,7 +6,7 @@
{% for entry in entries %} - {{ entry.text }}
+ {{ entry.text|safe }}
{% endfor %}