Skip to content

Commit

Permalink
cms: add project tile and blocks for projects and remove storefronts
Browse files Browse the repository at this point in the history
  • Loading branch information
vellip committed Jan 23, 2025
1 parent 218ffc3 commit 7d7f199
Show file tree
Hide file tree
Showing 26 changed files with 484 additions and 958 deletions.
5 changes: 5 additions & 0 deletions changelog/8756.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
### Removed
- removed storefront code as its obsolete now

### Added
- Wagtail block and logic to choose a project instance
40 changes: 6 additions & 34 deletions meinberlin/apps/cms/blocks.py
Original file line number Diff line number Diff line change
@@ -1,47 +1,19 @@
from django import forms
from django.db.models import Q
from django.utils.functional import cached_property
from django.utils.translation import gettext_lazy as _
from wagtail import blocks
from wagtail.images.blocks import ImageChooserBlock

from adhocracy4.projects.models import Access
from adhocracy4.projects.models import Project
from meinberlin.apps.cms.viewsets import project_chooser_viewset


class ProjectSelectionBlock(blocks.ChooserBlock):
target_model = Project
widget = forms.widgets.Select

@cached_property
def field(self):
return forms.ModelChoiceField(
queryset=self.target_model.objects.filter(
Q(access=Access.PUBLIC) | Q(access=Access.SEMIPUBLIC),
is_draft=False,
is_archived=False,
),
widget=self.widget,
required=self._required,
help_text=self._help_text,
)

def value_for_form(self, value):
if isinstance(value, Project):
return value.pk
return value

def value_from_form(self, value):
# if project became unavailable (unpublished), selection will become an
# empty string and cause a server error on save, so we give a fallback
value = value or None
return super().value_from_form(value)
ProjectSelectionBlock = project_chooser_viewset.get_block_class(
name="ProjectSelectionBlock", module_path="meinberlin.apps.cms.blocks"
)


class ProjectsWrapperBlock(blocks.StructBlock):
title = blocks.CharBlock(max_length=80)
heading = blocks.CharBlock(max_length=80)
projects = blocks.ListBlock(
ProjectSelectionBlock(label="Project"),
min_num=3
)

class Meta:
Expand Down
Empty file.
Empty file.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

from django.db import migrations, models
import django.db.models.deletion
import meinberlin.apps.cms.models.storefronts


