Skip to content

Commit

Permalink
Prevent data records with wrong format crashing csv import
Browse files Browse the repository at this point in the history
  • Loading branch information
nvgeele committed Aug 5, 2015
1 parent b2f7702 commit 0fa9de0
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion resolver/controllers/csv.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from flask import request, render_template, flash, make_response, redirect
from resolver import app
from resolver.model import Entity, Document, Data, Representation,\
entity_types, document_types
entity_types, document_types, data_formats
from resolver.database import db
from resolver.controllers.user import check_privilege
from resolver.util import log, UnicodeWriter, UnicodeReader, cleanID, import_log
Expand All @@ -18,6 +18,7 @@ def file_allowed(filename):
(filename.rsplit('.', 1)[1].lower() == 'csv')


# TODO: script for imports
@app.route('/resolver/csv/import', methods=["POST"])
@check_privilege
def admin_csv_import():
Expand Down Expand Up @@ -100,6 +101,9 @@ def admin_csv_import():
enabled = record[5] == '1'

if record[3] == 'data':
if not(record[7] and record[7] in data_formats):
failures.append((id, "Format missing or invalid for PID `%s'" % ent.id))
continue
doc = Data.query.filter(Data.format == record[7],
Document.entity_id == ent.id).first()
if doc:
Expand Down

0 comments on commit 0fa9de0

Please sign in to comment.