patt/creole.py

46 righe
1.4 KiB
Python

from django.urls.base import reverse
from .models import Project
def task_link_filter(text):
render_txt = ''
while len(text) > 0:
try:
pos = text.index('[[task:')
except ValueError:
pos = len(text)
render_txt += text[:pos]
text = text[pos + 7:]
if len(text):
pos = text.index(']]')
try:
task_id = int(text[:pos])
except ValueError:
render_txt += "[[task:" + text[:pos + 2]
else:
render_txt += '[[%s|#%d]]' % (reverse('patt-taskview', kwargs={'task_id': task_id}), task_id)
text = text[pos + 2:]
return render_txt
def tasklist_link_filter(text):
render_txt = ''
while len(text) > 0:
try:
pos = text.index('[[tasklist:')
except ValueError:
pos = len(text)
render_txt += text[:pos]
text = text[pos + 11:]
if len(text):
pos = text.index(']]')
try:
project_id = int(text[:pos])
except ValueError:
render_txt += "[[tasklist:" + text[:pos + 2]
else:
p = Project.objects.get(id=project_id)
render_txt += '[[%s|%s]]' % (reverse('patt-tasklist-prj', kwargs={'project_id': project_id}), p.name)
text = text[pos + 2:]
return render_txt