ctfy.sdk.resources.site
client.site — the operator's site pages (#3414): their content and
the Contact form.
1"""``client.site`` — the operator's site pages (#3414): their content and 2the Contact form.""" 3 4from __future__ import annotations 5 6from typing import Literal 7 8from ctfy.core.site import ContactTopic, SitePageSlug 9from ctfy.sdk._helpers import _raise_for_status 10from ctfy.sdk.base import BaseHttpClient 11from ctfy.server.models.site import ( 12 ContactMessageCreated, 13 SitePageResponse, 14 SiteResponse, 15) 16 17 18class SiteResource: 19 """What the About / Privacy / Terms / Contact pages draw from. 20 21 Every call here is ``404 site_pages_off`` while the deployment has not 22 switched the pages on, unless the caller is a platform admin, who reads 23 them as a preview (``SiteResponse.preview``). 24 """ 25 26 def __init__(self, http: BaseHttpClient) -> None: 27 self._http = http 28 29 def get(self) -> SiteResponse: 30 """The operator's addresses, partners, citation and service terms.""" 31 resp = self._http.request("GET", "/site") 32 _raise_for_status(resp) 33 return SiteResponse.model_validate(resp.json()) 34 35 def page(self, slug: SitePageSlug) -> SitePageResponse: 36 """One page's text, ``{locale: markdown}``.""" 37 resp = self._http.request("GET", f"/site/pages/{slug}") 38 _raise_for_status(resp) 39 return SitePageResponse.model_validate(resp.json()) 40 41 def contact( 42 self, 43 *, 44 email: str, 45 body: str, 46 topic: ContactTopic = "general", 47 name: str = "", 48 organization: str = "", 49 locale: Literal["en", "zh-CN"] = "en", 50 ) -> ContactMessageCreated: 51 """Leave a message for the operators; ``email`` is where they reply. 52 53 Rate-limited per caller. The acknowledgement never says whether the 54 message was stored. 55 """ 56 resp = self._http.request( 57 "POST", 58 "/site/contact", 59 json={ 60 "topic": topic, 61 "name": name, 62 "email": email, 63 "organization": organization, 64 "body": body, 65 "locale": locale, 66 }, 67 ) 68 _raise_for_status(resp) 69 return ContactMessageCreated.model_validate(resp.json())
class
SiteResource:
19class SiteResource: 20 """What the About / Privacy / Terms / Contact pages draw from. 21 22 Every call here is ``404 site_pages_off`` while the deployment has not 23 switched the pages on, unless the caller is a platform admin, who reads 24 them as a preview (``SiteResponse.preview``). 25 """ 26 27 def __init__(self, http: BaseHttpClient) -> None: 28 self._http = http 29 30 def get(self) -> SiteResponse: 31 """The operator's addresses, partners, citation and service terms.""" 32 resp = self._http.request("GET", "/site") 33 _raise_for_status(resp) 34 return SiteResponse.model_validate(resp.json()) 35 36 def page(self, slug: SitePageSlug) -> SitePageResponse: 37 """One page's text, ``{locale: markdown}``.""" 38 resp = self._http.request("GET", f"/site/pages/{slug}") 39 _raise_for_status(resp) 40 return SitePageResponse.model_validate(resp.json()) 41 42 def contact( 43 self, 44 *, 45 email: str, 46 body: str, 47 topic: ContactTopic = "general", 48 name: str = "", 49 organization: str = "", 50 locale: Literal["en", "zh-CN"] = "en", 51 ) -> ContactMessageCreated: 52 """Leave a message for the operators; ``email`` is where they reply. 53 54 Rate-limited per caller. The acknowledgement never says whether the 55 message was stored. 56 """ 57 resp = self._http.request( 58 "POST", 59 "/site/contact", 60 json={ 61 "topic": topic, 62 "name": name, 63 "email": email, 64 "organization": organization, 65 "body": body, 66 "locale": locale, 67 }, 68 ) 69 _raise_for_status(resp) 70 return ContactMessageCreated.model_validate(resp.json())
What the About / Privacy / Terms / Contact pages draw from.
Every call here is 404 site_pages_off while the deployment has not
switched the pages on, unless the caller is a platform admin, who reads
them as a preview (SiteResponse.preview).
def
get(self) -> ctfy.server.models.site.SiteResponse:
30 def get(self) -> SiteResponse: 31 """The operator's addresses, partners, citation and service terms.""" 32 resp = self._http.request("GET", "/site") 33 _raise_for_status(resp) 34 return SiteResponse.model_validate(resp.json())
The operator's addresses, partners, citation and service terms.
def
page( self, slug: Literal['about', 'privacy', 'terms', 'evaluation-service', 'security', 'faq']) -> ctfy.server.models.site.SitePageResponse:
36 def page(self, slug: SitePageSlug) -> SitePageResponse: 37 """One page's text, ``{locale: markdown}``.""" 38 resp = self._http.request("GET", f"/site/pages/{slug}") 39 _raise_for_status(resp) 40 return SitePageResponse.model_validate(resp.json())
One page's text, {locale: markdown}.
def
contact( self, *, email: str, body: str, topic: Literal['general', 'partnership', 'evaluation', 'privacy', 'security'] = 'general', name: str = '', organization: str = '', locale: Literal['en', 'zh-CN'] = 'en') -> ctfy.server.models.site.ContactMessageCreated:
42 def contact( 43 self, 44 *, 45 email: str, 46 body: str, 47 topic: ContactTopic = "general", 48 name: str = "", 49 organization: str = "", 50 locale: Literal["en", "zh-CN"] = "en", 51 ) -> ContactMessageCreated: 52 """Leave a message for the operators; ``email`` is where they reply. 53 54 Rate-limited per caller. The acknowledgement never says whether the 55 message was stored. 56 """ 57 resp = self._http.request( 58 "POST", 59 "/site/contact", 60 json={ 61 "topic": topic, 62 "name": name, 63 "email": email, 64 "organization": organization, 65 "body": body, 66 "locale": locale, 67 }, 68 ) 69 _raise_for_status(resp) 70 return ContactMessageCreated.model_validate(resp.json())
Leave a message for the operators; email is where they reply.
Rate-limited per caller. The acknowledgement never says whether the message was stored.