def make_csv_for_account(acc): if not isinstance(acc, models.Account): acc = models.Account.pull(acc) if not isinstance(acc, models.Account): print "could not resolve account from identifier " + str(acc) # ensure there's no bulk reapplication record models.BulkReApplication.delete_by_owner(acc.id) q = models.SuggestionQuery(statuses=['reapplication', 'submitted'], owner=acc.id).query() suggestions = models.Suggestion.q2obj(q=q, size=30000) if len(suggestions) < 11: return False, len(suggestions) filename = acc.id + ".csv" filepath = os.path.join(app.config.get("BULK_REAPP_PATH"), filename) if os.path.isfile(filepath): try: os.remove(filepath) except IOError as e: raise ReappCsvException(e.message, acc.id) reapplication.make_csv(filepath, suggestions) bulk_reapp = models.BulkReApplication() bulk_reapp.set_spreadsheet_name(filename) bulk_reapp.set_owner(acc.id) bulk_reapp.save() return True, len(suggestions)
def test_04_make_csv_full(self): s1 = models.Suggestion(**deepcopy(APPLICATION_SOURCE)) s2 = models.Suggestion(**deepcopy(APPLICATION_SOURCE)) s3 = models.Suggestion(**deepcopy(APPLICATION_SOURCE)) bj1 = s1.bibjson() bj1.remove_identifiers("pissn") bj1.remove_identifiers("eissn") bj1.add_identifier("pissn", "1234-5678") bj1.add_identifier("eissn", "9876-5432") bj1.title = "First Title" bj1.add_language("ES") bj1.add_language("Spanish") # which is not allowed, you know! (should be "Spanish; Castillian") bj2 = s2.bibjson() bj2.remove_identifiers("pissn") bj2.remove_identifiers("eissn") bj2.add_identifier("pissn", "2345-6789") bj1.add_identifier("eissn", "9876-5431") bj2.title = "Second Title" bj3 = s3.bibjson() bj3.remove_identifiers("pissn") bj3.remove_identifiers("eissn") bj3.add_identifier("pissn", "3456-7890") bj1.add_identifier("eissn", "9876-5430") bj3.title = "Third Title" reapplication.make_csv("full_app.csv", [s3, s2, s1]) # send the suggestions in in the wrong order for display on purpose assert os.path.exists("full_app.csv") # now let's check a few things about the sheet to be sure sheet = clcsv.ClCsv("full_app.csv") # get the three columns out of the sheet issn1, vals1 = sheet.get_column(1) issn2, vals2 = sheet.get_column(2) issn3, vals3 = sheet.get_column(3) # check that the column headers are in the right order assert issn1 == "1234-5678" assert issn2 == "2345-6789" assert issn3 == "3456-7890" # check that the column contents are the right contents assert vals1[0] == "First Title" assert vals2[0] == "Second Title" assert vals3[0] == "Third Title" # finally check the full question list qs = reapplication.Suggestion2QuestionXwalk.question_list() _, sheetqs = sheet.get_column(0) assert sheetqs == qs # check that the disallowed language got stripped assert "Spanish" not in vals1[34]
def test_02_make_csv_vbasic(self): s1 = models.Suggestion() bj1 = s1.bibjson() bj1.title = "The Title" bj1.add_identifier("eissn", "1245-5678") s2 = models.Suggestion() bj2 = s2.bibjson() bj2.title = "Second One" bj2.add_identifier("pissn", "9876-5432") reapplication.make_csv("basic_reapp.csv", [s1, s2]) assert os.path.exists("basic_reapp.csv")
def test_13_make_csv_reapp_unicode(self): s1 = models.Suggestion(**deepcopy(REAPP2_UNICODE_SOURCE)) reapplication.make_csv("full_reapp_unicode.csv", [s1]) assert os.path.exists("full_reapp_unicode.csv") # now let's check a few things about the sheet to be sure sheet = clcsv.ClCsv("full_reapp_unicode.csv") # get the three columns out of the sheet issn1, vals1 = sheet.get_column(1) # check that the column headers are in the right order assert issn1 == "1234-5678" # check that the column contents are the right contents assert vals1[0] == "The Title" # finally check the full question list qs = reapplication.Suggestion2QuestionXwalk.question_list() _, sheetqs = sheet.get_column(0) assert sheetqs == qs