Commit 02652cce41d982349fce4000c3a4752e4ee7d7f9

Authored by Thiago Ribeiro
2 parents 12c0a4e8 a961f7a9
Exists in master and in 79 other branches add_sisp_to_chef, add_super_archives_plugin, api_for_colab, automates_core_packing, backup_not_prod, changes_in_buttons_on_content_panel, colab_automated_login, colab_spb_plugin_recipe, colab_widgets_settings, design_validation, dev_env_minimal, disable_email_dev, fix_breadcrumbs_position, fix_categories_software_link, fix_edit_institution, fix_edit_software_with_another_license, fix_get_license_info, fix_gitlab_assets_permission, fix_list_style_inside_article, fix_list_style_on_folder_elements, fix_members_pagination, fix_merge_request_url, fix_models_translations, fix_no_license, fix_software_api, fix_software_block_migration, fix_software_communities_translations, fix_software_communities_unit_test, fix_style_create_institution_admin_panel, fix_superarchives_imports, fix_sym_links_noosfero, focus_search_field_theme, gov-user-refactoring, gov-user-refactoring-rails4, header_fix, institution_modal_on_rating, kalibro-conf-refactoring, kalibro-processor-package, lxc_settings, margin_fix, mezuro_cookbook, prezento, refactor_download_block, refactor_software_communities, refactor_software_for_sisp, register_page, release-process, release-process-v2, remove-unused-images, remove_broken_theme, remove_secondary_email_from_user, remove_sisp_buttons, removing_super_archives_email, review_message, scope2method, signals_user_noosfero, sisp_catalog_header, sisp_colab_config, sisp_dev, sisp_dev_master, sisp_simple_version, software_as_organization, software_catalog_style_fix, software_communities_html_refactor, software_infos_api, spb_minimal_env, spb_to_rails4, spec_refactor, stable-4.1, stable-4.2, stable-4.x, temp_soft_comm_refactoring, theme_header, theme_javascript_refactory, thread_dropdown, thread_page, update_search_by_categories, update_software_api, update_softwares_boxes

Merge branch 'to_csv' into 'master'

To csv

Add a new task to export catalog data to CSV files.

See merge request !2
lib/tasks/export.rake 0 → 100644
@@ -0,0 +1,133 @@ @@ -0,0 +1,133 @@
  1 +require 'csv'
  2 +
  3 +namespace :export do
  4 + namespace :catalog do
  5 + desc "Export all softwares to CSV"
  6 + task :csv => :environment do
  7 + Environment.all.each do |env|
  8 + if env.plugin_enabled?("MpogSoftware") or env.plugin_enabled?("SoftwareCommunitiesPlugin")
  9 + softwares_to_csv
  10 + categories_to_csv
  11 + software_categories_to_csv
  12 +
  13 + compress_files
  14 + end
  15 + end
  16 + end
  17 + end
  18 +
  19 + def softwares_to_csv
  20 + print "Exporting softwares to softwares.csv: "
  21 +
  22 + CSV.open('/tmp/softwares.csv', 'w') do |csv|
  23 + csv << [
  24 + "id",
  25 + "community_id",
  26 + "identifier",
  27 + "name",
  28 + "finality",
  29 + "acronym",
  30 + "created_at",
  31 + "image_filename",
  32 + "home_page_name",
  33 + "home_page_slug",
  34 + "home_page_path",
  35 + "home_page_body",
  36 + "home_page_abstract",
  37 + "home_page_published_at"
  38 + ]
  39 +
  40 + SoftwareInfo.all.each do |software|
  41 + if software.community
  42 + begin
  43 + csv << [
  44 + software.id,
  45 + software.community.id,
  46 + software.community.identifier,
  47 + software.community.name,
  48 + software.finality,
  49 + software.acronym,
  50 + software.community.created_at,
  51 + (software.community.image.nil? ? nil : software.community.image.filename),
  52 + (software.community.home_page.nil? ? nil : software.community.home_page.name),
  53 + (software.community.home_page.nil? ? nil : software.community.home_page.slug),
  54 + (software.community.home_page.nil? ? nil : software.community.home_page.path),
  55 + (software.community.home_page.nil? ? nil : software.community.home_page.body),
  56 + (software.community.home_page.nil? ? nil : software.community.home_page.abstract),
  57 + (software.community.home_page.nil? ? nil : software.community.home_page.published_at),
  58 + ]
  59 +
  60 + print '.'
  61 + rescue
  62 + print 'F'
  63 + end
  64 + end
  65 + end
  66 + end
  67 +
  68 + print "\n"
  69 + end
  70 +
  71 + def categories_to_csv
  72 + print "Exporting categories to categories.csv: "
  73 +
  74 + CSV.open('/tmp/categories.csv', 'w') do |csv|
  75 + csv << [
  76 + "id",
  77 + "name",
  78 + "path",
  79 + ]
  80 +
  81 + Category.all.each do |category|
  82 + begin
  83 + csv << [
  84 + category.id,
  85 + category.name,
  86 + category.path,
  87 + ]
  88 +
  89 + print '.'
  90 + rescue
  91 + print 'F'
  92 + end
  93 + end
  94 + end
  95 +
  96 + print "\n"
  97 + end
  98 +
  99 + def software_categories_to_csv
  100 + print "Exporting software and categories relation to software_categories.csv: "
  101 + CSV.open('/tmp/software_categories.csv', 'w') do |csv|
  102 + csv << [
  103 + "software_id",
  104 + "category_id"
  105 + ]
  106 +
  107 + SoftwareInfo.all.each do |software|
  108 + if software.community
  109 + software.community.categories.each do |category|
  110 + begin
  111 + csv << [
  112 + software.id,
  113 + category.id
  114 + ]
  115 +
  116 + print '.'
  117 + rescue
  118 + print 'F'
  119 + end
  120 + end
  121 + end
  122 + end
  123 + end
  124 +
  125 + print "\n"
  126 + end
  127 +
  128 + def compress_files
  129 + `cd /tmp/ && tar -zcvf software_catalog_csvs.tar.gz softwares.csv categories.csv software_categories.csv`
  130 +
  131 + `cd /tmp/ && rm softwares.csv categories.csv software_categories.csv`
  132 + end
  133 +end
0 \ No newline at end of file 134 \ No newline at end of file
views/blocks/categories_software.html.erb
@@ -8,9 +8,12 @@ @@ -8,9 +8,12 @@
8 <p><%= _("Categories:") %></p> 8 <p><%= _("Categories:") %></p>
9 <ul class="categories-mais-software"> 9 <ul class="categories-mais-software">
10 10
11 - <% Category.where(:name => "Software").first.children.each do |category| %>  
12 - <% unless category.software_infos.count < 1 %>  
13 - <li><%= link_to _("#{category.name}") + " (#{category.software_infos.count})", {:controller => :search, :action => :software_infos, :selected_categories_id => [category.id]} %></li> 11 + <% categories = Category.where(:name => "Software") %>
  12 + <% unless categories.blank? %>
  13 + <% categories.first.children.each do |category| %>
  14 + <% unless category.software_infos.count < 1 %>
  15 + <li><%= link_to _("#{category.name}") + " (#{category.software_infos.count})", {:controller => :search, :action => :software_infos, :selected_categories_id => [category.id]} %></li>
  16 + <% end %>
14 <% end %> 17 <% end %>
15 <% end %> 18 <% end %>
16 </ul> 19 </ul>