aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lesana/collection.py8
-rw-r--r--tests/test_collection.py20
2 files changed, 24 insertions, 4 deletions
diff --git a/lesana/collection.py b/lesana/collection.py
index da001ae..2ac99aa 100644
--- a/lesana/collection.py
+++ b/lesana/collection.py
@@ -33,10 +33,10 @@ class Entry(object):
label = self.collection.settings.get('entry_label', None)
if label:
t = jinja2.Template(label)
- return t.render(
- uid=self.uid,
- fname=self.fname,
- **self.data)
+ data = self.data
+ data['uid'] = self.uid
+ data['fname'] = self.fname
+ return t.render(**data)
else:
return self.uid
diff --git a/tests/test_collection.py b/tests/test_collection.py
index 5c326e3..869828a 100644
--- a/tests/test_collection.py
+++ b/tests/test_collection.py
@@ -196,6 +196,26 @@ class testEntries(unittest.TestCase):
entry = lesana.Entry(self.collection, data=data, fname=fname)
self.assertEqual(entry.uid, uid)
+ def test_entry_str_filename_and_uid(self):
+ fname = '11189ee47ddf4796b718a483b379f976.yaml'
+ with open(os.path.join(self.basepath, fname)) as fp:
+ data = ruamel.yaml.safe_load(fp)
+ data['uid'] = '11189ee47ddf4796b718a483b379f976'
+ entry = lesana.Entry(self.collection, data=data)
+ self.assertEqual(str(entry), data['uid'])
+ self.collection.settings['entry_label'] = '{{ uid }}: {{ name }}'
+ self.assertEqual(str(entry), data['uid'] + ': Another item')
+
+ def test_entry_str_filename_no_uid(self):
+ fname = '11189ee47ddf4796b718a483b379f976.yaml'
+ with open(os.path.join(self.basepath, fname)) as fp:
+ data = ruamel.yaml.safe_load(fp)
+ entry = lesana.Entry(self.collection, data=data)
+ uid = entry.uid
+ self.assertEqual(str(entry), uid)
+ self.collection.settings['entry_label'] = '{{ uid }}: {{ name }}'
+ self.assertEqual(str(entry), uid + ': Another item')
+
class testComplexCollection(unittest.TestCase):
@classmethod