2020-09-12 04:18:53 +02:00
|
|
|
from typing import Optional
|
|
|
|
|
2020-08-07 01:09:47 +02:00
|
|
|
import orjson
|
2020-01-29 20:41:23 +01:00
|
|
|
from django.conf import settings
|
|
|
|
from django.http import HttpRequest, HttpResponse, HttpResponseRedirect
|
2020-05-08 06:37:58 +02:00
|
|
|
from django.template.response import TemplateResponse
|
2020-01-29 20:41:23 +01:00
|
|
|
|
2020-06-11 00:54:34 +02:00
|
|
|
from version import LATEST_DESKTOP_VERSION
|
2020-05-08 06:37:58 +02:00
|
|
|
from zerver.context_processors import get_realm_from_request, latest_info_context
|
|
|
|
from zerver.decorator import add_google_analytics, redirect_to_login
|
2020-01-29 20:41:23 +01:00
|
|
|
from zerver.models import Realm
|
2020-06-11 00:54:34 +02:00
|
|
|
|
2020-01-29 20:41:23 +01:00
|
|
|
|
2020-05-08 06:37:58 +02:00
|
|
|
@add_google_analytics
|
2020-09-12 04:18:53 +02:00
|
|
|
def apps_view(request: HttpRequest, platform: Optional[str] = None) -> HttpResponse:
|
2020-01-29 20:41:23 +01:00
|
|
|
if settings.ZILENCER_ENABLED:
|
2020-05-08 06:37:58 +02:00
|
|
|
return TemplateResponse(
|
|
|
|
request,
|
|
|
|
'zerver/apps.html',
|
|
|
|
context={
|
|
|
|
"page_params": {
|
|
|
|
'electron_app_version': LATEST_DESKTOP_VERSION,
|
python: Use trailing commas consistently.
Automatically generated by the following script, based on the output
of lint with flake8-comma:
import re
import sys
last_filename = None
last_row = None
lines = []
for msg in sys.stdin:
m = re.match(
r"\x1b\[35mflake8 \|\x1b\[0m \x1b\[1;31m(.+):(\d+):(\d+): (\w+)", msg
)
if m:
filename, row_str, col_str, err = m.groups()
row, col = int(row_str), int(col_str)
if filename == last_filename:
assert last_row != row
else:
if last_filename is not None:
with open(last_filename, "w") as f:
f.writelines(lines)
with open(filename) as f:
lines = f.readlines()
last_filename = filename
last_row = row
line = lines[row - 1]
if err in ["C812", "C815"]:
lines[row - 1] = line[: col - 1] + "," + line[col - 1 :]
elif err in ["C819"]:
assert line[col - 2] == ","
lines[row - 1] = line[: col - 2] + line[col - 1 :].lstrip(" ")
if last_filename is not None:
with open(last_filename, "w") as f:
f.writelines(lines)
Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2020-04-10 05:23:40 +02:00
|
|
|
},
|
|
|
|
},
|
2020-05-08 06:37:58 +02:00
|
|
|
)
|
2020-06-08 23:04:39 +02:00
|
|
|
return HttpResponseRedirect('https://zulip.com/apps/', status=301)
|
2020-01-29 20:41:23 +01:00
|
|
|
|
2020-05-08 06:37:58 +02:00
|
|
|
@add_google_analytics
|
2020-01-29 20:41:23 +01:00
|
|
|
def plans_view(request: HttpRequest) -> HttpResponse:
|
|
|
|
realm = get_realm_from_request(request)
|
|
|
|
realm_plan_type = 0
|
2020-05-14 18:21:23 +02:00
|
|
|
free_trial_days = settings.FREE_TRIAL_DAYS
|
2020-06-09 12:24:32 +02:00
|
|
|
sponsorship_pending = False
|
|
|
|
|
2020-01-29 20:41:23 +01:00
|
|
|
if realm is not None:
|
|
|
|
realm_plan_type = realm.plan_type
|
|
|
|
if realm.plan_type == Realm.SELF_HOSTED and settings.PRODUCTION:
|
2020-06-08 23:04:39 +02:00
|
|
|
return HttpResponseRedirect('https://zulip.com/plans')
|
2020-01-29 20:41:23 +01:00
|
|
|
if not request.user.is_authenticated:
|
|
|
|
return redirect_to_login(next="plans")
|
2020-07-15 22:18:32 +02:00
|
|
|
if request.user.is_guest:
|
|
|
|
return TemplateResponse(request, "404.html", status=404)
|
2020-06-09 12:24:32 +02:00
|
|
|
if settings.CORPORATE_ENABLED:
|
|
|
|
from corporate.models import get_customer_by_realm
|
|
|
|
customer = get_customer_by_realm(realm)
|
|
|
|
if customer is not None:
|
|
|
|
sponsorship_pending = customer.sponsorship_pending
|
|
|
|
|
2020-05-08 06:37:58 +02:00
|
|
|
return TemplateResponse(
|
|
|
|
request,
|
|
|
|
"zerver/plans.html",
|
2020-06-09 12:24:32 +02:00
|
|
|
context={"realm_plan_type": realm_plan_type, 'free_trial_days': free_trial_days, 'sponsorship_pending': sponsorship_pending},
|
2020-05-08 06:37:58 +02:00
|
|
|
)
|
2020-01-29 20:41:23 +01:00
|
|
|
|
2020-05-08 06:37:58 +02:00
|
|
|
@add_google_analytics
|
2020-01-29 20:41:23 +01:00
|
|
|
def team_view(request: HttpRequest) -> HttpResponse:
|
2020-04-07 19:27:07 +02:00
|
|
|
if not settings.ZILENCER_ENABLED:
|
2020-06-08 23:04:39 +02:00
|
|
|
return HttpResponseRedirect('https://zulip.com/team/', status=301)
|
2020-04-07 19:27:07 +02:00
|
|
|
|
|
|
|
try:
|
2020-08-07 01:09:47 +02:00
|
|
|
with open(settings.CONTRIBUTOR_DATA_FILE_PATH, "rb") as f:
|
|
|
|
data = orjson.loads(f.read())
|
2020-04-07 19:27:07 +02:00
|
|
|
except FileNotFoundError:
|
2020-07-23 13:52:05 +02:00
|
|
|
data = {'contributors': {}, 'date': "Never ran."}
|
2020-01-29 20:41:23 +01:00
|
|
|
|
2020-05-08 06:37:58 +02:00
|
|
|
return TemplateResponse(
|
2020-01-29 20:41:23 +01:00
|
|
|
request,
|
|
|
|
'zerver/team.html',
|
|
|
|
context={
|
|
|
|
'page_params': {
|
2020-07-23 13:52:05 +02:00
|
|
|
'contributors': data['contributors'],
|
2020-01-29 20:41:23 +01:00
|
|
|
},
|
|
|
|
'date': data['date'],
|
|
|
|
},
|
|
|
|
)
|
2020-01-29 00:05:06 +01:00
|
|
|
|
|
|
|
def get_isolated_page(request: HttpRequest) -> bool:
|
|
|
|
'''Accept a GET param `?nav=no` to render an isolated, navless page.'''
|
|
|
|
return request.GET.get('nav') == 'no'
|
|
|
|
|
2020-05-08 06:37:58 +02:00
|
|
|
@add_google_analytics
|
|
|
|
def landing_view(request: HttpRequest, template_name: str) -> HttpResponse:
|
|
|
|
return TemplateResponse(request, template_name)
|
|
|
|
|
|
|
|
@add_google_analytics
|
|
|
|
def hello_view(request: HttpRequest) -> HttpResponse:
|
|
|
|
return TemplateResponse(request, 'zerver/hello.html', latest_info_context())
|
|
|
|
|
|
|
|
@add_google_analytics
|
2020-01-29 00:05:06 +01:00
|
|
|
def terms_view(request: HttpRequest) -> HttpResponse:
|
2020-05-08 06:37:58 +02:00
|
|
|
return TemplateResponse(
|
|
|
|
request, 'zerver/terms.html',
|
|
|
|
context={'isolated_page': get_isolated_page(request)},
|
|
|
|
)
|
2020-01-29 00:05:06 +01:00
|
|
|
|
2020-05-08 06:37:58 +02:00
|
|
|
@add_google_analytics
|
2020-01-29 00:05:06 +01:00
|
|
|
def privacy_view(request: HttpRequest) -> HttpResponse:
|
2020-05-08 06:37:58 +02:00
|
|
|
return TemplateResponse(
|
|
|
|
request, 'zerver/privacy.html',
|
|
|
|
context={'isolated_page': get_isolated_page(request)},
|
|
|
|
)
|