From 9fa0759c5ee831bb4d3e68d5c1556664028e8c32 Mon Sep 17 00:00:00 2001 From: Adrian Short Date: Mon, 7 Jun 2010 11:54:24 +0100 Subject: [PATCH] Added payment URLs to CSV downloads --- app.rb | 9 ++++----- lib/models.rb | 6 ++++++ 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/app.rb b/app.rb index 64cffcb..3853357 100644 --- a/app.rb +++ b/app.rb @@ -4,7 +4,6 @@ require 'sinatra-helpers/haml/partials' require 'haml' require 'lib/models' - get '/' do @directorates = Directorate.all( :order => ['name'] ) haml :home @@ -22,10 +21,10 @@ get '/suppliers/:slug.csv' do headers "Content-Disposition" => "attachment;filename=supplier-#{@supplier.slug}.csv", "Content-Type" => "application/octet-stream" - result = "Date,Ref.,Trans No,Directorate,Service,Amount ex. VAT\n" + result = "Date,Ref.,URL,Trans No,Directorate,Service,Amount ex. VAT\n" for payment in @supplier.payments - result += "#{payment.d.strftime("%d %b %Y")},#{payment.id},#{payment.trans_no},\"#{payment.directorate.name}\",#{payment.service.name},#{sprintf("%0.2f", payment.amount)}\n" + result += "#{payment.d.strftime("%d %b %Y")},#{payment.id},#{payment.url},#{payment.trans_no},\"#{payment.directorate.name}\",#{payment.service.name},#{sprintf("%0.2f", payment.amount)}\n" end result @@ -49,10 +48,10 @@ get '/services/:slug.csv' do headers "Content-Disposition" => "attachment;filename=service-#{@service.slug}.csv", "Content-Type" => "application/octet-stream" - result = "Date,Ref.,Trans No,Directorate,Supplier,Amount ex. VAT\n" + result = "Date,Ref.,URL,Trans No,Directorate,Supplier,Amount ex. VAT\n" for payment in @service.payments - result += "#{payment.d.strftime("%d %b %Y")},#{payment.id},#{payment.trans_no},\"#{payment.directorate.name}\",#{payment.supplier.name},#{sprintf("%0.2f", payment.amount)}\n" + result += "#{payment.d.strftime("%d %b %Y")},#{payment.id},#{payment.url},#{payment.trans_no},\"#{payment.directorate.name}\",#{payment.supplier.name},#{sprintf("%0.2f", payment.amount)}\n" end result diff --git a/lib/models.rb b/lib/models.rb index 2118b0e..294f97b 100644 --- a/lib/models.rb +++ b/lib/models.rb @@ -4,6 +4,8 @@ require 'dm-validations' require 'dm-timestamps' require 'dm-aggregates' +SITE_URL = 'http://armchairauditor.heroku.com/' + class Payment include DataMapper::Resource @@ -20,6 +22,10 @@ class Payment belongs_to :directorate belongs_to :service belongs_to :supplier + + def url + SITE_URL + "payments/" + @id.to_s + end end