py3: Switch almost all shebang lines to use `python3`.
This causes `upgrade-zulip-from-git`, as well as a no-option run of
`tools/build-release-tarball`, to produce a Zulip install running
Python 3, rather than Python 2. In particular this means that the
virtualenv we create, in which all application code runs, is Python 3.
One shebang line, on `zulip-ec2-configure-interfaces`, explicitly
keeps Python 2, and at least one external ops script, `wal-e`, also
still runs on Python 2. See discussion on the respective previous
commits that made those explicit. There may also be some other
third-party scripts we use, outside of this source tree and running
outside our virtualenv, that still run on Python 2.
2017-08-02 23:15:16 +02:00
|
|
|
#!/usr/bin/env python3
|
2017-06-08 02:47:44 +02:00
|
|
|
from __future__ import absolute_import
|
|
|
|
from __future__ import print_function
|
2017-06-10 05:23:19 +02:00
|
|
|
|
|
|
|
from django.conf import settings
|
2017-06-08 02:47:44 +02:00
|
|
|
from django.http import HttpRequest, HttpResponse
|
|
|
|
from django.shortcuts import render
|
|
|
|
from django.template import loader, TemplateDoesNotExist
|
|
|
|
|
2017-06-10 06:19:32 +02:00
|
|
|
from zerver.lib.send_email import build_email
|
2017-06-10 05:23:19 +02:00
|
|
|
from zerver.models import get_realm
|
|
|
|
|
|
|
|
import os
|
|
|
|
from typing import List, Dict, Any
|
|
|
|
|
2017-06-08 02:47:44 +02:00
|
|
|
ZULIP_PATH = os.path.join(os.path.dirname(os.path.abspath(__file__)), '../../')
|
|
|
|
|
|
|
|
def email_page(request):
|
|
|
|
# type: (HttpRequest) -> HttpResponse
|
|
|
|
# write fake data for all variables
|
2017-06-10 05:23:19 +02:00
|
|
|
realm = get_realm('zulip')
|
2017-06-08 02:47:44 +02:00
|
|
|
test_context = {
|
|
|
|
'user_profile': {
|
2017-06-10 05:23:19 +02:00
|
|
|
'full_name': 'Wile E. Coyote',
|
|
|
|
'email': 'coyote@acme.com',
|
2017-06-08 02:47:44 +02:00
|
|
|
'realm': {
|
2017-06-10 05:23:19 +02:00
|
|
|
'uri': realm.uri,
|
|
|
|
'name': 'Acme Corporation',
|
2017-06-08 02:47:44 +02:00
|
|
|
},
|
|
|
|
},
|
|
|
|
'realm': {
|
2017-06-10 05:23:19 +02:00
|
|
|
'uri': realm.uri,
|
|
|
|
'name': 'Acme Corporation',
|
2017-06-08 02:47:44 +02:00
|
|
|
},
|
|
|
|
'device_info': {
|
|
|
|
'login_time': "12/12/12, 12:12:12",
|
|
|
|
'device_browser': "Firefox",
|
|
|
|
'device_os': "ZulipOS",
|
2017-06-10 05:23:19 +02:00
|
|
|
'device_ip': '3.14.15.92',
|
2017-06-08 02:47:44 +02:00
|
|
|
},
|
|
|
|
'referrer': {
|
2017-06-10 05:23:19 +02:00
|
|
|
'full_name': 'Road Runner',
|
|
|
|
'email': 'runner@acme.com',
|
2017-06-08 02:47:44 +02:00
|
|
|
},
|
|
|
|
'user': {
|
2017-06-10 05:23:19 +02:00
|
|
|
'full_name': 'Wile E. Coyote',
|
|
|
|
'email': 'coyote@acme.com',
|
2017-06-08 02:47:44 +02:00
|
|
|
},
|
2017-06-10 05:23:19 +02:00
|
|
|
'referrer_name': 'Road Runner',
|
|
|
|
'referrer_email': 'runner@acme.com',
|
2017-06-14 17:43:33 +02:00
|
|
|
'referrer_realm_name': 'Acme Corporation',
|
2017-06-10 05:23:19 +02:00
|
|
|
'realm_uri': realm.uri,
|
2017-08-28 23:01:18 +02:00
|
|
|
'root_domain_uri': settings.ROOT_DOMAIN_URI,
|
2017-06-10 05:23:19 +02:00
|
|
|
'old_email': 'old_address@acme.com',
|
|
|
|
'new_email': 'new_address@acme.com',
|
2017-08-18 05:33:06 +02:00
|
|
|
'is_realm_admin': True,
|
2017-08-28 23:01:18 +02:00
|
|
|
'activate_url': '%s/accounts/do_confirm/5348720e4af7d2e8f296cbbd04d439489917ddc0' % (settings.ROOT_DOMAIN_URI,),
|
|
|
|
'unsubscribe_link': '%s/accounts/unsubscribe/<type>/cf88931365ef1b0f12eae8d488bbc7af3563d7f0' % (settings.ROOT_DOMAIN_URI,),
|
|
|
|
'organization_setup_advice_link': '%s/help/getting-your-organization-started-with-zulip' % (settings.ROOT_DOMAIN_URI,),
|
2017-06-08 02:47:44 +02:00
|
|
|
}
|
|
|
|
|
2017-06-10 06:53:16 +02:00
|
|
|
templates = [
|
2017-06-11 00:46:16 +02:00
|
|
|
'confirm_registration', 'invitation', 'invitation_reminder', 'followup_day1',
|
|
|
|
'followup_day2', 'missed_message', 'digest', 'find_team', 'password_reset',
|
|
|
|
'confirm_new_email', 'notify_change_in_email', 'notify_new_login']
|
2017-06-10 06:53:16 +02:00
|
|
|
|
|
|
|
for f in os.listdir(os.path.join(ZULIP_PATH, 'templates', 'zerver', 'emails')):
|
|
|
|
template = f.split('.')[0]
|
|
|
|
if template not in templates:
|
|
|
|
templates.append(template)
|
|
|
|
|
2017-06-08 02:47:44 +02:00
|
|
|
# Do not render these templates,
|
|
|
|
# as they are currently unsupported
|
|
|
|
ignore = [
|
2017-07-08 22:21:53 +02:00
|
|
|
'email_base_default',
|
|
|
|
'email_base_messages',
|
2017-06-08 02:47:44 +02:00
|
|
|
'digest',
|
|
|
|
'missed_message',
|
|
|
|
'password_reset',
|
|
|
|
]
|
|
|
|
|
|
|
|
data = [] # type: List[Dict[str, Any]]
|
2017-06-10 06:53:16 +02:00
|
|
|
for template in templates:
|
|
|
|
if template not in ignore:
|
2017-06-08 02:47:44 +02:00
|
|
|
try:
|
2017-07-11 05:01:32 +02:00
|
|
|
email = build_email('zerver/emails/' + template, to_email='recipient@acme.com',
|
|
|
|
context=test_context)
|
2017-06-10 06:19:32 +02:00
|
|
|
email_data = {
|
|
|
|
'template': template,
|
|
|
|
'subject': email.subject,
|
|
|
|
'body': email.body,
|
|
|
|
'html_message': email.alternatives[0][0] if len(email.alternatives) > 0 else 'Missing HTML message'}
|
|
|
|
data.append(email_data)
|
2017-06-10 01:28:01 +02:00
|
|
|
except Exception as e: # nocoverage
|
2017-06-08 02:47:44 +02:00
|
|
|
data.append({'template': template, 'failed': True, 'reason': e})
|
|
|
|
return render(request, 'zerver/test_emails.html', {'emails': data})
|