diff --git a/app/app.py b/app/app.py index 7c459b9..ab2eb6a 100644 --- a/app/app.py +++ b/app/app.py @@ -1,4 +1,5 @@ import os +import re from flask import Flask, render_template, redirect, url_for, request, flash from flask_migrate import Migrate from werkzeug.security import generate_password_hash, check_password_hash @@ -195,7 +196,7 @@ def events(): events = Event.query.all() periods = Period.query.all() - return render_template('events.html', events=events, periods=periods, datetime=datetime, date=date, ZoneInfo=ZoneInfo) + return render_template('events.html', events=events, periods=periods, datetime=datetime, date=date, ZoneInfo=ZoneInfo, re=re) @app.route('/event/edit//', methods=('GET', 'POST')) @login_required @@ -218,13 +219,13 @@ def editEvent(event_id): @login_required def tasks(): tasks = Task.query.all() - return render_template('tasks.html', str=str, tasks=tasks, datetime=datetime, date=date) + return render_template('tasks.html', str=str, tasks=tasks, datetime=datetime, date=date, re=re) @app.route('/task//') @login_required def task(task_id): task = Task.query.get_or_404(task_id) - return render_template('task.html', str=str, task=task, datetime=datetime, date=date) + return render_template('task.html', str=str, task=task, datetime=datetime, date=date, re=re) @app.route('/task/new', methods=('GET', 'POST')) @login_required diff --git a/app/templates/events.html b/app/templates/events.html index f0dea65..366845c 100644 --- a/app/templates/events.html +++ b/app/templates/events.html @@ -21,7 +21,17 @@
{% if event.tasks.description != None %} -

{{ event.tasks.description }}

+ {% set description = event.tasks.description %} + {% set url_regex = '(https?://[^\s]+)' %} + + {% set match = re.search(url_regex, description) %} + {% if match %} + {% set url = match.group(0) %} + {% set rest = description[match.end(0):] %} +

{{ description[:match.start(0)] }}{{ url }}{{ rest }}

+ {% else %} +

{{ description }}

+ {% endif %} {% endif %}
{% else %} diff --git a/app/templates/task.html b/app/templates/task.html index 886659b..071c3c7 100644 --- a/app/templates/task.html +++ b/app/templates/task.html @@ -9,7 +9,17 @@

{% if task.description != None %} -

{{ task.description }}

+ {% set description = task.description %} + {% set url_regex = '(https?://[^\s]+)' %} + + {% set match = re.search(url_regex, description) %} + {% if match %} + {% set url = match.group(0) %} + {% set rest = description[match.end(0):] %} +

{{ description[:match.start(0)] }}{{ url }}{{ rest }}

+ {% else %} +

{{ description }}

+ {% endif %} {% endif %}
diff --git a/app/templates/tasks.html b/app/templates/tasks.html index e7f0db8..9e39ed7 100644 --- a/app/templates/tasks.html +++ b/app/templates/tasks.html @@ -12,7 +12,17 @@ {% if task.description != None %} - {{ task.description }} + {% set description = task.description %} + {% set url_regex = '(https?://[^\s]+)' %} + + {% set match = re.search(url_regex, description) %} + {% if match %} + {% set url = match.group(0) %} + {% set rest = description[match.end(0):] %} +

{{ description[:match.start(0)] }}{{ url }}{{ rest }}

+ {% else %} +

{{ description }}

+ {% endif %} {% endif %}