Skip to content

Commit

Permalink
simplified menus
Browse files Browse the repository at this point in the history
  • Loading branch information
ramibch committed Jan 7, 2024
1 parent 6350251 commit e193384
Show file tree
Hide file tree
Showing 28 changed files with 581 additions and 3,225 deletions.
23 changes: 23 additions & 0 deletions cms/context_processors.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
from functools import cache
from itertools import chain


from wagtail.models import Locale
from cms.models.blog import BlogIndexPage
from cms.models.flex import FlexPage
from cms.models.text import TextPage


@cache
def cms_menu_pages(request):
try:
locale = Locale.objects.get(language_code=request.LANGUAGE_CODE)
except Locale.DoesNotExist:
return {"cms_navbar_pages": None}
blog_pages = BlogIndexPage.objects.filter(locale=locale, show_in_menus=True)
flex_pages = FlexPage.objects.filter(locale=locale, show_in_menus=True)
text_pages = TextPage.objects.filter(locale=locale, show_in_menus=True)
return {
"cms_navbar_pages": chain(blog_pages, flex_pages),
"cms_footer_pages": chain(blog_pages, flex_pages, text_pages),
}
31 changes: 16 additions & 15 deletions cms/migrations/0001_initial.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@
import wagtail.images.blocks
import wagtail.models
import wagtail.search.index
import wagtailmenus.models.menuitems
import wagtailmenus.models.menus
import wagtailmenus.models.mixins

# import wagtailmenus.models.menuitems
# import wagtailmenus.models.menus
# import wagtailmenus.models.mixins


