aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--app/models/incoming_message.rb69
-rw-r--r--app/views/request/_bubble.rhtml6
-rw-r--r--todo.txt21
3 files changed, 63 insertions, 33 deletions
diff --git a/app/models/incoming_message.rb b/app/models/incoming_message.rb
index f03210c47..0784a7dd5 100644
--- a/app/models/incoming_message.rb
+++ b/app/models/incoming_message.rb
@@ -17,7 +17,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.80 2008-04-18 15:44:49 francis Exp $
+# $Id: incoming_message.rb,v 1.81 2008-04-20 21:20:02 francis Exp $
# TODO
@@ -40,6 +40,40 @@ module TMail
end
end
+# To add an image, create a file with appropriate name corresponding to the
+# mime type in public/images e.g. icon_application_msexcel_large.png
+$file_extension_to_mime_type = {
+ "txt" => 'text/plain',
+ "pdf" => 'application/pdf',
+ "doc" => 'application/msword',
+ "rtf" => 'application/rtf',
+ "xls" => 'application/msexcel',
+ "tif" => 'image/tiff',
+ "gif" => 'image/gif'
+}
+$file_extension_to_mime_type_rev = $file_extension_to_mime_type.invert
+
+# XXX clearly this shouldn't be a global function, or the above global vars.
+def filename_to_mimetype(filename)
+ if not filename
+ return nil
+ end
+ if filename.match(/\.([^.]+)$/i)
+ lext = $1.downcase
+ if $file_extension_to_mime_type.include?(lext)
+ return $file_extension_to_mime_type[lext]
+ end
+ end
+ return nil
+end
+
+def mimetype_to_extension(mime)
+ if $file_extension_to_mime_type_rev.include?(mime)
+ return $file_extension_to_mime_type_rev[mime]
+ end
+ return nil
+end
+
# This is the type which is used to send data about attachments to the view
class FOIAttachment
attr_accessor :body
@@ -50,18 +84,13 @@ class FOIAttachment
def display_filename
if @filename
@filename
- elsif @content_type == 'text/plain'
- "attachment.txt"
- elsif @content_type == 'application/pdf'
- "attachment.pdf"
- elsif @content_type == 'application/msword'
- "attachment.doc"
- elsif @content_type == 'application/rtf'
- "attachment.rtf"
- elsif @content_type == 'application/msexcel'
- "attachment.xls"
else
- "attachment.bin"
+ calc_ext = mimetype_to_extension(@content_type)
+ if calc_ext
+ "attachment." + calc_ext
+ else
+ "attachment.bin"
+ end
end
end
end
@@ -249,8 +278,9 @@ class IncomingMessage < ActiveRecord::Base
else
# PDFs often come with this mime type, fix it up for view code
if curr_mail.content_type == 'application/octet-stream'
- if TMail::Mail.get_part_file_name(curr_mail).match(/\.pdf$/)
- curr_mail.content_type = 'application/pdf'
+ calc_mime = filename_to_mimetype(TMail::Mail.get_part_file_name(curr_mail))
+ if calc_mime
+ curr_mail.content_type = calc_mime
end
end
# e.g. http://www.whatdotheyknow.com/request/93/response/250
@@ -340,14 +370,9 @@ class IncomingMessage < ActiveRecord::Base
attachment = FOIAttachment.new()
attachment.body = content
attachment.filename = uu.match(/^begin\s+[0-9]+\s+(.*)$/)[1]
- if attachment.filename.match(/\.pdf$/)
- attachment.content_type = 'application/pdf'
- elsif attachment.filename.match(/\.doc$/)
- attachment.content_type = 'application/msword'
- elsif attachment.filename.match(/\.rtf$/)
- attachment.content_type = 'application/rtf'
- elsif attachment.filename.match(/\.xls$/)
- attachment.content_type = 'application/msexcel'
+ calc_mime = filename_to_mimetype(attachment.filename)
+ if calc_mime
+ attachment.content_type = calc_mime
else
attachment.content_type = 'application/octet-stream'
end
diff --git a/app/views/request/_bubble.rhtml b/app/views/request/_bubble.rhtml
index 0327f4b91..de3ee296f 100644
--- a/app/views/request/_bubble.rhtml
+++ b/app/views/request/_bubble.rhtml
@@ -7,8 +7,10 @@
<p> <% attachments.each do |a| %>
<% attachment_url = get_attachment_url(:id => incoming_message.info_request_id,
:incoming_message_id => incoming_message.id, :part => a.url_part_number, :file_name => a.display_filename) %>
- <% if ['application/pdf', 'application/msword', 'application/rtf', 'application/msexcel', 'text/plain', 'image/tiff', 'image/gif'].include?(a.content_type) %>
- <a href="<%=attachment_url%>"><img class="attachment_image" alt="Attachment" src="/images/icon_<%=a.content_type.sub('/', '_')%>_large.png"></a>
+ <% img_filename = "icon_" + a.content_type.sub('/', '_') + "_large.png"
+ full_filename = File.join(File.dirname(__FILE__), "../../../public/images", img_filename)
+ if File.exist?(full_filename) %>
+ <a href="<%=attachment_url%>"><img class="attachment_image" alt="Attachment" src="/images/<%=img_filename%>"></a>
<% else %>
Attachment:
<% end %>
diff --git a/todo.txt b/todo.txt
index 67a2e8512..88c7ceb16 100644
--- a/todo.txt
+++ b/todo.txt
@@ -1,9 +1,21 @@
Watch this one:
http://www.whatdotheyknow.com/request/crime_statistics_for_2007_champi
+OK, so we could index status of requests... But then there are two problems:
+1) Have to somehow reindex when a request becomes overdue.
+2) The Email/RSS won't work that well, as it uses created date as a filter,
+which won't work for when there is no event.
+
+Group requests by response
+Make it totally awesome like in Tommy's screenshot
+Cluster solr patch - https://issues.apache.org/jira/browse/SOLR-236
+
FOI requests to use to test it
==============================
+Complaint to info commissioner:
+http://www.whatdotheyknow.com/request/search_engine_advertising_bought
+
http://www.whatdotheyknow.com/request/details_of_grant_awarded_to_vi_g_
I received a reply on 4 April from Alison McCarthy to my request for
information about a development grant (SIC Code 7220) to Vero International
@@ -31,9 +43,6 @@ BAILII - relationship with law courts, robots.txt ?
Next
====
-Group requests by response
-Make it totally awesome like in Tommy's screenshot
-
Things to track:
- new requests
- new requests with keyword
@@ -57,12 +66,6 @@ When you click RSS feed when on own request, default to RSS in the choice on nex
"Some of the information" option should give you choice of complaining if you like.
-Add credits for everyone
- Heather Brook, Chris Lightfoot, other original suggester in Call for Proposals
- Julian Todd, Francis Davey, Etienne Pollard
- Alex Skene, John Cross, Adam McGregor
- Angie Ahl, Matthew Somerville, Tom Steinberg, Tommy, Francis Irving
-
Offer search on 404s
Search and replace text "FOI" and "Freedom of Information" out the way more