|
| 1 | +from typing import Self |
| 2 | +import strawberry |
| 3 | +from api.cms.page.registry import register_page_block |
| 4 | + |
| 5 | + |
| 6 | +@strawberry.type |
| 7 | +class Community: |
| 8 | + name: str |
| 9 | + description: str |
| 10 | + logo: str | None |
| 11 | + banner_photo: str | None |
| 12 | + banner_background_color: str | None |
| 13 | + |
| 14 | + mastodon_url: str | None |
| 15 | + facebook_url: str | None |
| 16 | + instagram_url: str | None |
| 17 | + linkedin_url: str | None |
| 18 | + twitter_url: str | None |
| 19 | + |
| 20 | + @classmethod |
| 21 | + def from_block(cls, block) -> Self: |
| 22 | + logo_url = None |
| 23 | + if block["logo"]: |
| 24 | + logo_url = block["logo"].get_rendition("width-300|jpegquality-60").full_url |
| 25 | + |
| 26 | + banner_photo_url = None |
| 27 | + if block["banner_photo"]: |
| 28 | + banner_photo_url = ( |
| 29 | + block["banner_photo"].get_rendition("width-300|jpegquality-60").full_url |
| 30 | + ) |
| 31 | + |
| 32 | + return cls( |
| 33 | + name=block["name"], |
| 34 | + description=block["description"], |
| 35 | + logo=logo_url, |
| 36 | + banner_photo=banner_photo_url, |
| 37 | + banner_background_color=block["banner_background_color"], |
| 38 | + mastodon_url=block["mastodon_url"], |
| 39 | + facebook_url=block["facebook_url"], |
| 40 | + instagram_url=block["instagram_url"], |
| 41 | + linkedin_url=block["linkedin_url"], |
| 42 | + twitter_url=block["twitter_url"], |
| 43 | + ) |
| 44 | + |
| 45 | + |
| 46 | +@register_page_block() |
| 47 | +@strawberry.type |
| 48 | +class CommunitiesSection: |
| 49 | + id: strawberry.ID |
| 50 | + title: str |
| 51 | + communities: list[Community] |
| 52 | + |
| 53 | + @classmethod |
| 54 | + def from_block(cls, block) -> Self: |
| 55 | + return cls( |
| 56 | + id=block.id, |
| 57 | + title=block.value["title"], |
| 58 | + communities=[ |
| 59 | + Community.from_block(community) |
| 60 | + for community in block.value["communities"] |
| 61 | + ], |
| 62 | + ) |
0 commit comments