2023-10-31 19:22:55 +01:00
|
|
|
from decimal import Decimal
|
|
|
|
from typing import Optional
|
2021-09-29 19:51:55 +02:00
|
|
|
from urllib.parse import urlencode, urljoin, urlunsplit
|
|
|
|
|
|
|
|
from django.conf import settings
|
|
|
|
from django.urls import reverse
|
|
|
|
|
2023-12-01 19:45:11 +01:00
|
|
|
from corporate.models import get_customer_by_realm
|
2023-12-01 12:23:31 +01:00
|
|
|
from zerver.models import Realm, get_realm
|
2021-09-29 19:51:55 +02:00
|
|
|
|
|
|
|
|
|
|
|
def get_support_url(realm: Realm) -> str:
|
|
|
|
support_realm_uri = get_realm(settings.STAFF_SUBDOMAIN).uri
|
|
|
|
support_url = urljoin(
|
|
|
|
support_realm_uri,
|
|
|
|
urlunsplit(("", "", reverse("support"), urlencode({"q": realm.string_id}), "")),
|
|
|
|
)
|
|
|
|
return support_url
|
2023-10-31 19:22:55 +01:00
|
|
|
|
|
|
|
|
|
|
|
def get_discount_for_realm(realm: Realm) -> Optional[Decimal]:
|
|
|
|
customer = get_customer_by_realm(realm)
|
|
|
|
if customer is not None:
|
|
|
|
return customer.default_discount
|
|
|
|
return None
|