aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--app/controllers/admin_public_body_controller.rb26
-rw-r--r--app/views/admin_public_body/import_csv.rhtml31
2 files changed, 37 insertions, 20 deletions
diff --git a/app/controllers/admin_public_body_controller.rb b/app/controllers/admin_public_body_controller.rb
index 797429d55..bce04ff98 100644
--- a/app/controllers/admin_public_body_controller.rb
+++ b/app/controllers/admin_public_body_controller.rb
@@ -121,6 +121,14 @@ class AdminPublicBodyController < AdminController
def import_csv
if params[:csv_file]
if !params[:tag].empty?
+ if params['commit'] == 'Dry run'
+ dry_run_only = true
+ elsif params['commit'] == 'Upload'
+ dry_run_only = false
+ else
+ raise "internal error, unknown button label"
+ end
+
# Try with dry run first
csv_contents = params[:csv_file].read
en = PublicBody.import_csv(csv_contents, params[:tag], true, admin_http_auth_user())
@@ -128,14 +136,18 @@ class AdminPublicBodyController < AdminController
notes = en[1]
if errors.size == 0
- # And if OK, with real run
- en = PublicBody.import_csv(csv_contents, params[:tag], false, admin_http_auth_user())
- errors = en[0]
- notes = en[1]
- if errors.size != 0
- raise "dry run mismatched real run"
+ if dry_run_only
+ notes.push("Dry run was successful, real run would do as above.")
+ else
+ # And if OK, with real run
+ en = PublicBody.import_csv(csv_contents, params[:tag], false, admin_http_auth_user())
+ errors = en[0]
+ notes = en[1]
+ if errors.size != 0
+ raise "dry run mismatched real run"
+ end
+ notes.push("Import was successful.")
end
- notes.push("Import was successful.")
end
@errors = errors.join("\n")
@notes = notes.join("\n")
diff --git a/app/views/admin_public_body/import_csv.rhtml b/app/views/admin_public_body/import_csv.rhtml
index 3ca1f4d59..75981a501 100644
--- a/app/views/admin_public_body/import_csv.rhtml
+++ b/app/views/admin_public_body/import_csv.rhtml
@@ -12,15 +12,7 @@
<% form_tag 'import_csv', :multipart => true do %>
<p>
- <label for="tag">Tag to add entries to (maybe you want:
- <% for category, description in PublicBodyCategories::CATEGORIES_BY_TAG %>
- <% if category != "other" %>
- <strong><%= category %></strong>=<%= description %>;
- <% end %>
- <% end %>
- )
- </label>
- <br/>
+ <label for="tag">Tag to add entries to / alter entries for:</label>
<%= text_field_tag 'tag', params[:tag] %>
</p>
@@ -30,10 +22,23 @@
<%= file_field_tag :csv_file, :size => 60 %>
</p>
- <p><strong>Note:</strong> This will report errors in the CSV file. If there are no errors, it will make updates.
- Any changes since last import will be overwritten - e.g. email addresses changed back. Changes and additions
- are reported on a successful import for you to check.
+ <p><strong>Note:</strong> Choose <strong>dry run</strong> to test, without
+ actually altering the database. Choose <strong>upload</strong> to actually
+ make the changes. In either case, you will be shown any errors, or details
+ of the changes. When uploading, any changes since last import will be
+ overwritten - e.g. email addresses changed back.
+ </p>
- <p><%= submit_tag 'Upload' %></p>
+ <p><%= submit_tag 'Dry run' %> <%= submit_tag 'Upload' %></p>
<% end %>
+<hr>
+
+<p>Standard tags:
+ <% for category, description in PublicBodyCategories::CATEGORIES_BY_TAG %>
+ <% if category != "other" %>
+ <strong><%= category %></strong>=<%= description %>;
+ <% end %>
+ <% end %>
+ </p>
+