class Migration(migrations.Migration):
Expand Down Expand Up @@ -208,11 +209,11 @@ class Migration(migrations.Migration):
"abstract": False,
"unique_together": {("site", "handle")},
},
bases=(
wagtailmenus.models.mixins.DefinesSubMenuTemplatesMixin,
models.Model,
wagtailmenus.models.menus.Menu,
),
# bases=(
# wagtailmenus.models.mixins.DefinesSubMenuTemplatesMixin,
# models.Model,
# wagtailmenus.models.menus.Menu,
# ),
),
migrations.CreateModel(
name="CustomMainMenu",
Expand Down Expand Up @@ -256,11 +257,11 @@ class Migration(migrations.Migration):
"verbose_name_plural": "main menu",
"abstract": False,
},
bases=(
wagtailmenus.models.mixins.DefinesSubMenuTemplatesMixin,
models.Model,
wagtailmenus.models.menus.Menu,
),
# bases=(
# wagtailmenus.models.mixins.DefinesSubMenuTemplatesMixin,
# models.Model,
# wagtailmenus.models.menus.Menu,
# ),
),
migrations.CreateModel(
name="DjangoServedPage",
Expand Down Expand Up @@ -970,7 +971,7 @@ class Migration(migrations.Migration):
"ordering": ("sort_order",),
"abstract": False,
},
bases=(models.Model, wagtailmenus.models.menuitems.MenuItem),
# bases=(models.Model, wagtailmenus.models.menuitems.MenuItem),
),
migrations.CreateModel(
name="CustomFlatMenuItem",
Expand Down Expand Up @@ -1087,7 +1088,7 @@ class Migration(migrations.Migration):
"ordering": ("sort_order",),
"abstract": False,
},
bases=(models.Model, wagtailmenus.models.menuitems.MenuItem),
# bases=(models.Model, wagtailmenus.models.menuitems.MenuItem),
),
migrations.CreateModel(
name="Brand",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# Generated by Django 4.2.5 on 2024-01-07 22:59

from django.db import migrations


class Migration(migrations.Migration):
dependencies = [
("cms", "0004_legal_impress_page_de_legal_impress_page_en_and_more"),
]

operations = [
migrations.RemoveField(
model_name="customflatmenuitem",
name="link_page",
),
migrations.RemoveField(
model_name="customflatmenuitem",
name="menu",
),
migrations.RemoveField(
model_name="custommainmenu",
name="site",
),
migrations.RemoveField(
model_name="custommainmenuitem",
name="link_page",
),
migrations.RemoveField(
model_name="custommainmenuitem",
name="menu",
),
migrations.RemoveField(
model_name="brand",
name="footer_text_de",
),
migrations.RemoveField(
model_name="brand",
name="footer_text_en",
),
migrations.RemoveField(
model_name="brand",
name="footer_text_es",
),
migrations.DeleteModel(
name="CustomFlatMenu",
),
migrations.DeleteModel(
name="CustomFlatMenuItem",
),
migrations.DeleteModel(
name="CustomMainMenu",
),
migrations.DeleteModel(
name="CustomMainMenuItem",
),
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Generated by Django 4.2.5 on 2024-01-07 23:01

from django.db import migrations


class Migration(migrations.Migration):
dependencies = [
("cms", "0005_remove_customflatmenuitem_link_page_and_more"),
]

operations = [
migrations.RemoveField(
model_name="brand",
name="footer_text",
),
migrations.RemoveField(
model_name="brand",
name="svg_footer",
),
]
5 changes: 0 additions & 5 deletions cms/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,6 @@
from .djangopages import DjangoServedPage
from .flex import FlexPage
from .home import HomePage
from .menus import CustomFlatMenu
from .menus import CustomFlatMenuItem
from .menus import CustomMainMenu
from .menus import CustomMainMenuItem
from .setttings import Banner
from .setttings import Brand
from .setttings import Links
Expand All @@ -22,4 +18,3 @@
# Flex page
# Site settings
# FAQs
# Menus models
90 changes: 0 additions & 90 deletions cms/models/menus.py

This file was deleted.

14 changes: 1 addition & 13 deletions cms/models/setttings.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,24 +44,12 @@ class Links(BaseSiteSetting):

@register_setting(icon="openquote")
class Brand(BaseSiteSetting):
footer_text = models.TextField(blank=True, null=True)
name = models.CharField(blank=True, null=True, max_length=16)
svg = models.ForeignKey(
Image, related_name="+", null=True, blank=True, on_delete=models.SET_NULL
)
svg_footer = models.ForeignKey(
Image, related_name="+", null=True, blank=True, on_delete=models.SET_NULL
)

panels = [
FieldPanel("name"),
FieldPanel("svg"),
FieldPanel("svg_footer"),
MultiFieldPanel(
localized_fieldpanel_list("footer_text"),
heading="Footer Slogan in Footer",
),
]
panels = [FieldPanel("name"), FieldPanel("svg")]


@register_setting(icon="user")
Expand Down
27 changes: 2 additions & 25 deletions cms/translation.py
Original file line number Diff line number Diff line change
@@ -1,33 +1,10 @@
from modeltranslation.translator import register
from modeltranslation.translator import TranslationOptions

from .models.setttings import Banner, Brand, Legal
from .models.menus import CustomFlatMenu, CustomFlatMenuItem, CustomMainMenuItem
from .models.setttings import Banner, Legal
from .models.snippets import FrequentAskedQuestion


# menus
@register(CustomMainMenuItem)
class MainMenuItemTranslationOptions(TranslationOptions):
fields = ("link_text",)


@register(CustomFlatMenuItem)
class FlatMenuItemTranslationOptions(TranslationOptions):
fields = ("link_text",)


@register(CustomFlatMenu)
class FlatMenuTranslationOptions(TranslationOptions):
fields = ("heading",)


# site setttings
@register(Brand)
class BrandTranslationOptions(TranslationOptions):
fields = ("footer_text",)


@register(Banner)
class BannerTranslationOptions(TranslationOptions):
fields = ("title", "text", "linked_page")
Expand All @@ -39,7 +16,7 @@ class FrequentAskedQuestionTranslationOptions(TranslationOptions):
fields = ("question", "answer")


# LEgal
# Legal
@register(Legal)
class LegalTranslationOptions(TranslationOptions):
fields = ("privacy_policy_page", "terms_page", "impress_page")
26 changes: 5 additions & 21 deletions config/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@
# Third-party apps
"wagtail_localize",
"wagtail_localize.locales", # This replaces "wagtail.locales"
"wagtailmenus",
# "wagtailmenus",
"django_extensions",
"rosetta",
"modeltranslation",
Expand Down Expand Up @@ -166,10 +166,10 @@
"django.contrib.messages.context_processors.messages",
# wagtail
"wagtail.contrib.settings.context_processors.settings",
# thid-party
"wagtailmenus.context_processors.wagtailmenus",
# project
"config.project.context_processors",
# core
"core.context_processors.cv_templates",
# cms
"cms.context_processors.cms_menu_pages",
],
"debug": DEBUG,
},
Expand Down Expand Up @@ -323,22 +323,6 @@
]


# Wagtail menus
# https://github.com/jazzband/wagtailmenus
# main menu (navbar)
WAGTAILMENUS_MAIN_MENU_MODEL = "cms.CustomMainMenu"
WAGTAILMENUS_MAIN_MENU_ITEMS_RELATED_NAME = "menu_items"

# flat menus
WAGTAILMENUS_FLAT_MENU_MODEL = "cms.CustomFlatMenu"
WAGTAILMENUS_FLAT_MENU_ITEMS_RELATED_NAME = "menu_items"
WAGTAILMENUS_FLAT_MENUS_HANDLE_CHOICES = (
("about", "About"),
("learn", "Learn"),
("info", "Info"),
("legal", "Legal"),
)

# static files (whitenoise)
STATIC_URL = "/static/"
STATIC_ROOT = BASE_DIR / "staticfiles"
Expand Down
Loading

0 comments on commit e193384

Please sign in to comment.