aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorElena ``of Valhalla'' Grandi <valhalla@trueelena.org>2017-08-05 16:58:45 +0200
committerElena ``of Valhalla'' Grandi <valhalla@trueelena.org>2017-08-05 16:58:45 +0200
commitc2885894c06e15a5be0b6a00edd8e0de7746b4a9 (patch)
tree65ea4e7498eff16030bf0a68b5c66471857f5c0d
parent96465262f72b1b4230513e978d8412d0affc75a1 (diff)
Fix printing Entry id when data includes the id
-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