mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-24 20:36:49 +00:00
Add rake task to export enterprises to CSV
This commit is contained in:
32
lib/tasks/enterprises.rake
Normal file
32
lib/tasks/enterprises.rake
Normal file
@@ -0,0 +1,32 @@
|
||||
require 'csv'
|
||||
|
||||
namespace :openfoodnetwork do
|
||||
namespace :dev do
|
||||
desc 'export enterprises to CSV'
|
||||
task :export_enterprises => :environment do
|
||||
CSV.open('db/enterprises.csv', 'wb') do |csv|
|
||||
csv << enterprise_header
|
||||
enterprises.each do |enterprise|
|
||||
csv << enterprise_row(enterprise)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
private
|
||||
|
||||
def enterprises
|
||||
Enterprise.by_name
|
||||
end
|
||||
|
||||
def enterprise_header
|
||||
['name', 'description', 'long_description', 'is_primary_producer', 'is_distributor', 'contact', 'phone', 'email', 'website', 'twitter', 'abn', 'acn', 'pickup_times', 'next_collection_at', 'distributor_info', 'visible', 'facebook', 'instagram', 'linkedin', 'address1', 'address2', 'city', 'zipcode', 'state', 'country']
|
||||
end
|
||||
|
||||
def enterprise_row(enterprise)
|
||||
[enterprise.name, enterprise.description, enterprise.long_description, enterprise.is_primary_producer, enterprise.is_distributor, enterprise.contact, enterprise.phone, enterprise.email, enterprise.website, enterprise.twitter, enterprise.abn, enterprise.acn, enterprise.pickup_times, enterprise.next_collection_at, enterprise.distributor_info, enterprise.visible, enterprise.facebook, enterprise.instagram, enterprise.linkedin, enterprise.address.address1, enterprise.address.address2, enterprise.address.city, enterprise.address.zipcode, enterprise.address.state_name, enterprise.address.country.andand.name]
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -6,9 +6,9 @@ namespace :openfoodnetwork do
|
||||
desc 'export users to CSV'
|
||||
task export_users: :environment do
|
||||
CSV.open('db/users.csv', 'wb') do |csv|
|
||||
csv << header
|
||||
csv << user_header
|
||||
users.each do |user|
|
||||
csv << row(user)
|
||||
csv << user_row(user)
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -34,7 +34,7 @@ namespace :openfoodnetwork do
|
||||
end
|
||||
|
||||
|
||||
def header
|
||||
def user_header
|
||||
["encrypted_password", "password_salt", "email", "remember_token", "persistence_token", "reset_password_token", "perishable_token", "sign_in_count", "failed_attempts", "last_request_at", "current_sign_in_at", "last_sign_in_at", "current_sign_in_ip", "last_sign_in_ip", "login", "created_at", "updated_at", "authentication_token", "unlock_token", "locked_at", "remember_created_at", "reset_password_sent_at",
|
||||
|
||||
"role_name",
|
||||
@@ -45,7 +45,7 @@ namespace :openfoodnetwork do
|
||||
end
|
||||
|
||||
|
||||
def row(user)
|
||||
def user_row(user)
|
||||
sa = user.orders.last.andand.ship_address
|
||||
ba = user.orders.last.andand.bill_address
|
||||
|
||||
|
||||
Reference in New Issue
Block a user