Commit 686b1bf6 by Piotr Mitros

Moved site, is_secure, etc. into render_to_string shortcut, and fixed bugs in…

Moved site, is_secure, etc. into render_to_string shortcut, and fixed bugs in the shortcut. We should test this pretty well, since this touches a lot of templates
parent eeffa7a6
...@@ -188,8 +188,7 @@ def create_account(request, post_override=None): ...@@ -188,8 +188,7 @@ def create_account(request, post_override=None):
up.save() up.save()
d={'name':post_vars['name'], d={'name':post_vars['name'],
'key':r.activation_key, 'key':r.activation_key}
'site':settings.SITE_NAME}
subject = render_to_string('emails/activation_email_subject.txt',d) subject = render_to_string('emails/activation_email_subject.txt',d)
# Email subject *must not* contain newlines # Email subject *must not* contain newlines
...@@ -282,8 +281,7 @@ def reactivation_email(request): ...@@ -282,8 +281,7 @@ def reactivation_email(request):
reg.register(user) reg.register(user)
d={'name':UserProfile.get(user = user).name, d={'name':UserProfile.get(user = user).name,
'key':r.activation_key, 'key':r.activation_key}
'site':settings.SITE_NAME}
subject = render_to_string('reactivation_email_subject.txt',d) subject = render_to_string('reactivation_email_subject.txt',d)
subject = ''.join(subject.splitlines()) subject = ''.join(subject.splitlines())
...@@ -336,8 +334,7 @@ def change_email_request(request): ...@@ -336,8 +334,7 @@ def change_email_request(request):
return HttpResponse(json.dumps({'success':False, return HttpResponse(json.dumps({'success':False,
'error':'Old email is the same as the new email.'})) 'error':'Old email is the same as the new email.'}))
d = {'site':settings.SITE_NAME, d = {'key':pec.activation_key,
'key':pec.activation_key,
'old_email' : user.email, 'old_email' : user.email,
'new_email' : pec.new_email} 'new_email' : pec.new_email}
...@@ -360,8 +357,7 @@ def confirm_email_change(request, key): ...@@ -360,8 +357,7 @@ def confirm_email_change(request, key):
return render_to_response("invalid_email_key.html", {}) return render_to_response("invalid_email_key.html", {})
user = pec.user user = pec.user
d = {'site':settings.SITE_NAME, d = {'old_email' : user.email,
'old_email' : user.email,
'new_email' : pec.new_email} 'new_email' : pec.new_email}
if len(User.objects.filter(email = pec.new_email)) != 0: if len(User.objects.filter(email = pec.new_email)) != 0:
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
# http://www.apache.org/licenses/LICENSE-2.0 # http://www.apache.org/licenses/LICENSE-2.0
# #
# Unless required by applicable law or agreed to in writing, software # Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, # distribuetd under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
from mako.lookup import TemplateLookup from mako.lookup import TemplateLookup
import tempfile import tempfile
from django.template import RequestContext from django.template import RequestContext
from django.conf import settings
requestcontext = None requestcontext = None
lookup = {} lookup = {}
...@@ -44,4 +45,5 @@ class MakoMiddleware(object): ...@@ -44,4 +45,5 @@ class MakoMiddleware(object):
def process_request (self, request): def process_request (self, request):
global requestcontext global requestcontext
requestcontext = RequestContext(request) requestcontext = RequestContext(request)
requestcontext['is_secure'] = request.is_secure()
requestcontext['site'] = settings.SITE_NAME
...@@ -18,18 +18,21 @@ from django.http import HttpResponse ...@@ -18,18 +18,21 @@ from django.http import HttpResponse
import mitxmako.middleware as middleware import mitxmako.middleware as middleware
from django.conf import settings from django.conf import settings
from mitxmako.middleware import requestcontext import mitxmako.middleware
def render_to_string(template_name, dictionary, context_instance=None, namespace='main'): def render_to_string(template_name, dictionary, context=None, namespace='main'):
context_instance = context_instance or Context(dictionary) context_instance = Context(dictionary)
# add dictionary to context_instance # add dictionary to context_instance
context_instance.update(dictionary or {}) context_instance.update(dictionary or {})
# collapse context_instance to a single dictionary for mako # collapse context_instance to a single dictionary for mako
context_dictionary = {} context_dictionary = {}
context_instance['settings'] = settings context_instance['settings'] = settings
context_instance['request_context'] = requestcontext for d in mitxmako.middleware.requestcontext:
context_dictionary.update(d)
for d in context_instance: for d in context_instance:
context_dictionary.update(d) context_dictionary.update(d)
if context:
context_dictionary.update(context)
# fetch and render template # fetch and render template
template = middleware.lookup[namespace].get_template(template_name) template = middleware.lookup[namespace].get_template(template_name)
return template.render(**context_dictionary) return template.render(**context_dictionary)
......
...@@ -3,7 +3,11 @@ offering of 6.002 using this email address. If it was you, and you'd ...@@ -3,7 +3,11 @@ offering of 6.002 using this email address. If it was you, and you'd
like to activate and use your account, copy and paste this address like to activate and use your account, copy and paste this address
into your web browser's address bar: into your web browser's address bar:
https://${ site }/activate/${ key } % if is_secure:
https://${ site }/activate/${ key }
% else:
http://${ site }/activate/${ key }
% endif
If you didn't request this, you don't need to do anything; you won't If you didn't request this, you don't need to do anything; you won't
receive any more email from us. Please do not reply to this e-mail; if receive any more email from us. Please do not reply to this e-mail; if
......
...@@ -3,7 +3,11 @@ from ${old_email} to ${new_email}. If you did not make this request, ...@@ -3,7 +3,11 @@ from ${old_email} to ${new_email}. If you did not make this request,
please contact the course staff immediately. Contact information is please contact the course staff immediately. Contact information is
listed at: listed at:
% if is_secure:
https://${ site }/t/mitx_help.html https://${ site }/t/mitx_help.html
% else:
http://${ site }/t/mitx_help.html
% endif
We keep a log of old e-mails, so if this request was unintentional, we We keep a log of old e-mails, so if this request was unintentional, we
can investigate. can investigate.
...@@ -2,7 +2,11 @@ We received a request to change the e-mail associated with your MITx ...@@ -2,7 +2,11 @@ We received a request to change the e-mail associated with your MITx
account from ${old_email} to ${new_email}. If this is correct, please account from ${old_email} to ${new_email}. If this is correct, please
confirm your new e-mail address by visiting: confirm your new e-mail address by visiting:
https://${ site }/email_confirm/${ key } % if is_secure:
https://${ site }/email_confirm/${ key }
% else:
http://${ site }/email_confirm/${ key }
% endif
If you didn't request this, you don't need to do anything; you won't If you didn't request this, you don't need to do anything; you won't
receive any more email from us. Please do not reply to this e-mail; if receive any more email from us. Please do not reply to this e-mail; if
......
MITx's prototype offering, 6.002x, is now open. To log in, visit MITx's prototype offering, 6.002x, is now open. To log in, visit
% if is_secure:
https://6002x.mitx.mit.edu https://6002x.mitx.mit.edu
% else:
http://6002x.mitx.mit.edu
% endif
where you will find a login button at the top right-hand corner of the where you will find a login button at the top right-hand corner of the
window. window.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment