Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Export all articles. #2235

Merged
merged 1 commit into from
Feb 25, 2025
Merged
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
6 changes: 6 additions & 0 deletions app/models/team.rb
Original file line number Diff line number Diff line change
Expand Up @@ -661,6 +661,12 @@ def get_dashboard_exported_data(filters, dashboard_type)
data
end

def get_articles_exported_data(query)
fact_check_data = FactCheck.get_exported_data(query, self)
explainer_data = Explainer.get_exported_data(query, self).drop(1) # Remove the header, we don't need a second header
fact_check_data + explainer_data
end

# Platforms for which statistics are available (e.g., at least one media request)
def statistics_platforms
TiplineRequest.joins(:project_media).where('project_medias.team_id' => self.id).group('platform').count.keys
Expand Down
6 changes: 5 additions & 1 deletion lib/list_export.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
class ListExport
TYPES = [:media, :feed, :fact_check, :explainer, :articles_dashboard, :tipline_dashboard ]
TYPES = [:media, :feed, :fact_check, :explainer, :articles_dashboard, :tipline_dashboard, :articles]

def initialize(type, query, team_id)
@type = type
Expand All @@ -21,6 +21,8 @@ def number_of_rows
@team.filtered_fact_checks(@parsed_query).count
when :explainer
@team.filtered_explainers(@parsed_query).count
when :articles
@team.filtered_explainers(@parsed_query).count + @team.filtered_fact_checks(@parsed_query).count
when :articles_dashboard, :tipline_dashboard
1 # Always maintain one row for dashboard data, but use different columns for export.
end
Expand Down Expand Up @@ -64,6 +66,8 @@ def export_data
FactCheck.get_exported_data(@parsed_query, @team)
when :explainer
Explainer.get_exported_data(@parsed_query, @team)
when :articles
@team.get_articles_exported_data(@parsed_query)
when :articles_dashboard, :tipline_dashboard
@team.get_dashboard_exported_data(@parsed_query, @type)
end
Expand Down
16 changes: 16 additions & 0 deletions test/lib/list_export_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -138,4 +138,20 @@ def teardown
assert_equal 1, csv_content.size
assert_equal 1, export.number_of_rows
end

test "should export articles CSV" do
t = create_team
create_explainer team: t
pm = create_project_media team: t
cd = create_claim_description project_media: pm
create_fact_check claim_description: cd

export = ListExport.new(:articles, '{}', t.id)
csv_url = export.generate_csv_and_send_email(create_user)
response = Net::HTTP.get_response(URI(csv_url))
assert_equal 200, response.code.to_i
csv_content = CSV.parse(response.body, headers: true)
assert_equal 2, csv_content.size
assert_equal 2, export.number_of_rows
end
end
Loading