diff options
Diffstat (limited to 'app/models')
-rw-r--r-- | app/models/info_request.rb | 38 | ||||
-rw-r--r-- | app/models/public_body.rb | 8 | ||||
-rw-r--r-- | app/models/user.rb | 18 |
3 files changed, 43 insertions, 21 deletions
diff --git a/app/models/info_request.rb b/app/models/info_request.rb index ef6f4bc4d..353c84105 100644 --- a/app/models/info_request.rb +++ b/app/models/info_request.rb @@ -22,7 +22,7 @@ # Copyright (c) 2007 UK Citizens Online Democracy. All rights reserved. # Email: francis@mysociety.org; WWW: http://www.mysociety.org/ # -# $Id: info_request.rb,v 1.72 2008-03-24 09:35:23 francis Exp $ +# $Id: info_request.rb,v 1.73 2008-03-25 17:25:09 francis Exp $ require 'digest/sha1' @@ -68,11 +68,29 @@ class InfoRequest < ActiveRecord::Base :title, :initial_request_text, { :status => :string }, - { :created_at => :date } + { :requested_by => :string }, + { :requested_from => :string }, + { :created_at => :date }, + { :type => :string} # see "def type" below ], :if => "$do_solr_index" def status # for name in Solr queries calculate_status end + def requested_by + self.user.url_name + end + def requested_from + self.public_body.url_name + end + # acts_on_solr indexes things with type: anyway but by default does text (full text) + # rather than string (flag) indexing for it. The entry in acts_on_solr above forces + # the type to be string, and this function returns the same value as acts_on_solr would + # anyway. Also, only needs to happen in this one model, as others are + # covered automatically by the multi solr search query command, which treats types same + # across all models. + def type + "InfoRequest" + end $do_solr_index = false $do_solr_index_marking = false @@ -141,15 +159,15 @@ public self.update_url_title end def update_url_title - url_title = MySociety::Format.simplify_url_part(self.title) - if url_title.size > 32 - url_title = url_title[0..31] - end - # For request with same name as others, tag on the request numeric id - while not InfoRequest.find_by_url_title(url_title, :conditions => self.id.nil? ? nil : ["id <> ?", self.id] ).nil? - url_title += "_" + self.id.to_s + url_title = MySociety::Format.simplify_url_part(self.title, 32) + # For request with same title as others, add on arbitary numeric identifier + unique_url_title = url_title + suffix_num = 2 # as there's already one without numeric suffix + while not InfoRequest.find_by_url_title(unique_url_title, :conditions => self.id.nil? ? nil : ["id <> ?", self.id] ).nil? + unique_url_title = url_title + "_" + suffix_num.to_s + suffix_num = suffix_num + 1 end - write_attribute(:url_title, url_title) + write_attribute(:url_title, unique_url_title) end # Email which public body should use to respond to request. This is in diff --git a/app/models/public_body.rb b/app/models/public_body.rb index 066ca8200..2403a97d8 100644 --- a/app/models/public_body.rb +++ b/app/models/public_body.rb @@ -21,7 +21,7 @@ # Copyright (c) 2007 UK Citizens Online Democracy. All rights reserved. # Email: francis@mysociety.org; WWW: http://www.mysociety.org/ # -# $Id: public_body.rb,v 1.46 2008-03-24 20:17:01 francis Exp $ +# $Id: public_body.rb,v 1.47 2008-03-25 17:25:09 francis Exp $ require 'csv' require 'set' @@ -72,8 +72,12 @@ class PublicBody < ActiveRecord::Base acts_as_solr :fields => [ {:name => { :boost => 10.0 }}, {:short_name => { :boost => 10.0 }}, - { :created_at => :date } + { :created_at => :date }, + { :moo => :string } ] + def moo + "authority" + end # When name or short name is changed, also change the url name def short_name=(short_name) diff --git a/app/models/user.rb b/app/models/user.rb index bd2df8267..1bbbdb83a 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -20,7 +20,7 @@ # Copyright (c) 2007 UK Citizens Online Democracy. All rights reserved. # Email: francis@mysociety.org; WWW: http://www.mysociety.org/ # -# $Id: user.rb,v 1.40 2008-03-21 14:45:38 francis Exp $ +# $Id: user.rb,v 1.41 2008-03-25 17:25:09 francis Exp $ require 'digest/sha1' @@ -87,15 +87,15 @@ class User < ActiveRecord::Base self.update_url_name end def update_url_name - url_name = MySociety::Format.simplify_url_part(self.name) - if url_name.size > 32 - url_name = url_name[0..31] + url_name = MySociety::Format.simplify_url_part(self.name, 32) + # For user with same name as others, add on arbitary numeric identifier + unique_url_name = url_name + suffix_num = 2 # as there's already one without numeric suffix + while not User.find_by_url_name(unique_url_name, :conditions => self.id.nil? ? nil : ["id <> ?", self.id] ).nil? + unique_url_name = url_name + "_" + suffix_num.to_s + suffix_num = suffix_num + 1 end - # For request with same name as others, tag on the request numeric id - while not User.find_by_url_name(url_name, :conditions => self.id.nil? ? nil : ["id <> ?", self.id] ).nil? - url_name += "_" + self.id.to_s - end - write_attribute(:url_name, url_name) + write_attribute(:url_name, unique_url_name) end # Virtual password attribute, which stores the hashed password, rather than plain text. |