Deprecated redirect_to_path and redirect_to_url in favor of letting redirect_to do the right thing when passed either a path or url. Introduced r as a unified method for render (still under construction)

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@1349 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
This commit is contained in:
David Heinemeier Hansson 2005-05-22 07:43:05 +00:00
parent dab360e181
commit 0367317dd6
9 changed files with 396 additions and 50 deletions

@ -1,5 +1,7 @@
*SVN*
* Deprecated redirect_to_path and redirect_to_url in favor of letting redirect_to do the right thing when passed either a path or url.
* Fixed use of an integer as return code for renders, so render_text "hello world", 404 now works #1327
* Fixed assert_redirect_to to work with redirect_to_path #869 [Nicholas Seckar]

@ -439,6 +439,52 @@ def action_name
end
protected
# A unified replacement for the individual renders (work-in-progress).
def r(options = {}, &block)
raise DoubleRenderError, "Can only render or redirect once per action" if performed?
add_variables_to_assigns
options[:status] = (options[:status] || DEFAULT_RENDER_STATUS_CODE).to_s
if options[:text]
@response.headers["Status"] = options[:status]
@response.body = block_given? ? block : options[:text]
@performed_render = true
return options[:text]
elsif options[:file]
assert_existance_of_template_file(options[:file]) if options[:use_full_path]
logger.info("Rendering #{options[:file]} (#{options[:status]})") unless logger.nil?
r(options.merge({ :text => @template.render_file(options[:file], options[:use_full_path])}))
elsif options[:template]
r(options.merge({ :file => options[:template], :use_full_path => true }))
elsif options[:inline]
r(options.merge({ :text => @template.render_template(options[:type] || :rhtml, options[:inline]) }))
elsif options[:action]
r(options.merge({ :template => default_template_name(options[:action]) }))
elsif options[:partial] && options[:collection]
r(options.merge({
:text => (
@template.render_partial_collection(
options[:partial], options[:collection], options[:spacer_template], options[:local_assigns]
) || ''
)
}))
elsif options[:partial]
r(options.merge({ :text => @template.render_partial(options[:partial], options[:object], options[:local_assigns]) }))
elsif options[:nothing]
r(options.merge({ :text => "" }))
else
r(options.merge({ :template => default_template_name }))
end
end
# Renders the template specified by <tt>template_name</tt>, which defaults to the name of the current controller and action.
# So calling +render+ in WeblogController#show will attempt to render "#{template_root}/weblog/show.rhtml" or
# "#{template_root}/weblog/show.rxml" (in that order). The template_root is set on the ActionController::Base class and is
@ -480,7 +526,7 @@ def render_template(template, status = nil, type = "rhtml") #:doc:
def render_text(text = nil, status = nil, &block) #:doc:
raise DoubleRenderError, "Can only render or redirect once per action" if performed?
add_variables_to_assigns
@response.headers["Status"] = status.to_s || DEFAULT_RENDER_STATUS_CODE
@response.headers["Status"] = (status || DEFAULT_RENDER_STATUS_CODE).to_s
@response.body = block_given? ? block : text
@performed_render = true
end
@ -645,32 +691,51 @@ def rewrite_options(options)
def default_url_options(options) #:doc:
end
# Redirects the browser to an URL that has been rewritten according to the hash of +options+ using a "302 Moved" HTTP header.
# See url_for for a description of the valid options.
# Redirects the browser to the target specified in +options+. This parameter can take one of three forms:
#
# * <tt>Hash</tt>: The URL will be generated by calling url_for with the +options+.
# * <tt>String starting with protocol:// (like http://)</tt>: Is passed straight through as the target for redirection.
# * <tt>String not containing a protocol</tt>: The current current protocol and host is prepended to the string.
#
# Examples:
# redirect_to :action => "show", :id => 5
# redirect_to "http://www.rubyonrails.org"
# redirect_to "/images/screenshot.jpg"
#
# The redirection happens as a "302 Moved" header.
def redirect_to(options = {}, *parameters_for_method_reference) #:doc:
if parameters_for_method_reference.empty?
@response.redirected_to = options
redirect_to_url(url_for(options))
else
@response.redirected_to, @response.redirected_to_method_params = options, parameters_for_method_reference
redirect_to_url(url_for(options, *parameters_for_method_reference))
case options
when %r{^\w+://.*}
raise DoubleRenderError, "Can only render or redirect once per action" if performed?
logger.info("Redirected to #{url}") unless logger.nil?
@response.redirect(options)
@performed_redirect = true
when String
redirect_to(request.protocol + request.host_with_port + options)
else
if parameters_for_method_reference.empty?
response.redirected_to = options
redirect_to(url_for(options))
else
response.redirected_to, response.redirected_to_method_params = options, parameters_for_method_reference
redirect_to(url_for(options, *parameters_for_method_reference))
end
end
end
# Redirects the browser to the specified <tt>path</tt> within the current host (specified with a leading /). Used to sidestep
# the URL rewriting and go directly to a known path. Example: <tt>redirect_to_path "/images/screenshot.jpg"</tt>.
# Deprecated in favor of calling redirect_to directly with the path.
def redirect_to_path(path) #:doc:
redirect_to_url(@request.protocol + @request.host_with_port + path)
redirect_to(path)
end
# Redirects the browser to the specified <tt>url</tt>. Used to redirect outside of the current application. Example:
# <tt>redirect_to_url "http://www.rubyonrails.org"</tt>. If the resource has moved permanently, it's possible to pass true as the
# second parameter and the browser will get "301 Moved Permanently" instead of "302 Found".
# Deprecated in favor of calling redirect_to directly with the url. If the resource has moved permanently, it's possible to pass
# true as the second parameter and the browser will get "301 Moved Permanently" instead of "302 Found". This can also be done through
# just setting the headers["Status"] to "301 Moved Permanently" before using the redirect_to.
def redirect_to_url(url, permanently = false) #:doc:
raise DoubleRenderError, "Can only render or redirect once per action" if performed?
logger.info("Redirected to #{url}") unless logger.nil?
@response.redirect(url, permanently)
@performed_redirect = true
headers["Status"] = "301 Moved Permanently" if permanently
redirect_to(url)
end
# Resets the session by clearing out all the objects stored within and initializing a new session object.

@ -5,6 +5,10 @@ def self.append_features(base)
base.class_eval do
alias_method :render_without_layout, :render
alias_method :render, :render_with_layout
alias_method :r_without_layout, :r
alias_method :r, :r_with_layout
class << self
alias_method :inherited_without_layout, :inherited
end
@ -212,8 +216,33 @@ def render_with_layout(template_name = default_template_name, status = nil, layo
end
end
def r_with_layout(options = {})
if (layout = active_layout_for_r(options)) && options[:text]
add_variables_to_assigns
logger.info("Rendering #{template_name} within #{layout}") unless logger.nil?
@content_for_layout = r_without_layout(options)
add_variables_to_assigns
erase_render_results
r_without_layout(options.merge({ :text => @template.render_file(layout, true)}))
else
r_without_layout(options)
end
end
private
def active_layout_for_r(options = {})
case options[:layout]
when FalseClass
nil
when NilClass
active_layout if action_has_layout?
else
active_layout(options[:layout])
end
end
def action_has_layout?
conditions = self.class.layout_conditions
case
@ -225,6 +254,5 @@ def action_has_layout?
true
end
end
end
end
end

@ -1,6 +1,8 @@
module ActionController
# These methods are available in both the production and test Request objects.
class AbstractRequest
cattr_accessor :relative_url_root
# Returns both GET and POST parameters in a single hash.
def parameters
@parameters ||= request_parameters.merge(query_parameters).merge(path_parameters).with_indifferent_access
@ -57,6 +59,16 @@ def xml_post?
def yaml_post?
post_format == :yaml && post?
end
# Returns true if the request's "X-Requested-With" header contains
# "XMLHttpRequest". (The Prototype Javascript library sends this header with
# every Ajax request.)
def xml_http_request?
env['HTTP_X_REQUESTED_WITH'] =~ /XMLHttpRequest/i
end
alias xhr? :xml_http_request?
# Determine originating IP address. REMOTE_ADDR is the standard
@ -120,20 +132,15 @@ def ssl?
protocol == 'https://'
end
# returns the interpreted path to requested resource after
# all the installation directory of this application was taken into account
# Returns the interpreted path to requested resource after all the installation directory of this application was taken into account
def path
uri = request_uri
path = uri ? uri.split('?').first : ''
# cut off the part of the url which leads to the installation directory of this app
path[relative_url_root.length..-1]
path = (uri = request_uri) ? uri.split('?').first : ''
path[relative_url_root.length..-1] # cut off the part of the url which leads to the installation directory of this app
end
# returns the path minus the web server relative
# installation directory
def relative_url_root
@@relative_url_root ||= File.dirname(env["SCRIPT_NAME"].to_s).gsub /(^\.$|^\/$)/, ''
# Returns the path minus the web server relative installation directory
def relative_url_root(force_reload = false)
@@relative_url_root ||= File.dirname(env["SCRIPT_NAME"].to_s).gsub(/(^\.$|^\/$)/, '')
end
def port
@ -158,14 +165,6 @@ def path_parameters
@path_parameters ||= {}
end
# Returns true if the request's "X-Requested-With" header contains
# "XMLHttpRequest". (The Prototype Javascript library sends this header with
# every Ajax request.)
def xml_http_request?
env['HTTP_X_REQUESTED_WITH'] =~ /XMLHttpRequest/i
end
alias xhr? :xml_http_request?
#--
# Must be implemented in the concrete request
#++

@ -8,7 +8,7 @@ def initialize
end
def redirect(to_url, permanently = false)
@headers["Status"] = permanently ? "301 Moved Permanently" : "302 Found"
@headers["Status"] ||= "302 Found"
@headers["location"] = to_url
@body = "<html><body>You are being <a href=\"#{to_url}\">redirected</a>.</body></html>"

@ -13,7 +13,7 @@ def hello_world() render "test/hello_world"; end
def hello_xml_world() render "test/hello_xml_world"; end
# a redirect to an internal location
def redirect_internal() redirect_to "nothing"; end
def redirect_internal() redirect_to "/nothing"; end
def redirect_to_action() redirect_to :action => "flash_me", :id => 1, :params => { "panda" => "fun" }; end
@ -270,7 +270,7 @@ def test_rendered_action
# check the redirection location
def test_redirection_location
process :redirect_internal
assert_equal 'nothing', @response.redirect_url
assert_equal 'http://test.host/nothing', @response.redirect_url
process :redirect_external
assert_equal 'http://www.rubyonrails.org', @response.redirect_url

@ -0,0 +1,237 @@
require File.dirname(__FILE__) + '/../abstract_unit'
Customer = Struct.new("Customer", :name)
module Fun
class GamesController < ActionController::Base
def hello_world
end
end
end
class TestController < ActionController::Base
layout :determine_layout
def hello_world
end
def render_hello_world
r :template => "test/hello_world"
end
def render_hello_world_from_variable
@person = "david"
r :text => "hello #{@person}"
end
def render_action_hello_world
r :action => "hello_world"
end
def render_text_hello_world
r :text => "hello world"
end
def render_custom_code
r :text => "hello world", :status => "404 Moved"
end
def render_xml_hello
@name = "David"
r :template => "test/hello"
end
def greeting
# let's just rely on the template
end
def layout_test
r :action => "hello_world"
end
def layout_test_with_different_layout
r :action => "hello_world", :layout => "standard"
end
def rendering_without_layout
r :action => "hello_world", :layout => false
end
def builder_layout_test
r :action => "hello"
end
def partials_list
@customers = [ Customer.new("david"), Customer.new("mary") ]
r :action => "list"
end
def partial_only
render_partial
end
def hello_in_a_string
@customers = [ Customer.new("david"), Customer.new("mary") ]
r :text => "How's there? #{render_to_string("test/list")}"
end
def accessing_params_in_template
r :inline => "Hello: <%= params[:name] %>"
end
def rescue_action(e) raise end
private
def determine_layout
case action_name
when "layout_test", "rendering_without_layout"
"layouts/standard"
when "builder_layout_test"
"layouts/builder"
end
end
end
TestController.template_root = File.dirname(__FILE__) + "/../fixtures/"
Fun::GamesController.template_root = File.dirname(__FILE__) + "/../fixtures/"
class TestLayoutController < ActionController::Base
layout "layouts/standard"
def hello_world
end
def hello_world_outside_layout
end
def rescue_action(e)
raise unless ActionController::MissingTemplate === e
end
end
class RenderTest < Test::Unit::TestCase
def setup
@request = ActionController::TestRequest.new
@response = ActionController::TestResponse.new
@request.host = "www.nextangle.com"
end
def test_simple_show
@request.action = "hello_world"
response = process_request
assert_equal "200 OK", response.headers["Status"]
assert_equal "test/hello_world", response.template.first_render
end
def test_do_with_render
@request.action = "render_hello_world"
assert_equal "test/hello_world", process_request.template.first_render
end
def test_do_with_render_from_variable
@request.action = "render_hello_world_from_variable"
assert_equal "hello david", process_request.body
end
def test_do_with_render_action
@request.action = "render_action_hello_world"
assert_equal "test/hello_world", process_request.template.first_render
end
def test_do_with_render_text
@request.action = "render_text_hello_world"
assert_equal "hello world", process_request.body
end
def test_do_with_render_custom_code
@request.action = "render_custom_code"
assert_equal "404 Moved", process_request.headers["Status"]
end
def test_attempt_to_access_object_method
@request.action = "clone"
assert_raises(ActionController::UnknownAction, "No action responded to [clone]") { process_request }
end
def test_private_methods
@request.action = "determine_layout"
assert_raises(ActionController::UnknownAction, "No action responded to [determine_layout]") { process_request }
end
def test_access_to_request_in_view
ActionController::Base.view_controller_internals = false
@request.action = "hello_world"
response = process_request
assert_nil response.template.assigns["request"]
ActionController::Base.view_controller_internals = true
@request.action = "hello_world"
response = process_request
assert_kind_of ActionController::AbstractRequest, response.template.assigns["request"]
end
def test_render_xml
@request.action = "render_xml_hello"
assert_equal "<html>\n <p>Hello David</p>\n<p>This is grand!</p>\n</html>\n", process_request.body
end
def test_render_xml_with_default
@request.action = "greeting"
assert_equal "<p>This is grand!</p>\n", process_request.body
end
def test_layout_rendering
@request.action = "layout_test"
assert_equal "<html>Hello world!</html>", process_request.body
end
def test_layout_test_with_different_layout
@request.action = "layout_test_with_different_layout"
assert_equal "<html>Hello world!</html>", process_request.body
end
def test_rendering_without_layout
@request.action = "rendering_without_layout"
assert_equal "Hello world!", process_request.body
end
def test_render_xml_with_layouts
@request.action = "builder_layout_test"
assert_equal "<wrapper>\n<html>\n <p>Hello </p>\n<p>This is grand!</p>\n</html>\n</wrapper>\n", process_request.body
end
def test_partials_list
@request.action = "partials_list"
assert_equal "Hello: davidHello: mary", process_request.body
end
def test_partial_only
@request.action = "partial_only"
assert_equal "only partial", process_request.body
end
def test_render_to_string
@request.action = "hello_in_a_string"
assert_equal "How's there? Hello: davidHello: mary", process_request.body
end
def test_nested_rendering
@request.action = "hello_world"
assert_equal "Living in a nested world", Fun::GamesController.process(@request, @response).body
end
def test_accessing_params_in_template
@request.action = "accessing_params_in_template"
@request.query_parameters[:name] = "David"
assert_equal "Hello: David", process_request.body
end
private
def process_request
TestController.process(@request, @response)
end
end

@ -65,7 +65,7 @@ def test_port_string
assert_equal ":8080", @request.port_string
end
def test_relative_url_root
def test_relative_url_root
@request.env['SCRIPT_NAME'] = nil
assert_equal "", @request.relative_url_root
@ -75,92 +75,108 @@ def test_relative_url_root
@request.env['SCRIPT_NAME'] = "/myapp.rb"
assert_equal "", @request.relative_url_root
@request.relative_url_root = nil
@request.env['SCRIPT_NAME'] = "/hieraki/dispatch.cgi"
assert_equal "/hieraki", @request.relative_url_root
@request.relative_url_root = nil
@request.env['SCRIPT_NAME'] = "/collaboration/hieraki/dispatch.cgi"
assert_equal "/collaboration/hieraki", @request.relative_url_root
end
def test_request_uri
@request.relative_url_root = nil
@request.set_REQUEST_URI "http://www.rubyonrails.org/path/of/some/uri?mapped=1"
assert_equal "/path/of/some/uri?mapped=1", @request.request_uri
assert_equal "/path/of/some/uri", @request.path
@request.relative_url_root = nil
@request.set_REQUEST_URI "http://www.rubyonrails.org/path/of/some/uri"
assert_equal "/path/of/some/uri", @request.request_uri
assert_equal "/path/of/some/uri", @request.path
@request.relative_url_root = nil
@request.set_REQUEST_URI "/path/of/some/uri"
assert_equal "/path/of/some/uri", @request.request_uri
assert_equal "/path/of/some/uri", @request.path
@request.relative_url_root = nil
@request.set_REQUEST_URI "/"
assert_equal "/", @request.request_uri
assert_equal "/", @request.path
@request.relative_url_root = nil
@request.set_REQUEST_URI "/?m=b"
assert_equal "/?m=b", @request.request_uri
assert_equal "/", @request.path
@request.relative_url_root = nil
@request.set_REQUEST_URI "/"
@request.env['SCRIPT_NAME'] = "/dispatch.cgi"
assert_equal "/", @request.request_uri
assert_equal "/", @request.path
@request.relative_url_root = nil
@request.set_REQUEST_URI "/hieraki/"
@request.env['SCRIPT_NAME'] = "/hieraki/dispatch.cgi"
assert_equal "/hieraki/", @request.request_uri
assert_equal "/", @request.path
@request.relative_url_root = nil
@request.set_REQUEST_URI "/collaboration/hieraki/books/edit/2"
@request.env['SCRIPT_NAME'] = "/collaboration/hieraki/dispatch.cgi"
assert_equal "/collaboration/hieraki/books/edit/2", @request.request_uri
assert_equal "/books/edit/2", @request.path
# The following tests are for when REQUEST_URI is not supplied (as in IIS)
@request.relative_url_root = nil
@request.set_REQUEST_URI nil
@request.env['PATH_INFO'] = "/path/of/some/uri?mapped=1"
@request.env['SCRIPT_NAME'] = nil #"/path/dispatch.rb"
assert_equal "/path/of/some/uri?mapped=1", @request.request_uri
assert_equal "/path/of/some/uri", @request.path
@request.relative_url_root = nil
@request.env['PATH_INFO'] = "/path/of/some/uri?mapped=1"
@request.env['SCRIPT_NAME'] = "/path/dispatch.rb"
assert_equal "/path/of/some/uri?mapped=1", @request.request_uri
assert_equal "/of/some/uri", @request.path
@request.relative_url_root = nil
@request.env['PATH_INFO'] = "/path/of/some/uri"
@request.env['SCRIPT_NAME'] = nil
assert_equal "/path/of/some/uri", @request.request_uri
assert_equal "/path/of/some/uri", @request.path
@request.relative_url_root = nil
@request.env['PATH_INFO'] = "/"
assert_equal "/", @request.request_uri
assert_equal "/", @request.path
@request.relative_url_root = nil
@request.env['PATH_INFO'] = "/?m=b"
assert_equal "/?m=b", @request.request_uri
assert_equal "/", @request.path
@request.relative_url_root = nil
@request.env['PATH_INFO'] = "/"
@request.env['SCRIPT_NAME'] = "/dispatch.cgi"
assert_equal "/", @request.request_uri
assert_equal "/", @request.path
@request.relative_url_root = nil
@request.env['PATH_INFO'] = "/hieraki/"
@request.env['SCRIPT_NAME'] = "/hieraki/dispatch.cgi"
assert_equal "/hieraki/", @request.request_uri
assert_equal "/", @request.path
# This test ensures that Rails uses REQUEST_URI over PATH_INFO
@request.relative_url_root = nil
@request.env['REQUEST_URI'] = "/some/path"
@request.env['PATH_INFO'] = "/another/path"
@request.env['SCRIPT_NAME'] = "/dispatch.cgi"
assert_equal "/some/path", @request.request_uri
assert_equal "/some/path", @request.path
end

@ -1,5 +1,4 @@
require 'test/unit'
require File.dirname(__FILE__) + '/../../lib/action_view/helpers/form_options_helper'
require File.dirname(__FILE__) + '/../abstract_unit'
class MockTimeZone
attr_reader :name
@ -260,7 +259,7 @@ def test_country_select
assert_equal(
"<select id=\"post_origin\" name=\"post[origin]\"><option value=\"Afghanistan\">Afghanistan</option>\n<option value=\"Albania\">Albania</option>\n<option value=\"Algeria\">Algeria</option>\n<option value=\"American Samoa\">American Samoa</option>\n<option value=\"Andorra\">Andorra</option>\n<option value=\"Angola\">Angola</option>\n<option value=\"Anguilla\">Anguilla</option>\n<option value=\"Antarctica\">Antarctica</option>\n<option value=\"Antigua And Barbuda\">Antigua And Barbuda</option>\n<option value=\"Argentina\">Argentina</option>\n<option value=\"Armenia\">Armenia</option>\n<option value=\"Aruba\">Aruba</option>\n<option value=\"Australia\">Australia</option>\n<option value=\"Austria\">Austria</option>\n<option value=\"Azerbaijan\">Azerbaijan</option>\n<option value=\"Bahamas\">Bahamas</option>\n<option value=\"Bahrain\">Bahrain</option>\n<option value=\"Bangladesh\">Bangladesh</option>\n<option value=\"Barbados\">Barbados</option>\n<option value=\"Belarus\">Belarus</option>\n<option value=\"Belgium\">Belgium</option>\n<option value=\"Belize\">Belize</option>\n<option value=\"Benin\">Benin</option>\n<option value=\"Bermuda\">Bermuda</option>\n<option value=\"Bhutan\">Bhutan</option>\n<option value=\"Bolivia\">Bolivia</option>\n<option value=\"Bosnia and Herzegowina\">Bosnia and Herzegowina</option>\n<option value=\"Botswana\">Botswana</option>\n<option value=\"Bouvet Island\">Bouvet Island</option>\n<option value=\"Brazil\">Brazil</option>\n<option value=\"British Indian Ocean Territory\">British Indian Ocean Territory</option>\n<option value=\"Brunei Darussalam\">Brunei Darussalam</option>\n<option value=\"Bulgaria\">Bulgaria</option>\n<option value=\"Burkina Faso\">Burkina Faso</option>\n<option value=\"Burma\">Burma</option>\n<option value=\"Burundi\">Burundi</option>\n<option value=\"Cambodia\">Cambodia</option>\n<option value=\"Cameroon\">Cameroon</option>\n<option value=\"Canada\">Canada</option>\n<option value=\"Cape Verde\">Cape Verde</option>\n<option value=\"Cayman Islands\">Cayman Islands</option>\n<option value=\"Central African Republic\">Central African Republic</option>\n<option value=\"Chad\">Chad</option>\n<option value=\"Chile\">Chile</option>\n<option value=\"China\">China</option>\n<option value=\"Christmas Island\">Christmas Island</option>\n<option value=\"Cocos (Keeling) Islands\">Cocos (Keeling) Islands</option>\n<option value=\"Colombia\">Colombia</option>\n<option value=\"Comoros\">Comoros</option>\n<option value=\"Congo\">Congo</option>\n<option value=\"Congo, the Democratic Republic of the\">Congo, the Democratic Republic of the</option>\n<option value=\"Cook Islands\">Cook Islands</option>\n<option value=\"Costa Rica\">Costa Rica</option>\n<option value=\"Cote d'Ivoire\">Cote d'Ivoire</option>\n<option value=\"Croatia\">Croatia</option>\n<option value=\"Cyprus\">Cyprus</option>\n<option value=\"Czech Republic\">Czech Republic</option>\n<option value=\"Denmark\" selected=\"selected\">Denmark</option>\n<option value=\"Djibouti\">Djibouti</option>\n<option value=\"Dominica\">Dominica</option>\n<option value=\"Dominican Republic\">Dominican Republic</option>\n<option value=\"East Timor\">East Timor</option>\n<option value=\"Ecuador\">Ecuador</option>\n<option value=\"Egypt\">Egypt</option>\n<option value=\"El Salvador\">El Salvador</option>\n<option value=\"England\">England" +
"</option>\n<option value=\"Equatorial Guinea\">Equatorial Guinea</option>\n<option value=\"Eritrea\">Eritrea</option>\n<option value=\"Espana\">Espana</option>\n<option value=\"Estonia\">Estonia</option>\n<option value=\"Ethiopia\">Ethiopia</option>\n<option value=\"Falkland Islands\">Falkland Islands</option>\n<option value=\"Faroe Islands\">Faroe Islands</option>\n<option value=\"Fiji\">Fiji</option>\n<option value=\"Finland\">Finland</option>\n<option value=\"France\">France</option>\n<option value=\"French Guiana\">French Guiana</option>\n<option value=\"French Polynesia\">French Polynesia</option>\n<option value=\"French Southern Territories\">French Southern Territories</option>\n<option value=\"Gabon\">Gabon</option>\n<option value=\"Gambia\">Gambia</option>\n<option value=\"Georgia\">Georgia</option>\n<option value=\"Germany\">Germany</option>\n<option value=\"Ghana\">Ghana</option>\n<option value=\"Gibraltar\">Gibraltar</option>\n<option value=\"Great Britain\">Great Britain</option>\n<option value=\"Greece\">Greece</option>\n<option value=\"Greenland\">Greenland</option>\n<option value=\"Grenada\">Grenada</option>\n<option value=\"Guadeloupe\">Guadeloupe</option>\n<option value=\"Guam\">Guam</option>\n<option value=\"Guatemala\">Guatemala</option>\n<option value=\"Guinea\">Guinea</option>\n<option value=\"Guinea-Bissau\">Guinea-Bissau</option>\n<option value=\"Guyana\">Guyana</option>\n<option value=\"Haiti\">Haiti</option>\n<option value=\"Heard and Mc Donald Islands\">Heard and Mc Donald Islands</option>\n<option value=\"Honduras\">Honduras</option>\n<option value=\"Hong Kong\">Hong Kong</option>\n<option value=\"Hungary\">Hungary</option>\n<option value=\"Iceland\">Iceland</option>\n<option value=\"India\">India</option>\n<option value=\"Indonesia\">Indonesia</option>\n<option value=\"Ireland\">Ireland</option>\n<option value=\"Israel\">Israel</option>\n<option value=\"Italy\">Italy</option>\n<option value=\"Iran\">Iran</option>\n<option value=\"Irak\">Irak</option>\n<option value=\"Jamaica\">Jamaica</option>\n<option value=\"Japan\">Japan</option>\n<option value=\"Jordan\">Jordan</option>\n<option value=\"Kazakhstan\">Kazakhstan</option>\n<option value=\"Kenya\">Kenya</option>\n<option value=\"Kiribati\">Kiribati</option>\n<option value=\"Korea, Republic of\">Korea, Republic of</option>\n<option value=\"Korea (South)\">Korea (South)</option>\n<option value=\"Kuwait\">Kuwait</option>\n<option value=\"Kyrgyzstan\">Kyrgyzstan</option>\n<option value=\"Lao People's Democratic Republic\">Lao People's Democratic Republic</option>\n<option value=\"Latvia\">Latvia</option>\n<option value=\"Lebanon\">Lebanon</option>\n<option value=\"Lesotho\">Lesotho</option>\n<option value=\"Liberia\">Liberia</option>\n<option value=\"Liechtenstein\">Liechtenstein</option>\n<option value=\"Lithuania\">Lithuania</option>\n<option value=\"Luxembourg\">Luxembourg</option>\n<option value=\"Macau\">Macau</option>\n<option value=\"Macedonia\">Macedonia</option>\n<option value=\"Madagascar\">Madagascar</option>\n<option value=\"Malawi\">Malawi</option>\n<option value=\"Malaysia\">Malaysia</option>\n<option value=\"Maldives\">Maldives</option>\n<option value=\"Mali\">Mali</option>\n<option value=\"Malta\">Malta</option>\n<option value=\"Marshall Islands\">Marshall Islands</option>\n<option value=\"Martinique\">Martinique</option>\n<option value=\"Mauritania\">Mauritania</option>\n<option value=\"Mauritius\">Mauritius</option>\n<option value=\"Mayotte\">Mayotte</option>\n<option value=\"Mexico\">Mexico</option>\n<option value=\"Micronesia, Federated States of\">Micronesia, Federated States of</option>\n<option value=\"Moldova, Republic of\">Moldova, Republic of</option>\n<option value=\"Monaco\">Monaco</option>\n<option value=\"Mongolia\">Mongolia</option>\n<option value=\"Montserrat\">Montserrat</option>\n<option value=\"Morocco\">Morocco</option>\n<option value=\"Mozambique\">Mozambique</option>\n<option value=\"Myanmar\">Myanmar</option>\n<option value=\"Namibia\">Namibia</option>\n<option value=\"Nauru\">Nauru</option>\n<option value=\"Nepal\">Nepal</option>\n<option value=\"Netherlands\">Netherlands</option>\n<option value=\"Netherlands Antilles\">Netherlands Antilles</option>\n<option value=\"New Caledonia\">New Caledonia</option>" +
"\n<option value=\"New Zealand\">New Zealand</option>\n<option value=\"Nicaragua\">Nicaragua</option>\n<option value=\"Niger\">Niger</option>\n<option value=\"Nigeria\">Nigeria</option>\n<option value=\"Niue\">Niue</option>\n<option value=\"Norfolk Island\">Norfolk Island</option>\n<option value=\"Northern Ireland\">Northern Ireland</option>\n<option value=\"Northern Mariana Islands\">Northern Mariana Islands</option>\n<option value=\"Norway\">Norway</option>\n<option value=\"Oman\">Oman</option>\n<option value=\"Pakistan\">Pakistan</option>\n<option value=\"Palau\">Palau</option>\n<option value=\"Panama\">Panama</option>\n<option value=\"Papua New Guinea\">Papua New Guinea</option>\n<option value=\"Paraguay\">Paraguay</option>\n<option value=\"Peru\">Peru</option>\n<option value=\"Philippines\">Philippines</option>\n<option value=\"Pitcairn\">Pitcairn</option>\n<option value=\"Poland\">Poland</option>\n<option value=\"Portugal\">Portugal</option>\n<option value=\"Puerto Rico\">Puerto Rico</option>\n<option value=\"Qatar\">Qatar</option>\n<option value=\"Reunion\">Reunion</option>\n<option value=\"Romania\">Romania</option>\n<option value=\"Russia\">Russia</option>\n<option value=\"Rwanda\">Rwanda</option>\n<option value=\"Saint Kitts and Nevis\">Saint Kitts and Nevis</option>\n<option value=\"Saint Lucia\">Saint Lucia</option>\n<option value=\"Saint Vincent and the Grenadines\">Saint Vincent and the Grenadines</option>\n<option value=\"Samoa (Independent)\">Samoa (Independent)</option>\n<option value=\"San Marino\">San Marino</option>\n<option value=\"Sao Tome and Principe\">Sao Tome and Principe</option>\n<option value=\"Saudi Arabia\">Saudi Arabia</option>\n<option value=\"Scotland\">Scotland</option>\n<option value=\"Senegal\">Senegal</option>\n<option value=\"Seychelles\">Seychelles</option>\n<option value=\"Sierra Leone\">Sierra Leone</option>\n<option value=\"Singapore\">Singapore</option>\n<option value=\"Slovakia\">Slovakia</option>\n<option value=\"Slovenia\">Slovenia</option>\n<option value=\"Solomon Islands\">Solomon Islands</option>\n<option value=\"Somalia\">Somalia</option>\n<option value=\"South Africa\">South Africa</option>\n<option value=\"South Georgia and the South Sandwich Islands\">South Georgia and the South Sandwich Islands</option>\n<option value=\"South Korea\">South Korea</option>\n<option value=\"Spain\">Spain</option>\n<option value=\"Sri Lanka\">Sri Lanka</option>\n<option value=\"St. Helena\">St. Helena</option>\n<option value=\"St. Pierre and Miquelon\">St. Pierre and Miquelon</option>\n<option value=\"Suriname\">Suriname</option>\n<option value=\"Svalbard and Jan Mayen Islands\">Svalbard and Jan Mayen Islands</option>\n<option value=\"Swaziland\">Swaziland</option>\n<option value=\"Sweden\">Sweden</option>\n<option value=\"Switzerland\">Switzerland</option>\n<option value=\"Taiwan\">Taiwan</option>\n<option value=\"Tajikistan\">Tajikistan</option>\n<option value=\"Tanzania\">Tanzania</option>\n<option value=\"Thailand\">Thailand</option>\n<option value=\"Togo\">Togo</option>\n<option value=\"Tokelau\">Tokelau</option>\n<option value=\"Tonga\">Tonga</option>\n<option value=\"Trinidad\">Trinidad</option>\n<option value=\"Trinidad and Tobago\">Trinidad and Tobago</option>\n<option value=\"Tunisia\">Tunisia</option>\n<option value=\"Turkey\">Turkey</option>\n<option value=\"Turkmenistan\">" +
"\n<option value=\"New Zealand\">New Zealand</option>\n<option value=\"Nicaragua\">Nicaragua</option>\n<option value=\"Niger\">Niger</option>\n<option value=\"Nigeria\">Nigeria</option>\n<option value=\"Niue\">Niue</option>\n<option value=\"Norfolk Island\">Norfolk Island</option>\n<option value=\"Northern Ireland\">Northern Ireland</option>\n<option value=\"Northern Mariana Islands\">Northern Mariana Islands</option>\n<option value=\"Norway\">Norway</option>\n<option value=\"Oman\">Oman</option>\n<option value=\"Pakistan\">Pakistan</option>\n<option value=\"Palau\">Palau</option>\n<option value=\"Panama\">Panama</option>\n<option value=\"Papua New Guinea\">Papua New Guinea</option>\n<option value=\"Paraguay\">Paraguay</option>\n<option value=\"Peru\">Peru</option>\n<option value=\"Philippines\">Philippines</option>\n<option value=\"Pitcairn\">Pitcairn</option>\n<option value=\"Poland\">Poland</option>\n<option value=\"Portugal\">Portugal</option>\n<option value=\"Puerto Rico\">Puerto Rico</option>\n<option value=\"Qatar\">Qatar</option>\n<option value=\"Reunion\">Reunion</option>\n<option value=\"Romania\">Romania</option>\n<option value=\"Russia\">Russia</option>\n<option value=\"Rwanda\">Rwanda</option>\n<option value=\"Saint Kitts and Nevis\">Saint Kitts and Nevis</option>\n<option value=\"Saint Lucia\">Saint Lucia</option>\n<option value=\"Saint Vincent and the Grenadines\">Saint Vincent and the Grenadines</option>\n<option value=\"Samoa (Independent)\">Samoa (Independent)</option>\n<option value=\"San Marino\">San Marino</option>\n<option value=\"Sao Tome and Principe\">Sao Tome and Principe</option>\n<option value=\"Saudi Arabia\">Saudi Arabia</option>\n<option value=\"Scotland\">Scotland</option>\n<option value=\"Senegal\">Senegal</option>\n<option value=\"Serbia and Montenegro\">Serbia and Montenegro</option>\n<option value=\"Seychelles\">Seychelles</option>\n<option value=\"Sierra Leone\">Sierra Leone</option>\n<option value=\"Singapore\">Singapore</option>\n<option value=\"Slovakia\">Slovakia</option>\n<option value=\"Slovenia\">Slovenia</option>\n<option value=\"Solomon Islands\">Solomon Islands</option>\n<option value=\"Somalia\">Somalia</option>\n<option value=\"South Africa\">South Africa</option>\n<option value=\"South Georgia and the South Sandwich Islands\">South Georgia and the South Sandwich Islands</option>\n<option value=\"South Korea\">South Korea</option>\n<option value=\"Spain\">Spain</option>\n<option value=\"Sri Lanka\">Sri Lanka</option>\n<option value=\"St. Helena\">St. Helena</option>\n<option value=\"St. Pierre and Miquelon\">St. Pierre and Miquelon</option>\n<option value=\"Suriname\">Suriname</option>\n<option value=\"Svalbard and Jan Mayen Islands\">Svalbard and Jan Mayen Islands</option>\n<option value=\"Swaziland\">Swaziland</option>\n<option value=\"Sweden\">Sweden</option>\n<option value=\"Switzerland\">Switzerland</option>\n<option value=\"Taiwan\">Taiwan</option>\n<option value=\"Tajikistan\">Tajikistan</option>\n<option value=\"Tanzania\">Tanzania</option>\n<option value=\"Thailand\">Thailand</option>\n<option value=\"Togo\">Togo</option>\n<option value=\"Tokelau\">Tokelau</option>\n<option value=\"Tonga\">Tonga</option>\n<option value=\"Trinidad\">Trinidad</option>\n<option value=\"Trinidad and Tobago\">Trinidad and Tobago</option>\n<option value=\"Tunisia\">Tunisia</option>\n<option value=\"Turkey\">Turkey</option>\n<option value=\"Turkmenistan\">" +
"Turkmenistan</option>\n<option value=\"Turks and Caicos Islands\">Turks and Caicos Islands</option>\n<option value=\"Tuvalu\">Tuvalu</option>\n<option value=\"Uganda\">Uganda</option>\n<option value=\"Ukraine\">Ukraine</option>\n<option value=\"United Arab Emirates\">United Arab Emirates</option>\n<option value=\"United Kingdom\">United Kingdom</option>\n<option value=\"United States\">United States</option>\n<option value=\"United States Minor Outlying Islands\">United States Minor Outlying Islands</option>\n<option value=\"Uruguay\">Uruguay</option>\n<option value=\"Uzbekistan\">Uzbekistan</option>\n<option value=\"Vanuatu\">Vanuatu</option>\n<option value=\"Vatican City State (Holy See)\">Vatican City State (Holy See)</option>\n<option value=\"Venezuela\">Venezuela</option>\n<option value=\"Viet Nam\">Viet Nam</option>\n<option value=\"Virgin Islands (British)\">Virgin Islands (British)</option>\n<option value=\"Virgin Islands (U.S.)\">Virgin Islands (U.S.)</option>\n<option value=\"Wales\">Wales</option>\n<option value=\"Wallis and Futuna Islands\">Wallis and Futuna Islands</option>\n<option value=\"Western Sahara\">Western Sahara</option>\n<option value=\"Yemen\">Yemen</option>\n<option value=\"Zambia\">Zambia</option>\n<option value=\"Zimbabwe\">Zimbabwe</option></select>",
country_select("post", "origin")
)