Use system.getHostname() everywhere
Replace os.environ['HTTP_HOST'] with system.getHostname(), as a
result we do not crash when 'HTTP_HOST' is unset now.
--- a/app/soc/logic/helper/notifications.py Mon Sep 07 20:02:35 2009 +0200
+++ b/app/soc/logic/helper/notifications.py Mon Sep 07 20:06:27 2009 +0200
@@ -22,7 +22,6 @@
]
-import os
import time
from django.template import loader
@@ -34,6 +33,7 @@
from soc.logic import accounts
from soc.logic import dicts
from soc.logic import mail_dispatcher
+from soc.logic import system
from soc.views.helper import redirects
@@ -81,7 +81,7 @@
to_user = user_logic.getForFields(properties, unique=True)
invitation_url = "http://%(host)s%(index)s" % {
- 'host' : os.environ['HTTP_HOST'],
+ 'host' : system.getHostname(),
'index': redirects.getInviteProcessRedirect(entity, None),
}
@@ -164,7 +164,7 @@
url = "http://%(host)s%(redirect)s" % {
'redirect': redirects.getApplicantRedirect(entity,
{'url_name': params['group_url_name']}),
- 'host': os.environ['HTTP_HOST'],
+ 'host': system.getHostname(),
}
message_properties = {
@@ -269,7 +269,7 @@
# create the url to show this notification
notification_url = "http://%(host)s%(index)s" % {
- 'host' : os.environ['HTTP_HOST'],
+ 'host' : system.getHostname(),
'index': redirects.getPublicRedirect(notification_entity,
notification_view.getParams())}
@@ -340,7 +340,7 @@
'name': user_entity.name
},
'site_name': site_name,
- 'site_location': 'http://%s' % os.environ['HTTP_HOST'],
+ 'site_location': 'http://%s' % system.getHostname(),
}
# send out the message using the default welcome template
--- a/app/soc/modules/ghop/tasks/task_update.py Mon Sep 07 20:02:35 2009 +0200
+++ b/app/soc/modules/ghop/tasks/task_update.py Mon Sep 07 20:06:27 2009 +0200
@@ -23,7 +23,6 @@
import logging
-import os
from google.appengine.api.labs import taskqueue
from google.appengine.ext import db
@@ -31,6 +30,7 @@
from django import http
from django.utils.translation import ugettext
+from soc.logic import system
from soc.tasks.helper import error_handler
from soc.views.helper import redirects
@@ -180,7 +180,7 @@
subscriber_start_index:subscriber_start_index+batch_size])
task_url = "http://%(host)s%(task)s" % {
- 'host': os.environ['HTTP_HOST'],
+ 'host': system.getHostname(),
'task': redirects.getPublicRedirect(
task_entity, {'url_name': 'ghop/task'}),
}
--- a/app/soc/tasks/surveys.py Mon Sep 07 20:02:35 2009 +0200
+++ b/app/soc/tasks/surveys.py Mon Sep 07 20:06:27 2009 +0200
@@ -23,13 +23,13 @@
import logging
-import os
from google.appengine.api.labs import taskqueue
from django import http
from soc.tasks.helper import error_handler
+from soc.logic import system
def getDjangoURLPatterns():
@@ -222,7 +222,7 @@
survey_url = "http://%(host)s%(redirect)s" % {
'redirect': survey_redirect,
- 'host': os.environ['HTTP_HOST'],
+ 'host': system.getHostname(),
}
# set the context for the mail template
--- a/app/soc/views/helper/requests.py Mon Sep 07 20:02:35 2009 +0200
+++ b/app/soc/views/helper/requests.py Mon Sep 07 20:06:27 2009 +0200
@@ -22,9 +22,10 @@
]
-import os
import urlparse
+from soc.logic import system
+
def getSingleIndexedParamValue(request, param_name, values=()):
"""Returns a value indexed by a query parameter in the HTTP request.
@@ -119,7 +120,7 @@
# no HTTP referrer, so cannot possibly start with expected prefix
return False
- http_host = 'http://%s/%s' % (os.environ['HTTP_HOST'], url_name)
+ http_host = 'http://%s/%s' % (system.getHostname(), url_name)
if http_from.startswith(http_host):
return True
--- a/app/soc/views/models/org_app.py Mon Sep 07 20:02:35 2009 +0200
+++ b/app/soc/views/models/org_app.py Mon Sep 07 20:06:27 2009 +0200
@@ -22,8 +22,6 @@
]
-import os
-
from django import forms
from django.utils import simplejson
@@ -32,6 +30,7 @@
from soc.logic import dicts
from soc.logic import mail_dispatcher
from soc.logic import models as model_logic
+from soc.logic import system
from soc.logic.models import program as program_logic
from soc.logic.models import org_app as org_app_logic
from soc.views import helper
@@ -239,7 +238,7 @@
# use the accepted template and subject
template = params['accepted_mail_template']
context['subject'] = 'Congratulations!'
- context['HTTP_host'] = 'http://%s' % (os.environ['HTTP_HOST'])
+ context['HTTP_host'] = 'http://%s' % (system.getHostname())
elif status == 'rejected':
# use the rejected template and subject
template = params['rejected_mail_template']
--- a/app/soc/views/models/program.py Mon Sep 07 20:02:35 2009 +0200
+++ b/app/soc/views/models/program.py Mon Sep 07 20:06:27 2009 +0200
@@ -25,8 +25,6 @@
]
-import os
-
from django import forms
from django import http
from django.utils.translation import ugettext
@@ -34,6 +32,7 @@
from soc.logic import allocations
from soc.logic import cleaning
from soc.logic import dicts
+from soc.logic import system
from soc.logic.helper import timeline as timeline_helper
from soc.logic.models import host as host_logic
from soc.logic.models import mentor as mentor_logic
@@ -416,7 +415,7 @@
contents = [content]
return_url = "http://%(host)s%(index)s" % {
- 'host' : os.environ['HTTP_HOST'],
+ 'host' : system.getHostname(),
'index': redirects.getSlotsRedirect(program, params)
}