summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lesana/command.py28
1 files changed, 23 insertions, 5 deletions
diff --git a/lesana/command.py b/lesana/command.py
index 6d31b34..dd1864a 100644
--- a/lesana/command.py
+++ b/lesana/command.py
@@ -1,8 +1,10 @@
import logging
import os
import subprocess
+import sys
import guacamole
+import jinja2
from . import Collection, Entry
@@ -175,11 +177,27 @@ class Search(guacamole.Command):
pagesize = ctx.args.pagesize or 12
collection = Collection(ctx.args.collection)
collection.start_search(' '.join(ctx.args.query))
- # TODO: pass the entries to a proper template
- for entry in collection.get_search_results(
- offset,
- pagesize):
- print(entry)
+ results = collection.get_search_results(
+ offset,
+ pagesize)
+ if ctx.args.template:
+ env = jinja2.Environment(
+ loader=jinja2.FileSystemLoader(
+ searchpath='.',
+ followlinks=True,
+ ),
+ # TODO: add autoescaping settings
+ )
+ try:
+ template = env.get_template(ctx.args.template)
+ except jinja2.exceptions.TemplateNotFound as e:
+ logging.error("Could not find template: {}".format(e))
+ sys.exit(1)
+ else:
+ print(template.render(entries=results))
+ else:
+ for entry in results:
+ print(entry)
class Init(guacamole.Command):