class Migration(migrations.Migration):
Expand All @@ -17,7 +16,7 @@ class Migration(migrations.Migration):
name="project",
field=models.ForeignKey(
blank=True,
limit_choices_to=meinberlin.apps.cms.models.storefronts.project_choice_limit,
limit_choices_to={"in_id": [1, 2]},
null=True,
on_delete=django.db.models.deletion.CASCADE,
related_name="+",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# Generated by Django 3.2.17 on 2023-02-09 12:31

from django.db import migrations, models
import meinberlin.apps.cms.models.storefronts


class Migration(migrations.Migration):
Expand All @@ -13,15 +12,11 @@ class Migration(migrations.Migration):
migrations.AddField(
model_name="storefront",
name="num_entries",
field=models.PositiveIntegerField(
default=meinberlin.apps.cms.models.storefronts.get_num_entries_count
),
field=models.PositiveIntegerField(default=1),
),
migrations.AddField(
model_name="storefront",
name="num_projects",
field=models.PositiveIntegerField(
default=meinberlin.apps.cms.models.storefronts.get_num_projects_count
),
field=models.PositiveIntegerField(default=1),
),
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,194 @@
# Generated by Django 4.2.11 on 2025-01-22 14:49

from django.db import migrations
import meinberlin.apps.cms.blocks
import wagtail.blocks
import wagtail.fields
import wagtail.images.blocks


class Migration(migrations.Migration):

dependencies = [
("meinberlin_cms", "0047_headerpages_easy_language_page"),
]

operations = [
migrations.RemoveField(
model_name="homepage",
name="storefront",
),
migrations.AlterField(
model_name="homepage",
name="body",
field=wagtail.fields.StreamField(
[
(
"paragraph",
wagtail.blocks.RichTextBlock(
template="meinberlin_cms/blocks/richtext_block.html"
),
),
(
"projects",
wagtail.blocks.StructBlock(
[
("heading", wagtail.blocks.CharBlock(max_length=80)),
(
"projects",
wagtail.blocks.ListBlock(
meinberlin.apps.cms.blocks.ProjectSelectionBlock(
label="Project"
),
min_num=3,
),
),
]
),
),
(
"call_to_action",
wagtail.blocks.StructBlock(
[
("body", wagtail.blocks.RichTextBlock()),
("link", wagtail.blocks.CharBlock()),
(
"link_text",
wagtail.blocks.CharBlock(
label="Link Text", max_length=50
),
),
]
),
),
(
"image_call_to_action",
wagtail.blocks.StructBlock(
[
("image", wagtail.images.blocks.ImageChooserBlock()),
("title", wagtail.blocks.CharBlock(max_length=80)),
("body", wagtail.blocks.RichTextBlock()),
("link", wagtail.blocks.CharBlock()),
(
"link_text",
wagtail.blocks.CharBlock(
label="Link Text", max_length=50
),
),
]
),
),
(
"columns_text",
wagtail.blocks.StructBlock(
[
(
"columns_count",
wagtail.blocks.ChoiceBlock(
choices=[
(2, "Two columns"),
(3, "Three columns"),
(4, "Four columns"),
]
),
),
(
"columns",
wagtail.blocks.ListBlock(
wagtail.blocks.RichTextBlock(
label="Column body"
)
),
),
]
),
),
(
"activities",
wagtail.blocks.StructBlock(
[
("heading", wagtail.blocks.CharBlock(label="Heading")),
(
"count",
wagtail.blocks.IntegerBlock(
default=5, label="Count"
),
),
]
),
),
(
"accordion_list",
wagtail.blocks.StructBlock(
[
(
"list_title",
wagtail.blocks.CharBlock(
help_text="Optional title for the list of accordions.",
required=False,
),
),
(
"accordions",
wagtail.blocks.ListBlock(
wagtail.blocks.StructBlock(
[
(
"expand_accordion",
wagtail.blocks.BooleanBlock(
help_text="The accordion is collapsed by default. Select this option to have it expanded when the page loads.",
label="Expand accordion?",
required=False,
),
),
("title", wagtail.blocks.CharBlock()),
(
"body",
wagtail.blocks.RichTextBlock(
required=False
),
),
]
),
help_text="Add, remove, or reorder accordions.",
),
),
]
),
),
(
"infographic",
wagtail.blocks.StructBlock(
[
("text_left", wagtail.blocks.CharBlock(max_length=50)),
(
"text_center",
wagtail.blocks.CharBlock(max_length=50),
),
("text_right", wagtail.blocks.CharBlock(max_length=50)),
]
),
),
(
"map_teaser",
wagtail.blocks.StructBlock(
[
("image", wagtail.images.blocks.ImageChooserBlock()),
("body", wagtail.blocks.RichTextBlock()),
]
),
),
],
use_json_field=True,
),
),
migrations.DeleteModel(
name="Storefront",
),
migrations.DeleteModel(
name="StorefrontCollection",
),
migrations.DeleteModel(
name="StorefrontItem",
),
]
1 change: 0 additions & 1 deletion meinberlin/apps/cms/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,3 @@
from .navigation_menues import * # noqa
from .pages import * # noqa
from .settings import * # noqa
from .storefronts import * # noqa
8 changes: 1 addition & 7 deletions meinberlin/apps/cms/models/pages.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ class HomePage(Page):
template="meinberlin_cms/blocks/richtext_block.html"
),
),
("projects", cms_blocks.ProjectsWrapperBlock()),
("call_to_action", cms_blocks.CallToActionBlock()),
("image_call_to_action", cms_blocks.ImageCallToActionBlock()),
("columns_text", cms_blocks.ColumnsBlock()),
Expand All @@ -64,18 +65,11 @@ class HomePage(Page):
on_delete=models.SET_NULL,
related_name="+",
)
storefront = models.ForeignKey(
"meinberlin_cms.Storefront",
on_delete=models.SET_NULL,
null=True,
related_name="+",
)

content_panels = Page.content_panels + [
panels.FieldPanel("subtitle"),
panels.FieldPanel("header_image"),
panels.FieldPanel("body"),
panels.FieldPanel("storefront"),
]


Expand Down
Loading

0 comments on commit 7d7f199

Please sign in to comment.