if not all(key in payload for key in payloads[template]):
raise InvalidPayloadException
if 'order_date' in payload:
payload['order_date'] = self._get_formatted_date(payload['order_date'])
if 'payment_date' in payload:
payload['payment_date'] = self._get_formatted_date(payload['payment_date'])
if 'shipped_date' in payload:
payload['shipped_date'] = self._get_formatted_date(payload['shipped_date'])
I have some code that triggers a PDF generation. It accepts a python dict that contains the payload for the PDF.
There are a good few number of dates that need to be displayed in the PDF but not all documents contain all PDFs. I need to format the dates before sending it to the PDF. At the moment my code is a lot of different IF statements to catch all the possible dates and format them in the dict.
Is there a more pythonic way to do it?