Skip to content

Commit 3f062e4

Browse files
vijaykalamVijay Kalambekar
andauthored
feat: expose custom columns as category elements in OPDS feed
Co-authored-by: Vijay Kalambekar <vijaykalambekar-external@worldfamilyenglish.com>
1 parent f182ff4 commit 3f062e4

2 files changed

Lines changed: 23 additions & 0 deletions

File tree

cps/db.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -436,6 +436,24 @@ def __repr__(self):
436436
def atom_timestamp(self):
437437
return self.timestamp.strftime('%Y-%m-%dT%H:%M:%S+00:00') or ''
438438

439+
@property
440+
def custom_extra_fill(self):
441+
out = []
442+
for col_id in cc_classes:
443+
val = getattr(self, 'custom_column_' + str(col_id), None)
444+
if val:
445+
col_def = CalibreDB.session_factory().query(CustomColumns).filter(CustomColumns.id == col_id).first()
446+
name = col_def.name if col_def else "Column {}".format(col_id)
447+
values = val if isinstance(val, list) else [val]
448+
for item in values:
449+
if hasattr(item, 'value'):
450+
out.append({
451+
'name': name,
452+
'value': item.value
453+
})
454+
return out
455+
456+
439457
@property
440458
def isbn(self):
441459
for identifier in self.identifiers:

cps/templates/feed.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,11 @@
6363
term="{{tag.name}}"
6464
label="{{tag.name}}"/>
6565
{% endfor %}
66+
{% for cc in entry.Books.custom_extra_fill %}
67+
<category scheme="custom_column:{{cc.name}}"
68+
term="{{cc.name}}"
69+
label="{{cc.value}}"/>
70+
{% endfor %}
6671
{% if entry.Books.comments[0] %}<summary>{{entry.Books.comments[0].text|striptags}}</summary>{% endif %}
6772
{% if entry.Books.has_cover %}
6873
<link type="image/jpeg" href="{{url_for('opds.feed_get_cover', book_id=entry.Books.id)}}" rel="http://opds-spec.org/image"/>

0 commit comments

Comments
 (0)