View Single Post
Old 10-08-2022, 10:42 AM   #15
chaley
Grand Sorcerer
chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.
 
Posts: 12,495
Karma: 8065348
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
Proof of concept

I did a proof of concept implementation using the code from the template functions implementation. It works.

Given the following template:
Code:
python:
def evaluate(self, mi, db):
    print(mi.authors)
    s = self.get_default_if_none(mi, 'series', '**no series**')
    return s + ':::' + str(self.get_default_if_none(mi, '#myint', 999))

def get_default_if_none(self, mi, field, default):
    v = mi.get(field, None)
    return default if v is None else v
The screen capture shows what I get in the template tester. The template tester still highlights strings and matching parentheses.

This isn't close to done. For example it doesn't include caching, error handling, or pulling the db out of the mi instance.
Attached Thumbnails
Click image for larger version

Name:	Clipboard01.jpg
Views:	1457
Size:	106.1 KB
ID:	197044  
chaley is offline   Reply With Quote