Remove new CSV report generation
The new CSV report was more configurable and could work on proposals,
processes and comments. However, it had several issues.
In the public area, by default it generated a blank file.
In the admin section, the report was hard to configure and it generated
a file with less quality than the old system.
So until we improve this system, we're bringing back the old investment
CSV exporter.
This commit reverts most of commit 9d1ca3bf.
This commit is contained in:
@@ -101,8 +101,6 @@ module Abilities
|
||||
can [:deliver], Newsletter, hidden_at: nil
|
||||
can [:manage], Dashboard::AdministratorTask
|
||||
|
||||
can [:edit, :update], DownloadSetting
|
||||
|
||||
can :manage, LocalCensusRecord
|
||||
can [:create, :read], LocalCensusRecords::Import
|
||||
end
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
class Budget
|
||||
require "csv"
|
||||
class Investment < ApplicationRecord
|
||||
SORTING_OPTIONS = { id: "id", supports: "cached_votes_up" }.freeze
|
||||
|
||||
@@ -26,8 +25,6 @@ class Budget
|
||||
include Milestoneable
|
||||
include Randomizable
|
||||
|
||||
extend DownloadSettings::BudgetInvestmentCsv
|
||||
|
||||
translates :title, touch: true
|
||||
translates :description, touch: true
|
||||
include Globalizable
|
||||
@@ -57,8 +54,6 @@ class Budget
|
||||
inverse_of: :commentable,
|
||||
class_name: "Comment"
|
||||
|
||||
delegate :name, :email, to: :author, prefix: true
|
||||
|
||||
validates_translation :title, presence: true, length: { in: 4..Budget::Investment.title_max_length }
|
||||
validates_translation :description, presence: true, length: { maximum: Budget::Investment.description_max_length }
|
||||
|
||||
|
||||
@@ -1,11 +1,8 @@
|
||||
require "csv"
|
||||
|
||||
class Comment < ApplicationRecord
|
||||
include Flaggable
|
||||
include HasPublicAuthor
|
||||
include Graphqlable
|
||||
include Notifiable
|
||||
extend DownloadSettings::CommentCsv
|
||||
|
||||
COMMENTABLE_TYPES = %w[Debate Proposal Budget::Investment Poll Topic
|
||||
Legislation::Question Legislation::Annotation
|
||||
|
||||
@@ -1,26 +0,0 @@
|
||||
module DownloadSettings
|
||||
module BudgetInvestmentCsv
|
||||
extend ActiveSupport::Concern
|
||||
|
||||
def get_association_attribute_names
|
||||
["author_name", "author_email"]
|
||||
end
|
||||
|
||||
def get_downloadables_names(config)
|
||||
DownloadSetting.where(name_model: "Budget::Investment",
|
||||
downloadable: true,
|
||||
config: config).pluck(:name_field)
|
||||
end
|
||||
|
||||
def to_csv(budgets, admin_attr, options = {})
|
||||
attributes = admin_attr.nil? ? [] : admin_attr
|
||||
|
||||
CSV.generate(options) do |csv|
|
||||
csv << attributes
|
||||
budgets.each do |budget|
|
||||
csv << attributes.map { |attr| budget.send(attr) }
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -1,26 +0,0 @@
|
||||
module DownloadSettings
|
||||
module CommentCsv
|
||||
extend ActiveSupport::Concern
|
||||
|
||||
def get_association_attribute_names
|
||||
["author_name", "author_email"]
|
||||
end
|
||||
|
||||
def get_downloadables_names(config)
|
||||
DownloadSetting.where(name_model: "Comment",
|
||||
downloadable: true,
|
||||
config: config).pluck(:name_field)
|
||||
end
|
||||
|
||||
def to_csv(comments, admin_attr, options = {})
|
||||
attributes = admin_attr.nil? ? [] : admin_attr
|
||||
|
||||
CSV.generate(options) do |csv|
|
||||
csv << attributes
|
||||
comments.each do |comment|
|
||||
csv << attributes.map { |attr| comment.send(attr) }
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -1,26 +0,0 @@
|
||||
module DownloadSettings
|
||||
module DebateCsv
|
||||
extend ActiveSupport::Concern
|
||||
|
||||
def get_association_attribute_names
|
||||
["author_name", "author_email"]
|
||||
end
|
||||
|
||||
def get_downloadables_names(config)
|
||||
DownloadSetting.where(name_model: "Debate",
|
||||
downloadable: true,
|
||||
config: config).pluck(:name_field)
|
||||
end
|
||||
|
||||
def to_csv(debates, admin_attr, options = {})
|
||||
attributes = admin_attr.nil? ? [] : admin_attr
|
||||
|
||||
CSV.generate(options) do |csv|
|
||||
csv << attributes
|
||||
debates.each do |debate|
|
||||
csv << attributes.map { |attr| debate.send(attr) }
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -1,26 +0,0 @@
|
||||
module DownloadSettings
|
||||
module LegislationProcessCsv
|
||||
extend ActiveSupport::Concern
|
||||
|
||||
def get_association_attribute_names
|
||||
[]
|
||||
end
|
||||
|
||||
def get_downloadables_names(config)
|
||||
DownloadSetting.where(name_model: "Legislation::Process",
|
||||
downloadable: true,
|
||||
config: config).pluck(:name_field)
|
||||
end
|
||||
|
||||
def to_csv(processes, admin_attr, options = {})
|
||||
attributes = admin_attr.nil? ? [] : admin_attr
|
||||
|
||||
CSV.generate(options) do |csv|
|
||||
csv << attributes
|
||||
processes.each do |process|
|
||||
csv << attributes.map { |attr| process.send(attr) }
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -1,26 +0,0 @@
|
||||
module DownloadSettings
|
||||
module ProposalCsv
|
||||
extend ActiveSupport::Concern
|
||||
|
||||
def get_association_attribute_names
|
||||
["author_name", "author_email"]
|
||||
end
|
||||
|
||||
def get_downloadables_names(config)
|
||||
DownloadSetting.where(name_model: "Proposal",
|
||||
downloadable: true,
|
||||
config: config).pluck(:name_field)
|
||||
end
|
||||
|
||||
def to_csv(proposals, admin_attr, options = {})
|
||||
attributes = admin_attr.nil? ? [] : admin_attr
|
||||
|
||||
CSV.generate(options) do |csv|
|
||||
csv << attributes
|
||||
proposals.each do |proposal|
|
||||
csv << attributes.map { |attr| proposal.send(attr) }
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -1,5 +1,4 @@
|
||||
require "numeric"
|
||||
require "csv"
|
||||
|
||||
class Debate < ApplicationRecord
|
||||
include Rails.application.routes.url_helpers
|
||||
@@ -28,9 +27,6 @@ class Debate < ApplicationRecord
|
||||
belongs_to :geozone
|
||||
has_many :comments, as: :commentable, inverse_of: :commentable
|
||||
|
||||
extend DownloadSettings::DebateCsv
|
||||
delegate :name, :email, to: :author, prefix: true
|
||||
|
||||
validates_translation :title, presence: true, length: { in: 4..Debate.title_max_length }
|
||||
validates_translation :description, presence: true, length: { in: 10..Debate.description_max_length }
|
||||
validates :author, presence: true
|
||||
|
||||
@@ -1,17 +0,0 @@
|
||||
class DownloadSetting < ApplicationRecord
|
||||
validates :name_model, presence: true
|
||||
validates :name_field, presence: true
|
||||
|
||||
def self.initialize(model, field_name, config)
|
||||
download_setting = DownloadSetting.find_by(name_model: model.name,
|
||||
name_field: field_name,
|
||||
config: config)
|
||||
if download_setting.nil?
|
||||
download_setting = DownloadSetting.create!(downloadable: false,
|
||||
name_model: model.name,
|
||||
name_field: field_name,
|
||||
config: config)
|
||||
end
|
||||
download_setting
|
||||
end
|
||||
end
|
||||
@@ -1,5 +1,3 @@
|
||||
require "csv"
|
||||
|
||||
class Legislation::Process < ApplicationRecord
|
||||
include ActsAsParanoidAliases
|
||||
include Taggable
|
||||
@@ -17,7 +15,6 @@ class Legislation::Process < ApplicationRecord
|
||||
translates :milestones_summary, touch: true
|
||||
translates :homepage, touch: true
|
||||
include Globalizable
|
||||
extend DownloadSettings::LegislationProcessCsv
|
||||
|
||||
PHASES_AND_PUBLICATIONS = %i[homepage_phase draft_phase debate_phase allegations_phase
|
||||
proposals_phase draft_publication result_publication].freeze
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
require "csv"
|
||||
|
||||
class Proposal < ApplicationRecord
|
||||
include Rails.application.routes.url_helpers
|
||||
include Flaggable
|
||||
@@ -43,9 +41,6 @@ class Proposal < ApplicationRecord
|
||||
has_many :dashboard_actions, through: :dashboard_executed_actions, class_name: "Dashboard::Action"
|
||||
has_many :polls, as: :related, inverse_of: :related
|
||||
|
||||
extend DownloadSettings::ProposalCsv
|
||||
delegate :name, :email, to: :author, prefix: true
|
||||
|
||||
validates_translation :title, presence: true, length: { in: 4..Proposal.title_max_length }
|
||||
validates_translation :description, length: { maximum: Proposal.description_max_length }
|
||||
validates_translation :summary, presence: true
|
||||
|
||||
Reference in New Issue
Block a user