summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lesana/collection.py16
-rw-r--r--lesana/command.py3
-rw-r--r--tests/test_collection.py1
3 files changed, 14 insertions, 6 deletions
diff --git a/lesana/collection.py b/lesana/collection.py
index dc005bb..966741c 100644
--- a/lesana/collection.py
+++ b/lesana/collection.py
@@ -33,13 +33,17 @@ class Entry(object):
label = self.collection.settings.get('entry_label', None)
if label:
t = jinja2.Template(label)
- data = self.data
- data['uid'] = self.uid
- data['fname'] = self.fname
- return t.render(**data)
+ return t.render(**self.get_data())
else:
return self.uid
+ def get_data(self):
+ d = self.data.copy()
+ d['uid'] = self.uid
+ d['fname'] = self.fname
+ d['short_id'] = self.short_id
+ return d
+
def empty_data(self):
data = ''
for field in self.collection.settings['fields']:
@@ -64,6 +68,10 @@ class Entry(object):
def idterm(self):
return "Q"+self.uid
+ @property
+ def short_id(self):
+ return self.uid[:8]
+
def validate(self):
errors = []
valid = True
diff --git a/lesana/command.py b/lesana/command.py
index 7f683c8..dbad2d2 100644
--- a/lesana/command.py
+++ b/lesana/command.py
@@ -217,8 +217,7 @@ class Search(Command):
print(template.render(entries=results))
else:
for entry in results:
- print("{suid}: {entry}".format(
- suid=entry.uid[:8],
+ print("{entry}".format(
entry=entry,
))
diff --git a/tests/test_collection.py b/tests/test_collection.py
index cc28a27..66f034a 100644
--- a/tests/test_collection.py
+++ b/tests/test_collection.py
@@ -169,6 +169,7 @@ class testEntries(unittest.TestCase):
data = ruamel.yaml.safe_load(fp)
entry = lesana.Entry(self.collection, data=data, fname=fname)
self.assertEqual(entry.idterm, 'Q'+uid)
+ self.assertEqual(entry.short_id, uid[:8])
def test_write_new(self):
new_entry = lesana.Entry(self.collection)