# pylint: disable=no-member,no-self-argument,unused-argument,R0801
"""The branding settings of the organization that operates a Smarter platform."""
from typing import Optional
from urllib.parse import urljoin
from pydantic import AnyUrl, BaseModel, EmailStr, Field, HttpUrl, model_validator
from smarter.common.conf.const import THE_EMPTY_SET
from smarter.common.conf.util import (
before_field_validator,
field_default,
input_value,
with_derived_default,
)
from smarter.common.exceptions import SmarterConfigurationError
from smarter.lib.django.validators import SmarterValidator
[docs]
class BrandingSettings(BaseModel):
"""The platform operator's branding: name, address, contacts, links and logo."""
platform_branding_app_name: str = Field(
"Smarter",
description="The application's name, which prefixes the names of the platform's Django apps in the admin and the web console.",
examples=["Acme AI"],
title="Branding App Name",
)
"""
The application's name, which prefixes the names of the platform's Django apps in the admin and the web console: ``SMARTER_PLATFORM_BRANDING_APP_NAME``.
:type: str
:default: ``"Smarter"``
:raises SmarterConfigurationError: If the value is not a string.
"""
platform_branding_product_name: str = Field(
"The Smarter Project",
description="The product's name, shown in the web console, emails and documentation.",
examples=["Acme AI Platform"],
title="Branding Product Name",
)
"""
The product's name, shown in the web console, emails and documentation: ``SMARTER_PLATFORM_BRANDING_PRODUCT_NAME``.
:type: str
:default: ``"The Smarter Project"``
:raises SmarterConfigurationError: If the value is not a string.
"""
platform_branding_product_description: str = Field(
"An open source, no-code AI authoring platform designed for instructional use.",
description="A one-sentence description of the product, shown in the web console and in page metadata.",
examples=["A no-code AI platform for Acme's teams."],
title="Branding Product Description",
)
"""
A one-sentence description of the product, shown in the web console and in page metadata: ``SMARTER_PLATFORM_BRANDING_PRODUCT_DESCRIPTION``.
:type: str
:default: ``"An open source, no-code AI authoring platform designed for instructional use."``
:raises SmarterConfigurationError: If the value is not a string.
"""
platform_branding_cdn_url: HttpUrl = Field(
HttpUrl("https://cdn.smarter.sh"),
description="The CDN of the product's own static assets, e.g. its logo and Open Graph image.",
examples=["https://cdn.example.com"],
title="Branding CDN URL",
)
"""
The CDN of the product's own static assets, e.g. its logo and Open Graph image: ``SMARTER_PLATFORM_BRANDING_CDN_URL``.
:type: HttpUrl
:default: ``"https://cdn.smarter.sh"``
"""
platform_branding_docs_url: HttpUrl = Field(
HttpUrl("https://docs.smarter.sh"),
description="The product's documentation site, linked from the web console and the api.",
examples=["https://docs.example.com"],
title="Branding Documentation URL",
)
"""
The product's documentation site, linked from the web console and the api: ``SMARTER_PLATFORM_BRANDING_DOCS_URL``.
:type: HttpUrl
:default: ``"https://docs.smarter.sh"``
"""
platform_branding_blog_url: HttpUrl = Field(
HttpUrl("https://blog.smarter.sh"),
description="The product's blog, e.g. its release announcements.",
examples=["https://blog.example.com"],
title="Branding Blog URL",
)
"""
The product's blog, e.g. its release announcements: ``SMARTER_PLATFORM_BRANDING_BLOG_URL``.
:type: HttpUrl
:default: ``"https://blog.smarter.sh"``
"""
[docs]
@before_field_validator("platform_branding_blog_url")
def validate_platform_branding_blog_url(cls, v: Optional[HttpUrl]) -> HttpUrl:
"""
Validate ``platform_branding_blog_url``: an empty value is the default.
:param v: The value.
:returns: The value, or the default.
"""
if v is None or v in THE_EMPTY_SET:
return field_default(cls, "platform_branding_blog_url")
return v
platform_branding_corporate_name: str = Field(
"Lawrence P. McDaniel",
description="The corporate name used for branding purposes throughout the platform.",
examples=["Acme Corporation"],
title="Branding Corporate Name",
)
"""
The corporate name used for branding purposes throughout the platform.
This setting specifies the name of the organization or company that owns
or operates the platform. It is used in various branding contexts,
such as email templates, user interfaces, and documentation.
:type: str
:default: ``"Lawrence P. McDaniel"``
:raises SmarterConfigurationError: If the value is not a string.
"""
platform_branding_support_phone_number: str = Field(
"(###) 555-1212",
description="The support phone number used for branding purposes throughout the platform.",
examples=["+1-800-555-1234"],
title="Branding Support Phone Number",
)
"""
The support phone number used for branding purposes throughout the platform.
This setting specifies the phone number that users can call for support
or assistance related to the platform. It is used in various branding contexts,
such as email templates, user interfaces, and documentation.
:type: str
:default: ``"(###) 555-1212"``
:raises SmarterConfigurationError: If the value is not a string.
"""
platform_branding_support_email: EmailStr = Field(
"lpm0073@gmail.com",
description="The support email address used for branding purposes throughout the platform.",
title="Branding Support Email",
)
"""
The support email address used for branding purposes throughout the platform.
This setting specifies the email address that users can contact for support
or assistance related to the platform. It is used in various branding contexts,
such as email templates, user interfaces, and documentation.
:type: EmailStr
:default: ``"lpm0073@gmail.com"``
:raises SmarterConfigurationError: If the value is not a EmailStr.
"""
platform_branding_address1: str = Field(
"123 Main St, Anytown, USA",
description="The corporate address used for branding purposes throughout the platform.",
examples=["123 Main St, Anytown, USA"],
title="Branding Address",
)
"""
The corporate address used for branding purposes throughout the platform.
This setting specifies the physical address of the organization or company that owns
or operates the platform. It is used in various branding contexts,
such as email templates, user interfaces, and documentation.
:type: str
:default: ``"123 Main St, Anytown, USA"``
:raises SmarterConfigurationError: If the value is not a string.
"""
[docs]
@before_field_validator("platform_branding_address1")
def validate_branding_address(cls, v: Optional[str]) -> str:
"""Validates the `branding_address1` field.
Args:
v (Optional[str]): The branding address value to validate.
Returns:
str: The validated branding address.
"""
if v in THE_EMPTY_SET:
return field_default(cls, "platform_branding_address1")
if not isinstance(v, str):
raise SmarterConfigurationError(f"branding_address1 of type {type(v)} is not a str.")
return v
platform_branding_address2: Optional[str] = Field(
"Suite 100",
description="The second line of the corporate address used for branding purposes throughout the platform.",
examples=["Suite 100"],
title="Branding Address Line 2",
)
"""
The second line of the corporate address used for branding purposes throughout the platform.
This setting specifies the second line of the physical address of the organization or company that owns
or operates the platform. It is used in various branding contexts,
such as email templates, user interfaces, and documentation.
:type: Optional[str]
:default: ``"Suite 100"``
:raises SmarterConfigurationError: If the value is not a string.
"""
platform_branding_city: str = Field(
"Anytown",
description="The corporate city used for branding purposes throughout the platform.",
examples=["Anytown"],
title="Branding City",
)
"""
The corporate city used for branding purposes throughout the platform.
This setting specifies the city of the physical address of the organization or company that owns
or operates the platform. It is used in various branding contexts,
such as email templates, user interfaces, and documentation.
:type: str
:default: ``"Anytown"``
:raises SmarterConfigurationError: If the value is not a string.
"""
platform_branding_state: str = Field(
"CA",
description="The corporate state used for branding purposes throughout the platform.",
examples=["CA"],
title="Branding State",
)
"""
The corporate state used for branding purposes throughout the platform.
This setting specifies the state of the physical address of the organization or company that owns
or operates the platform. It is used in various branding contexts,
such as email templates, user interfaces, and documentation.
:type: str
:default: ``"CA"``
:raises SmarterConfigurationError: If the value is not a string.
"""
platform_branding_postal_code: str = Field(
"12345",
description="The corporate postal code used for branding purposes throughout the platform.",
examples=["12345"],
title="Branding Postal Code",
)
"""
The corporate postal code used for branding purposes throughout the platform.
This setting specifies the postal code of the physical address of the organization or company that owns
or operates the platform. It is used in various branding contexts,
such as email templates, user interfaces, and documentation.
:type: str
:default: ``"12345"``
:raises SmarterConfigurationError: If the value is not a string.
"""
[docs]
@before_field_validator("platform_branding_postal_code")
def validate_platform_branding_postal_code(cls, v: Optional[str]) -> str:
"""Validates the `branding_postal_code` field.
Args:
v (Optional[str]): The branding postal code value to validate.
Returns:
str: The validated branding postal code.
"""
if v in THE_EMPTY_SET:
return field_default(cls, "platform_branding_postal_code")
if not isinstance(v, str):
raise SmarterConfigurationError(f"branding_postal_code of type {type(v)} is not a str.")
return v
platform_branding_country: str = Field(
"USA",
description="The corporate country used for branding purposes throughout the platform.",
examples=["USA"],
title="Branding Country",
)
"""
The corporate country used for branding purposes throughout the platform.
This setting specifies the country of the physical address of the organization or company that owns
or operates the platform. It is used in various branding contexts,
such as email templates, user interfaces, and documentation.
:type: str
:default: ``"USA"``
:raises SmarterConfigurationError: If the value is not a string.
"""
platform_branding_currency: str = Field(
"USD",
description="The currency used for branding purposes throughout the platform.",
examples=["USD"],
title="Branding Currency",
)
"""
The currency used for branding purposes throughout the platform.
This setting specifies the currency that is used in various branding contexts,
such as email templates, user interfaces, and documentation. It can be used to
indicate the currency in which prices, billing, or financial information
is presented to users.
:type: str
:default: ``"USD"``
:raises SmarterConfigurationError: If the value is not a string.
"""
platform_branding_timezone: str = Field(
"America/Denver",
description="The timezone used for branding purposes throughout the platform.",
examples=["America/New_York"],
title="Branding Timezone",
)
"""
The timezone used for branding purposes throughout the platform.
This setting specifies the timezone that is used in various branding contexts,
such as email templates, user interfaces, and documentation. It can be used to
indicate the timezone in which dates and times are presented to users.
:type: str
:default: ``"America/Denver"``
:raises SmarterConfigurationError: If the value is not a string.
"""
platform_branding_contact_url: Optional[HttpUrl] = Field(
HttpUrl("https://lawrencemcdaniel.com/"),
description="The contact URL used for branding purposes throughout the platform.",
examples=["https://www.example.com/contact"],
title="Branding Contact URL",
)
"""
The contact URL used for branding purposes throughout the platform.
This setting specifies the URL that users can visit to contact
the organization or company that owns or operates the platform.
It is used in various branding contexts, such as email templates,
user interfaces, and documentation.
:type: str
:default: ``"https://lawrencemcdaniel.com/"``
:raises SmarterConfigurationError: If the value is not a string.
"""
platform_branding_primary_contact: str = Field(
"Lawrence McDaniel",
description="The name of the person who is the technical point of contact for this platform.",
examples=["Lawrence McDaniel"],
title="Branding Primary Contact",
)
"""
The name of the person who is the technical point of contact for this platform.
This setting names the person who hosts the platform and answers its users' questions.
The welcome email is written from this person, and signed with this name.
:type: str
:default: ``"Lawrence McDaniel"``
:raises SmarterConfigurationError: If the value is not a string.
"""
platform_branding_support_hours: str = Field(
"MON-FRI 9:00 AM - 5:00 PM GMT-6 (CST)",
description="The support hours used for branding purposes throughout the platform.",
examples=["Mon-Fri 9am-5pm EST"],
title="Branding Support Hours",
)
"""
The support hours used for branding purposes throughout the platform.
This setting specifies the hours during which support is available
for users of the platform. It is used in various branding contexts,
such as email templates, user interfaces, and documentation.
:type: str
:default: ``"MON-FRI 9:00 AM - 5:00 PM GMT-6 (CST)"``
:raises SmarterConfigurationError: If the value is not a string.
"""
platform_branding_url_facebook: Optional[HttpUrl] = Field(
HttpUrl("https://facebook.com"),
description="The Facebook URL used for branding purposes throughout the platform.",
examples=["https://www.facebook.com/example"],
title="Branding URL Facebook",
)
"""
The Facebook URL used for branding purposes throughout the platform.
This setting specifies the Facebook page URL of the organization or company that owns
or operates the platform. It is used in various branding contexts,
such as email templates, user interfaces, and documentation.
:type: Optional[HttpUrl]
:default: ``"https://facebook.com"``
:raises SmarterConfigurationError: If the value is not a valid HttpUrl.
"""
platform_branding_url_twitter: Optional[HttpUrl] = Field(
HttpUrl("https://x.com/fullstackwlarry"),
description="The Twitter URL used for branding purposes throughout the platform.",
examples=["https://www.twitter.com/example"],
title="Branding URL Twitter",
)
"""
The Twitter URL used for branding purposes throughout the platform.
This setting specifies the Twitter profile URL of the organization or company that owns
or operates the platform. It is used in various branding contexts,
such as email templates, user interfaces, and documentation.
:type: Optional[HttpUrl]
:default: ``"https://x.com/fullstackwlarry"``
:raises SmarterConfigurationError: If the value is not a valid HttpUrl.
"""
platform_branding_url_linkedin: Optional[HttpUrl] = Field(
HttpUrl("https://www.linkedin.com/in/lawrencemcdaniel/"),
description="The LinkedIn URL used for branding purposes throughout the platform.",
examples=["https://www.linkedin.com/company/example"],
title="Branding URL LinkedIn",
)
"""
The LinkedIn URL used for branding purposes throughout the platform.
This setting specifies the LinkedIn profile URL of the organization or company that owns
or operates the platform. It is used in various branding contexts,
such as email templates, user interfaces, and documentation.
:type: Optional[HttpUrl]
:default: ``"https://www.linkedin.com/in/lawrencemcdaniel/"``
:raises SmarterConfigurationError: If the value is not a valid HttpUrl.
"""
platform_branding_url_slack: Optional[HttpUrl] = Field(
HttpUrl("https://join.slack.com/t/thesmarterproject/shared_invite/zt-4f0t6v46q-e2c5Of4hS4fBr_XwfQARCw"),
description="The invite link of the Slack workspace that the platform's emails invite users to.",
examples=["https://join.slack.com/t/example/shared_invite/zt-example"],
title="Branding URL Slack",
)
"""
The invite link of the Slack workspace that the platform's emails invite users to.
The welcome email links to it, and the Slack invitation email, which a Celery Beat task sends
two days after the welcome email, is about it. The default is the invite link of The Smarter
Project's Slack workspace.
:type: Optional[HttpUrl]
:default: ``"https://join.slack.com/t/thesmarterproject/shared_invite/zt-4f0t6v46q-e2c5Of4hS4fBr_XwfQARCw"``
:raises SmarterConfigurationError: If the value is not a valid HttpUrl.
"""
platform_branding_logo: Optional[AnyUrl] = Field(
None,
description="The URL to the platform's logo image.",
examples=["https://cdn.example.com/logo.png"],
title="Platform Logo URL",
)
"""
The URL to the platform's logo image.
This setting specifies the web address of the logo image used in the platform's user interface.
It should be a valid URL pointing to an external image resource accessible by the frontend.
:type: Optional[AnyUrl]
:default: ``/images/logo/smarter-crop.png`` on :attr:`platform_branding_cdn_url`. See :meth:`derive_branding_defaults`.
:raises SmarterConfigurationError: If the value is not a valid URL string.
"""
platform_branding_marketing_site_url: Optional[HttpUrl] = Field(
None,
description="The URL to the platform's marketing site.",
examples=["https://www.example.com"],
title="Marketing Site URL",
)
"""
The URL to the platform's marketing site.
This setting specifies the web address of the marketing site associated
with the platform. It should be a valid URL pointing to an external website.
:type: Optional[httpHttpUrl]
:default: ``https://`` the root domain, e.g. ``https://example.com``. See :meth:`derive_branding_defaults`.
:raises SmarterConfigurationError: If the value is not a valid URL string.
"""
[docs]
@model_validator(mode="before")
@classmethod
def derive_branding_defaults(cls, data: object) -> object:
"""
Derive the logo and the marketing site's url, unless they are set.
The logo is ``/images/logo/smarter-crop.png`` on the CDN, and the marketing site is ``https://``
the root domain, which :class:`~smarter.common.conf.settings.platform.PlatformSettings` holds.
:param data: The values to validate: the constructor's and the environment's.
:returns: The values, with the derived defaults added.
"""
cdn_url = input_value(cls, data, "platform_branding_cdn_url")
logo = urljoin(str(cdn_url), "/images/logo/smarter-crop.png")
data = with_derived_default(data, "platform_branding_logo", logo)
if "platform_root_domain" not in cls.model_fields:
return data
root_domain = input_value(cls, data, "platform_root_domain")
marketing_site_url = f"https://{root_domain}"
return with_derived_default(data, "platform_branding_marketing_site_url", marketing_site_url)
__all__ = ["BrandingSettings"]