-
Notifications
You must be signed in to change notification settings - Fork 25
Expand file tree
/
Copy pathcommunities_section.py
More file actions
64 lines (55 loc) · 1.76 KB
/
communities_section.py
File metadata and controls
64 lines (55 loc) · 1.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
from typing import Self
import strawberry
from api.cms.page.registry import register_page_block
@strawberry.type
class Community:
name: str
description: str
logo: str | None
banner_photo: str | None
banner_background_color: str | None
mastodon_url: str | None
facebook_url: str | None
instagram_url: str | None
linkedin_url: str | None
twitter_url: str | None
website_url: str | None
@classmethod
def from_block(cls, block) -> Self:
logo_url = None
if block["logo"]:
logo_url = block["logo"].get_rendition("width-300|jpegquality-60").full_url
banner_photo_url = None
if block["banner_photo"]:
banner_photo_url = (
block["banner_photo"].get_rendition("width-300|jpegquality-60").full_url
)
return cls(
name=block["name"],
description=block["description"],
logo=logo_url,
banner_photo=banner_photo_url,
banner_background_color=block["banner_background_color"],
mastodon_url=block["mastodon_url"],
facebook_url=block["facebook_url"],
instagram_url=block["instagram_url"],
linkedin_url=block["linkedin_url"],
twitter_url=block["twitter_url"],
website_url=block["website_url"],
)
@register_page_block()
@strawberry.type
class CommunitiesSection:
id: strawberry.ID
title: str
communities: list[Community]
@classmethod
def from_block(cls, block) -> Self:
return cls(
id=block.id,
title=block.value["title"],
communities=[
Community.from_block(community)
for community in block.value["communities"]
],
)