Skip to content
This repository was archived by the owner on Oct 22, 2025. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema.define(version: 20180301162116) do
ActiveRecord::Schema.define(version: 20180314112813) do

# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ class CensusesController < Decidim::Admin::ApplicationController

before_action :show_instructions,
unless: :census_authorization_active_in_organization?
before_action :set_status, on: %i(show create)

def show
authorize! :show, CensusDatum
@status = Status.new(current_organization)
end

def create
Expand All @@ -21,10 +21,11 @@ def create
data = CsvData.new(params[:file].path)
CensusDatum.insert_all(current_organization, data.values)
RemoveDuplicatesJob.perform_later(current_organization)
@invalid_rows = data.errors
flash[:notice] = t('.success', count: data.values.count,
errors: data.errors.count)
end
redirect_to censuses_path
render :show
end

def destroy
Expand All @@ -39,6 +40,10 @@ def show_instructions
render :instructions
end

def set_status
@status = Status.new(current_organization)
end

def census_authorization_active_in_organization?
(current_organization.available_authorizations & CENSUS_AUTHORIZATIONS).any?
end
Expand Down
2 changes: 1 addition & 1 deletion decidim-census/app/models/decidim/census/csv_data.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def process_row(row)
if id_document.present? && !date.nil?
values << [id_document, date]
else
errors << row
errors << { line: $., data: row }
end
end

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<div class="card">
<div class="card-divider">
<h2 class="card-title">
<%= t('admin.new.errors.title', scope: 'decidim.census') %>
</h2>
</div>
<div class="card-section">
<div class="table-scroll">
<table class="table-list table-list--lastleft table-census-errors">
<thead>
<tr>
<th>
<%= t('admin.new.errors.data.line', scope: 'decidim.census') %>
</th>
<th>
<%= t('admin.new.errors.data.data', scope: 'decidim.census') %>
</th>
</tr>
</thead>
<tbody>
<% @invalid_rows.each do |row| %>
<tr>
<td>
<%= row[:line] %>
</td>
<td>
<%= row[:data].fields.join(';') %>
</td>
</tr>
<% end %>
</tbody>
</table>
</div>
</div>
</div>
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
<%= render 'invalid_rows' if @invalid_rows.present? %>

<div class="card">
<div class="card-divider">
Expand All @@ -7,11 +8,11 @@
</div>
<div class="card-section">
<% if @status.count > 0 %>
<p><%= t('decidim.census.admin.show.data', count: @status.count,
<p><%= t('decidim.census.admin.show.data', count: @status.count,
due_date: l(@status.last_import_at, format: :long)) %>
</p>
<%= link_to t('decidim.census.admin.destroy.title'),
censuses_path,
<%= link_to t('decidim.census.admin.destroy.title'),
censuses_path,
method: :delete,
class: 'button alert',
data: { confirm: t('decidim.census.admin.destroy.confirm') } %>
Expand All @@ -21,7 +22,6 @@
</div>
</div>


<div class="card">
<div class="card-divider">
<h2 class="card-title">
Expand All @@ -37,7 +37,3 @@
<% end %>
</div>
</div>




5 changes: 5 additions & 0 deletions decidim-census/config/locales/ca.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,8 @@ ca:
title: Pujar un nou cens
file: Arxiu excel .csv amb les dades del cens
submit: Carrega
errors:
title: Errors en la importació
data:
line: Línia
data: Dades
5 changes: 5 additions & 0 deletions decidim-census/config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,8 @@ en:
title: Upload a new census
file: Excel .csv file with census data
submit: Upload file
errors:
title: Import errors
data:
line: Line
data: Data
5 changes: 5 additions & 0 deletions decidim-census/config/locales/es.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,8 @@ es:
title: Subir un nuevo censo
file: Archivo excel .csv con los datos del censo
submit: Subir archivo
errors:
title: Errores en la importación
data:
line: Línea
data: Datos
12 changes: 11 additions & 1 deletion decidim-census/spec/controllers/censuses_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,24 @@
# Don't know why don't prepend with `spec/fixtures` automatically
file = fixture_file_upload('spec/fixtures/files/data1.csv')
post :create, params: { file: file }
expect(response).to have_http_status(:redirect)
expect(response).to render_template(:show)

expect(Decidim::Census::CensusDatum.count).to be 3
expect(Decidim::Census::CensusDatum.first.id_document)
.to eq encode_id_document('1111A')
expect(Decidim::Census::CensusDatum.last.id_document)
.to eq encode_id_document('3333C')
end

it 'fails to import some data' do
sign_in user

file = fixture_file_upload('spec/fixtures/files/with-errors.csv')
post :create, params: { file: file }

expect(response).to render_template(:show)
expect(assigns(:invalid_rows).count).to be 3
end
end

describe 'POST #delete_all' do
Expand Down