Skip to content

Commit

Permalink
Delegate date strings formatting to datetime.isoformat()
Browse files Browse the repository at this point in the history
The SecureDrop SDK now supports date stings in ISO8061 format,
so we can stop relying on custom-defined formats.

The custom JSON formatter made this a one-line change! 🎉  @legoktm
  • Loading branch information
gonzalo-bulnes committed Apr 27, 2022
1 parent b917f9c commit 1eff662
Showing 1 changed file with 1 addition and 3 deletions.
4 changes: 1 addition & 3 deletions securedrop/journalist_app/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,6 @@
from werkzeug.exceptions import HTTPException # noqa: F401

_insecure_views = ['main.login', 'static']
# Timezone-naive datetime format expected by SecureDrop Client
API_DATETIME_FORMAT = "%Y-%m-%dT%H:%M:%S.%fZ"


def get_logo_url(app: Flask) -> str:
Expand Down Expand Up @@ -75,7 +73,7 @@ class JSONEncoder(json.JSONEncoder):

def default(self, obj: 'Any') -> 'Any':
if isinstance(obj, datetime):
return obj.strftime(API_DATETIME_FORMAT)
return obj.isoformat()
super(JSONEncoder, self).default(obj)

app.json_encoder = JSONEncoder
Expand Down

0 comments on commit 1eff662

Please sign in to comment.