mirror of
https://github.com/postgres/pgweb.git
synced 2025-08-03 15:38:59 +00:00
Add filter to list all templates in a directory
This commit is contained in:
@ -2,7 +2,10 @@ from django.template.defaultfilters import stringfilter
|
||||
from django import template
|
||||
from django.utils.safestring import mark_safe
|
||||
from django.template.loader import get_template
|
||||
from django.conf import settings
|
||||
|
||||
import os
|
||||
from pathlib import Path
|
||||
import json
|
||||
import pynliner
|
||||
|
||||
@ -103,6 +106,13 @@ def joinandor(value, andor):
|
||||
return ", ".join([str(x) for x in value[:-1]]) + ' ' + andor + ' ' + str(value[-1])
|
||||
|
||||
|
||||
@register.filter()
|
||||
def list_templates(value):
|
||||
for f in Path(os.path.join(settings.PROJECT_ROOT, '../templates/', value)).iterdir():
|
||||
if f.is_file() and f.suffix == '.html':
|
||||
yield f.stem
|
||||
|
||||
|
||||
@register.simple_tag(takes_context=True)
|
||||
def git_changes_link(context):
|
||||
return mark_safe('<a href="https://git.postgresql.org/gitweb/?p=pgweb.git;a=history;f=templates/{}">View</a> change history.'.format(context.template_name))
|
||||
|
Reference in New Issue
Block a user