aboutsummaryrefslogtreecommitdiffstats
path: root/app/models
diff options
context:
space:
mode:
Diffstat (limited to 'app/models')
-rw-r--r--app/models/incoming_message.rb10
-rw-r--r--app/models/info_request.rb28
-rw-r--r--app/models/public_body.rb6
-rw-r--r--app/models/user.rb4
4 files changed, 35 insertions, 13 deletions
diff --git a/app/models/incoming_message.rb b/app/models/incoming_message.rb
index a22385347..661b3b659 100644
--- a/app/models/incoming_message.rb
+++ b/app/models/incoming_message.rb
@@ -18,7 +18,7 @@
# Copyright (c) 2007 UK Citizens Online Democracy. All rights reserved.
# Email: francis@mysociety.org; WWW: http://www.mysociety.org/
#
-# $Id: incoming_message.rb,v 1.55 2008-03-07 10:13:57 francis Exp $
+# $Id: incoming_message.rb,v 1.56 2008-03-07 23:13:38 francis Exp $
# TODO
@@ -320,13 +320,13 @@ class IncomingMessage < ActiveRecord::Base
attachments = self.get_attachments_for_display
for attachment in attachments
if attachment.content_type == 'text/plain'
- text += attachment.body
+ text += attachment.body + "\n\n"
elsif attachment.content_type == 'application/msword'
tempfile = Tempfile.new('foipdf')
tempfile.print attachment.body
tempfile.flush
system("/usr/bin/wvText " + tempfile.path + " " + tempfile.path + ".txt")
- text += File.read(tempfile.path + ".txt")
+ text += File.read(tempfile.path + ".txt") + "\n\n"
File.unlink(tempfile.path + ".txt")
tempfile.close
elsif attachment.content_type == 'application/pdf'
@@ -334,7 +334,7 @@ class IncomingMessage < ActiveRecord::Base
tempfile.print attachment.body
tempfile.flush
IO.popen("/usr/bin/pdftotext " + tempfile.path + " -", "r") do |child|
- text += child.read()
+ text += child.read() + "\n\n"
end
tempfile.close
end
@@ -344,7 +344,7 @@ class IncomingMessage < ActiveRecord::Base
# Returns text for indexing
def get_text_for_indexing
- return get_body_for_quoting + get_attachment_text
+ return get_body_for_quoting + "\n\n" + get_attachment_text
end
# Returns the name of the person the incoming message is from, or nil if there isn't one
diff --git a/app/models/info_request.rb b/app/models/info_request.rb
index 9bff40a60..b6da611d9 100644
--- a/app/models/info_request.rb
+++ b/app/models/info_request.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: info_request.rb,v 1.57 2008-03-06 20:10:29 francis Exp $
+# $Id: info_request.rb,v 1.58 2008-03-07 23:13:38 francis Exp $
require 'digest/sha1'
@@ -64,7 +64,16 @@ class InfoRequest < ActiveRecord::Base
end
# Full text search indexing
- acts_as_solr :fields => [ :title ], :if => "$do_solr_index"
+ acts_as_solr :fields => [
+ :title,
+ :initial_request_text,
+ { :status => :string }
+# { :created_at => :date }
+ ], :if => "$do_solr_index"
+ def status # for name in Solr queries
+ calculate_status
+ end
+
$do_solr_index = false
def self.update_solr_index
$do_solr_index = true
@@ -79,7 +88,13 @@ class InfoRequest < ActiveRecord::Base
raise "failed to solr_save"
end
for outgoing_message in info_request.outgoing_messages
- outgoing_message.solr_save
+ # Initial request text is indexed for InfoRequest models -
+ # see :initial_request_text in acts_as_solr entry above
+ if outgoing_message.message_type != 'initial_request'
+ outgoing_message.solr_save
+ else
+ outgoing_message.solr_destroy
+ end
end
for incoming_message in info_request.incoming_messages
incoming_message.solr_save
@@ -210,6 +225,7 @@ public
end
# Work out what the situation of the request is
+ # waiting_classification
# waiting_response
# waiting_response_overdue # XXX calculated, should be cached for display?
# waiting_clarification
@@ -217,6 +233,10 @@ public
# successful
# partially_successful
def calculate_status
+ if self.awaiting_description
+ return 'waiting_classification'
+ end
+
# See if response would be overdue
date_today = Time.now.strftime("%Y-%m-%d")
date_response = date_response_required_by.strftime("%Y-%m-%d")
@@ -405,7 +425,7 @@ public
# Display version of status
def display_status
status = self.calculate_status
- if self.awaiting_description
+ if status == 'waiting_classification'
"Awaiting classification."
elsif status == 'waiting_response'
"Awaiting response."
diff --git a/app/models/public_body.rb b/app/models/public_body.rb
index c45ec75a6..82eaa5822 100644
--- a/app/models/public_body.rb
+++ b/app/models/public_body.rb
@@ -22,14 +22,12 @@
# 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.33 2008-03-05 18:14:03 francis Exp $
+# $Id: public_body.rb,v 1.34 2008-03-07 23:13:38 francis Exp $
require 'csv'
require 'set'
class PublicBody < ActiveRecord::Base
- #acts_as_solr :fields => [:name, :short_name]
-
validates_presence_of :name
validates_presence_of :url_name
validates_presence_of :request_email
@@ -61,6 +59,8 @@ class PublicBody < ActiveRecord::Base
acts_as_versioned
self.non_versioned_columns << 'created_at' << 'updated_at'
+ acts_as_solr :fields => [{:name => { :boost => 10.0 }}, {:short_name => { :boost => 10.0 }} ]
+
# When name or short name is changed, also change the url name
def short_name=(short_name)
write_attribute(:short_name, short_name)
diff --git a/app/models/user.rb b/app/models/user.rb
index bc1028ae1..547ae4225 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.33 2008-02-28 16:25:30 francis Exp $
+# $Id: user.rb,v 1.34 2008-03-07 23:13:38 francis Exp $
require 'digest/sha1'
@@ -39,6 +39,8 @@ class User < ActiveRecord::Base
attr_accessor :password_confirmation
validates_confirmation_of :password, :message =>"^Please enter the same password twice"
+ acts_as_solr :fields => [ {:name => { :boost => 5.0 }} ]
+
def validate
errors.add(:email, "doesn't look like a valid address") unless MySociety::Validate.is_valid_email(self.email)
end