An open source, stand-alone, customisable public spending data web app.
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

models.rb 4.2 KiB

14 anos atrás
14 anos atrás
14 anos atrás
14 anos atrás
14 anos atrás
14 anos atrás
14 anos atrás
14 anos atrás
14 anos atrás
14 anos atrás
14 anos atrás
14 anos atrás
14 anos atrás
14 anos atrás
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. require 'rubygems'
  2. require 'datamapper'
  3. require 'dm-core'
  4. require 'dm-validations'
  5. require 'dm-timestamps'
  6. require 'dm-aggregates'
  7. require 'dm-serializer'
  8. require 'dm-migrations'
  9. class Payment
  10. include DataMapper::Resource
  11. property :id, Serial
  12. property :created_at, DateTime
  13. property :updated_at, DateTime
  14. property :service_id, Integer, :required => true
  15. property :supplier_id, Integer, :required => true
  16. property :amount, BigDecimal, :precision => 10, :scale => 2, :required => true # ex VAT
  17. property :d, Date, :required => true # transaction date
  18. property :transaction_id, Integer # May not be unique per payment as one transaction could have several payments
  19. belongs_to :service
  20. belongs_to :supplier
  21. has 1, :directorate, { :through => :service }
  22. def url
  23. SETTING.site_url + "payments/" + @id.to_s
  24. end
  25. end
  26. class Directorate
  27. include DataMapper::Resource
  28. property :id, Serial
  29. property :created_at, DateTime
  30. property :updated_at, DateTime
  31. property :name, String, :length => 255, :required => true
  32. property :slug, String, :length => 255, :required => true
  33. has n, :services, :order => ['name']
  34. has n, :suppliers, { :through => :services, :order => ['name'] }
  35. # before :save, :slugify
  36. #
  37. # def slugify
  38. # @slug = @name.gsub(/[^\w\s-]/, '').gsub(/\s+/, '-').downcase
  39. # puts "I've just been slugified"
  40. # end
  41. end
  42. class Service
  43. include DataMapper::Resource
  44. property :id, Serial
  45. property :created_at, DateTime
  46. property :updated_at, DateTime
  47. property :directorate_id, Integer
  48. property :name, String, :length => 255, :required => true
  49. property :slug, String, :length => 255, :required => true
  50. has n, :payments, :order => ['d']
  51. has n, :suppliers, { :through => :payments, :order => ['name'] }
  52. belongs_to :directorate, :required => false
  53. # before :save, :slugify
  54. #
  55. # def slugify
  56. # @slug = @name.gsub(/[^\w\s-]/, '').gsub(/\s+/, '-').downcase
  57. # puts "I've just been slugified"
  58. # end
  59. end
  60. class Supplier
  61. include DataMapper::Resource
  62. property :id, Serial
  63. property :created_at, DateTime
  64. property :updated_at, DateTime
  65. property :name, String, :length => 255, :required => true
  66. property :slug, String, :length => 255, :required => true
  67. has n, :payments, :order => ['d']
  68. has n, :services, { :through => :payments, :order => ['name'] }
  69. has n, :directorates, { :through => :payments }
  70. # before :save, :slugify
  71. #
  72. # def slugify
  73. # @slug = @name.gsub(/[^\w\s-]/, '').gsub(/\s+/, '-').downcase
  74. # end
  75. end
  76. class Council
  77. include DataMapper::Resource
  78. property :id, Serial
  79. property :created_at, DateTime
  80. property :updated_at, DateTime
  81. property :name, String, :length => 255, :required => true
  82. property :slug, String, :length => 255
  83. property :url, String, :length => 255
  84. property :data_url, String, :length => 512
  85. property :open_licence, Boolean, :default => false
  86. property :machine_readable, Boolean, :default => false
  87. property :start_d, Date
  88. property :end_d, Date
  89. before :save, :slugify
  90. def slugify
  91. @slug = @name.gsub(/[^\w\s-]/, '').gsub(/\s+/, '-').downcase
  92. end
  93. end
  94. # This is a singleton. We only use the first row in the settings table.
  95. class Setting
  96. include DataMapper::Resource
  97. property :id, Serial
  98. property :site_name, String, :length => 255, :required => true
  99. property :site_tagline, String, :length => 255
  100. property :site_url, String, :length => 255
  101. property :org_name, String, :length => 255
  102. property :org_url, String, :length => 255
  103. property :data_url, String, :length => 255
  104. property :disqus_shortname, String, :length => 255
  105. property :google_analytics_id, String, :length => 255
  106. end
  107. # DataMapper.setup(:default, ENV['DATABASE_URL'] || "mysql://root@localhost/armchairauditor_sutton")
  108. DataMapper.setup(:default, ENV['DATABASE_URL'] || "sqlite3://#{Dir.pwd}/db.sqlite3")
  109. DataMapper.auto_upgrade!