Пример #1
0
    def generate_book_notes(self, username: str) -> str:
        def format_booknote(booknote: Mapping) -> dict:
            escaped_note = booknote['notes'].replace('"', '""')
            return {
                "work_id": f"OL{booknote['work_id']}W",
                "edition_id": f"OL{booknote['edition_id']}M",
                "note": f'"{escaped_note}"',
                "created_on": booknote['created'].strftime(self.date_format),
            }

        return csv_string(Booknotes.select_all_by_username(username),
                          format_booknote)
Пример #2
0
    def generate_book_notes(self, username):
        csv = []
        csv.append('Work ID,Edition ID,Note,Created On')
        notes = Booknotes.select_all_by_username(username)

        for note in notes:
            escaped_note = note['notes'].replace('"', '""')
            row = [
                f"OL{note['work_id']}W",
                f"OL{note['edition_id']}M",
                f'"{escaped_note}"',
                note['created'].strftime(self.date_format)
            ]
            csv.append(','.join(row))

        return '\n'.join(csv)