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
This commit is contained in:
@@ -188,8 +188,7 @@ def create_account(request, post_override=None):
|
||||
up.save()
|
||||
|
||||
d={'name':post_vars['name'],
|
||||
'key':r.activation_key,
|
||||
'site':settings.SITE_NAME}
|
||||
'key':r.activation_key}
|
||||
|
||||
subject = render_to_string('emails/activation_email_subject.txt',d)
|
||||
# Email subject *must not* contain newlines
|
||||
@@ -282,8 +281,7 @@ def reactivation_email(request):
|
||||
reg.register(user)
|
||||
|
||||
d={'name':UserProfile.get(user = user).name,
|
||||
'key':r.activation_key,
|
||||
'site':settings.SITE_NAME}
|
||||
'key':r.activation_key}
|
||||
|
||||
subject = render_to_string('reactivation_email_subject.txt',d)
|
||||
subject = ''.join(subject.splitlines())
|
||||
@@ -336,8 +334,7 @@ def change_email_request(request):
|
||||
return HttpResponse(json.dumps({'success':False,
|
||||
'error':'Old email is the same as the new email.'}))
|
||||
|
||||
d = {'site':settings.SITE_NAME,
|
||||
'key':pec.activation_key,
|
||||
d = {'key':pec.activation_key,
|
||||
'old_email' : user.email,
|
||||
'new_email' : pec.new_email}
|
||||
|
||||
@@ -360,9 +357,8 @@ def confirm_email_change(request, key):
|
||||
return render_to_response("invalid_email_key.html", {})
|
||||
|
||||
user = pec.user
|
||||
d = {'site':settings.SITE_NAME,
|
||||
'old_email' : user.email,
|
||||
'new_email' : pec.new_email}
|
||||
d = {'old_email' : user.email,
|
||||
'new_email' : pec.new_email}
|
||||
|
||||
if len(User.objects.filter(email = pec.new_email)) != 0:
|
||||
return render_to_response("email_exists.html", d)
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# 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.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
@@ -15,6 +15,7 @@
|
||||
from mako.lookup import TemplateLookup
|
||||
import tempfile
|
||||
from django.template import RequestContext
|
||||
from django.conf import settings
|
||||
|
||||
requestcontext = None
|
||||
lookup = {}
|
||||
@@ -44,4 +45,5 @@ class MakoMiddleware(object):
|
||||
def process_request (self, request):
|
||||
global requestcontext
|
||||
requestcontext = RequestContext(request)
|
||||
|
||||
requestcontext['is_secure'] = request.is_secure()
|
||||
requestcontext['site'] = settings.SITE_NAME
|
||||
|
||||
@@ -18,18 +18,21 @@ from django.http import HttpResponse
|
||||
import mitxmako.middleware as middleware
|
||||
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'):
|
||||
context_instance = context_instance or Context(dictionary)
|
||||
def render_to_string(template_name, dictionary, context=None, namespace='main'):
|
||||
context_instance = Context(dictionary)
|
||||
# add dictionary to context_instance
|
||||
context_instance.update(dictionary or {})
|
||||
# collapse context_instance to a single dictionary for mako
|
||||
context_dictionary = {}
|
||||
context_instance['settings'] = settings
|
||||
context_instance['request_context'] = requestcontext
|
||||
for d in mitxmako.middleware.requestcontext:
|
||||
context_dictionary.update(d)
|
||||
for d in context_instance:
|
||||
context_dictionary.update(d)
|
||||
if context:
|
||||
context_dictionary.update(context)
|
||||
# fetch and render template
|
||||
template = middleware.lookup[namespace].get_template(template_name)
|
||||
return template.render(**context_dictionary)
|
||||
|
||||
@@ -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
|
||||
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
|
||||
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,
|
||||
please contact the course staff immediately. Contact information is
|
||||
listed at:
|
||||
|
||||
% if is_secure:
|
||||
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
|
||||
can investigate.
|
||||
|
||||
@@ -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
|
||||
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
|
||||
receive any more email from us. Please do not reply to this e-mail; if
|
||||
|
||||
@@ -1,6 +1,10 @@
|
||||
MITx's prototype offering, 6.002x, is now open. To log in, visit
|
||||
|
||||
% if is_secure:
|
||||
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
|
||||
window.
|
||||
|
||||
Reference in New Issue
Block a user