-
Notifications
You must be signed in to change notification settings - Fork 19
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Reactivate Japanese Locale #542
Changes from all commits
85d3dbe
ed47b7c
35826d8
8865a76
2539ef1
7347f83
af411e7
77a442e
974fbe4
7163e5b
aefab1a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -742,6 +742,59 @@ def migrate_96(TRN): | |
(r[0], hsi)) | ||
TRN.execute() | ||
|
||
@staticmethod | ||
def migrate_133(TRN): | ||
ffq_key_path = SERVER_CONFIG["japanese_ffqs_path_key"] | ||
ffq_file_path = SERVER_CONFIG["japanese_ffqs_path_reports"] | ||
|
||
# The below string translates to "Food frequency questionnaire" | ||
JFFQ_FILE_LABEL = "食物摂取頻度調査票" | ||
|
||
if not os.path.exists(ffq_key_path): | ||
print("Key not found:" + ffq_key_path) | ||
return | ||
|
||
with open(ffq_key_path) as csv_file: | ||
csv_contents = csv.reader(csv_file) | ||
header = True | ||
|
||
for csv_row in csv_contents: | ||
if header: | ||
header = False | ||
continue | ||
ffq_id, barcode = csv_row | ||
|
||
# Find the source associated with the barcode and make sure | ||
# it wasn't scrubbed or removed | ||
TRN.add( | ||
"SELECT akb.source_id " | ||
"FROM ag.ag_kit_barcodes akb " | ||
"INNER JOIN ag.source s " | ||
"ON akb.source_id = s.id " | ||
"WHERE akb.barcode = %s AND s.date_revoked IS NULL", | ||
(barcode, ) | ||
) | ||
rows = TRN.execute()[-1] | ||
|
||
if len(rows) == 1: | ||
row = rows[0] | ||
source_id = row[0] | ||
pdf_name = ffq_id + ".pdf" | ||
pdf_path = ffq_file_path + pdf_name | ||
pdf_contents = open(pdf_path, "rb").read() | ||
|
||
TRN.add( | ||
"INSERT INTO ag.external_reports (" | ||
"source_id, file_name, file_title, file_type, " | ||
"file_contents, report_type" | ||
") VALUES (%s, %s, %s, %s, %s, %s)", | ||
(source_id, pdf_name, JFFQ_FILE_LABEL, | ||
"application/pdf", pdf_contents, "ffq") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It looks like the MIME type is stored along side the contents, why not pull this out for the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The |
||
) | ||
else: | ||
print("No mapping: " + ffq_id + " - " + barcode) | ||
TRN.execute() | ||
|
||
MIGRATION_LOOKUP = { | ||
"0048.sql": migrate_48.__func__, | ||
"0050.sql": migrate_50.__func__, | ||
|
@@ -753,6 +806,7 @@ def migrate_96(TRN): | |
# "0082.sql": migrate_82.__func__ | ||
# ... | ||
"0096.sql": migrate_96.__func__, | ||
"0133.sql": migrate_133.__func__ | ||
} | ||
|
||
@classmethod | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The MIME type is specific to PDF
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The MIME type is stored on a per-file basis and it's entirely possible it will be used for non-PDF file types in the future. Do you have a suggestion on an alternative to _bytes that's not specific to a single file type?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
bytes is fine but perhaps use the stored MIME type rather than hard code it on response?