Skip to content

Commit

Permalink
[Catalogue] Carte contact verticale (numerique-gouv#242)
Browse files Browse the repository at this point in the history
* Setting the new block aside for now

* Work on the contact card

* Finish code for contact cards
  • Loading branch information
Ash-Crow authored Dec 5, 2024
1 parent 070b662 commit 0118b82
Show file tree
Hide file tree
Showing 9 changed files with 8,302 additions and 105 deletions.

Large diffs are not rendered by default.

86 changes: 86 additions & 0 deletions content_manager/blocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -717,6 +717,91 @@ class Meta:
template = "content_manager/blocks/video.html"


class VerticalContactCardStructValue(blocks.StructValue):
def display(self):
contact = self.get("contact", None)

name = self.get("name", "")
if contact and not name:
name = contact.name

role = self.get("role", "")
if contact and not role:
role = contact.role

organization = self.get("organization", "")
if contact and not organization:
organization = contact.organization.name

image = self.get("image", "")
if contact and not image:
image = contact.image

return {"name": name, "role": role, "organization": organization, "image": image}

def enlarge_link(self):
"""
Determine if we need (and can) enlarge the link on the card.
This requires:
- That a link is present
- That no other link is used on the card (such as a tag with a link, or a call-to-action)
"""
link = self.get("link")
tags = self.get("tags")
call_to_action = self.get("call_to_action", "")

if not (link and link.url()):
return False

enlarge = True
if len(call_to_action):
enlarge = False
elif len(tags):
print(tags)
print(tags.raw_data)
tags_list = tags.raw_data
for tag in tags_list:
if (
tag["value"]["link"]["page"] is not None
or tag["value"]["link"]["document"] is not None
or tag["value"]["link"]["external_url"] != ""
):
enlarge = False

return enlarge


class VerticalContactCardBlock(blocks.StructBlock):
contact = SnippetChooserBlock(
"blog.Person",
label=_("Person"),
help_text=_("Optional, all values can be manually specified or overriden below"),
required=False,
)
link = LinkWithoutLabelBlock(
label=_("Link"),
required=False,
)
heading_tag = blocks.ChoiceBlock(
label=_("Heading level"),
choices=HEADING_CHOICES,
required=False,
default="h3",
help_text=_("Adapt to the page layout. Defaults to heading 3."),
)
name = blocks.CharBlock(label=_("Name"), max_length=255, required=False)
role = blocks.CharBlock(label=_("Role"), max_length=255, required=False)
organization = blocks.CharBlock(label=_("Organization"), max_length=255, required=False)
contact_info = blocks.CharBlock(label=_("Contact info"), max_length=500, required=False)
image = ImageChooserBlock(label="Image", required=False)
tags = TagListBlock(label=_("Tags"), required=False)

class Meta:
icon = "user"
value_class = VerticalContactCardStructValue
template = ("content_manager/blocks/contact_card_vertical.html",)


## Other apps-related blocks
class RecentEntriesStructValue(blocks.StructValue):
"""
Expand Down Expand Up @@ -877,6 +962,7 @@ class Meta:

class ColumnBlock(CommonStreamBlock):
card = VerticalCardBlock(label=_("Vertical card"), group=_("DSFR components"))
contact_card = VerticalContactCardBlock(label=_("Contact card"), group=_("Extra components"))


class ItemGridBlock(blocks.StructBlock):
Expand Down
Binary file modified content_manager/locale/fr/LC_MESSAGES/django.mo
Binary file not shown.
Loading

0 comments on commit 0118b82

Please sign in to comment.