-
Notifications
You must be signed in to change notification settings - Fork 244
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2887 from CannonLock/SOFTWARE-5443
Create Institution Endpoint (SOFTWARE-5443)
- Loading branch information
Showing
4 changed files
with
110 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
from flask import Response | ||
from .common import to_csv, to_json_bytes | ||
from typing import List | ||
|
||
def create_accepted_response(data: List, headers, default=None) -> Response: | ||
"""Provides CSV or JSON options for list of list(string)""" | ||
|
||
if not default: | ||
default = "application/json" | ||
|
||
accepted_response_builders = { | ||
"text/csv": lambda: Response(to_csv(data), mimetype="text/csv"), | ||
"application/json": lambda: Response(to_json_bytes(data), mimetype="application/json"), | ||
} | ||
|
||
requested_types = set(headers.get('Accept', 'default').replace(' ', '').split(",")) | ||
accepted_and_requested = set(accepted_response_builders.keys()).intersection(requested_types) | ||
|
||
if accepted_and_requested: | ||
return accepted_response_builders[accepted_and_requested.pop()]() | ||
else: | ||
return accepted_response_builders[default]() |