$def with (doc, decorations=None, cta=True, availability=None, extra=None) $ is_work = doc.get('type', {}).get('key') == '/type/work' $ book_url = doc.url() if is_work else doc.key $ book_provider = get_book_provider(doc) $if book_provider: $ work_edition_url = book_url + '?edition=' + urlquote(book_provider.get_best_identifier_slug(doc)) $else: $ work_edition_url = book_url