Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dev #110

Merged
merged 2 commits into from
May 14, 2024
Merged

Dev #110

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Generated by Django 4.2.3 on 2024-05-14 09:32

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('base', '0027_integrationsettings_google_site_verification_key'),
]

operations = [
migrations.AlterModelOptions(
name='servicecategory',
options={'ordering': ['order'], 'verbose_name': 'Service Category', 'verbose_name_plural': 'Service Categories'},
),
migrations.AddField(
model_name='servicecategory',
name='order',
field=models.IntegerField(blank=True, editable=False, null=True),
),
]
4 changes: 3 additions & 1 deletion base/models/snippets.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,14 +79,15 @@ def slug(self):
return slugify(self.name)


@register_snippet
class ServiceCategory(models.Model):
name = models.CharField(max_length=255, verbose_name=_("Name"))
icon = models.CharField(max_length=100, verbose_name=_("Icon"))
order = models.IntegerField(null=True, blank=True)

panels = [
FieldPanel('name'),
FieldPanel('icon', widget=IconChooserWidget),
FieldPanel('order'),
]

api_fields = [
Expand All @@ -97,6 +98,7 @@ def __str__(self):
return self.name

class Meta:
ordering = ['order']
verbose_name = _("Service Category")
verbose_name_plural = _("Service Categories")

Expand Down
14 changes: 8 additions & 6 deletions base/templates/blocks/main_menu.html
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
{% load wagtailimages_tags wagtailiconchooser_tags %}

{% if value.has_sub_items %}
<div class="navbar-item has-dropdown is-hoverable">
<div class="navbar-item has-dropdown is-hoverable {% if value.large_submenu %}is-mega{% endif %}">
<a class="navbar-item nav-item-title" {% if value.page.url %}href="{{ value.page.url }}" {% endif %}>
{{ value.label }}
</a>
{% if value.large_submenu %}
<div class="navbar-dropdown megamenu">
<div>
<div class="container megamenu-container">
{% if value.page %}
{% if value.page.specific.is_products_index and value.page.specific.group_menu_items_by_service %}
{% include "blocks/products_by_service_menu.html" %}
{% if value.page.specific.is_services_index %}
{% include "blocks/services_with_products_menu.html" %}
{% else %}
<div class="columns is-multiline">
<div class="columns is-multiline megamenu-columns">
{% for sub_page in value.page.get_children %}
{% if sub_page.show_in_menus and sub_page.live %}
<div class="column is-half">
<div class="column is-half-touch is-one-third-desktop is-one-quarter-fullhd">
<a class="navbar-item" href="{{ sub_page.url }}">
<div class="menu-item-figure">
{% if sub_page.specific.nav_menu_icon %}
Expand All @@ -37,6 +37,8 @@
{% endfor %}
</div>
{% endif %}


{% if value.sub_items %}
<div class="columns is-multiline sub-items-list">
{% for item in value.sub_items %}
Expand Down
45 changes: 0 additions & 45 deletions base/templates/blocks/products_by_service_menu.html

This file was deleted.

66 changes: 66 additions & 0 deletions base/templates/blocks/services_with_products_menu.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
{% load wagtailimages_tags wagtailiconchooser_tags %}

<div class="columns is-multiline is-mobile megamenu-columns">
{% with value.page.specific.service_pages.count as services_count %}
{% for service_page_ in value.page.specific.service_pages %}
{% with service_page=service_page_.specific %}
{% if service_page.show_in_menus and service_page.live %}
<div class="column is-half-touch is-one-third-desktop is-one-quarter-fullhd">
<a class="navbar-item" href="{{ service_page.url }}"
style="font-weight: bold;text-decoration: underline">
<div class="menu-item-figure">
{% if service_page.nav_menu_icon %}
{% svg_icon service_page.nav_menu_icon %}
{% elif service_page.banner_image %}
{% image service_page.banner_image original as service_page_image %}
<img src="{{ service_page_image.url }}" alt="">
{% elif service_page.introduction_image %}
{% image service_page.introduction_image original as service_page_image %}
<img src="{{ service_page_image.url }}" alt="">
{% endif %}
</div>
<div class="menu-item-label">
{{ service_page.title }}
</div>
<hr>
</a>
{% if service_page.core_products %}
{% for product_page in service_page.core_products %}
<a class="navbar-item is-hidden-touch" href="{{ product_page.url }}"
style="margin-left: 50px;display: b">
<div class="menu-item-figure">
{% if product_page.introduction_image %}
{% image product_page.introduction_image original as product_image %}
<img src="{{ product_image.url }}" alt="">
{% endif %}
</div>
<div class="menu-item-label">
{{ product_page.title }}
</div>
</a>
{% endfor %}
{% endif %}
{% if service_page.flex_pages %}
{% for flex_page in service_page.flex_pages %}
<a class="navbar-item" href="{{ flex_page.url }}"
style="margin-left: 50px;">
<div class="menu-item-figure">
{% if flex_page.banner_image %}
{% image flex_page.banner_image original as flex_page_image %}
<img src="{{ flex_page_image.url }}" alt="">
{% endif %}
</div>
<div class="menu-item-label">
{{ flex_page.title }}
</div>
</a>
{% endfor %}
{% endif %}
</div>
{% endif %}
{% endwith %}
{% endfor %}

{% endwith %}
</div>

11 changes: 10 additions & 1 deletion base/wagtail_hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@
from django.utils.translation import gettext_lazy as _
from wagtail import hooks
from wagtail.admin.ui.components import Component
from wagtail.snippets.models import register_snippet
from wagtail.snippets.views.snippets import SnippetViewSet
from wagtail_modeladmin.options import (
ModelAdmin,
modeladmin_register, ModelAdminGroup,
)
from wagtailcache.cache import clear_cache

from base.models import Theme
from base.models import Theme, ServiceCategory
from base.utils import get_latest_cms_release
from base.views import cms_version_view
from nmhs_cms.utils.version import get_main_version, check_version_greater_than_current
Expand Down Expand Up @@ -41,6 +43,13 @@ def urlconf_base():
]


class ServiceViewSet(SnippetViewSet):
model = ServiceCategory


register_snippet(ServiceViewSet)


class ThemeSettings(ModelAdmin):
model = Theme
menu_label = _('Themes')
Expand Down
32 changes: 23 additions & 9 deletions nmhs_cms/static/css/navigation.css
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ header {
border-bottom: 1px solid rgba(195, 192, 192, 0.37);
}

.navbar-item.is-mega {
position: static;
}


/* .header-nav {
padding: 10px 10px 0;
} */
Expand Down Expand Up @@ -190,23 +195,32 @@ header {

.navbar-burger:hover {
background-color: transparent !important;

}

.navbar-dropdown.megamenu {
background-color: unset;
box-shadow: none;
padding-top: 0;
}

.megamenu {
min-width: 600px;
padding: 30px;
.megamenu-container {
background-color: #fff;
box-shadow: 0 8px 8px rgba(10, 10, 10, .1);
border-bottom-left-radius: var(--border-radius);
border-bottom-right-radius: var(--border-radius);
padding-bottom: 40px;
}

.megamenu-container .megamenu-columns {
margin: 0;
}

.megamenu .navbar-item {
padding: 5px 0 !important;
white-space: normal;
display: flex;
align-items: center;
.megamenu-container .megamenu-columns .navbar-item {
text-wrap: wrap;
word-break: normal;
}


.megamenu .navbar-item .menu-item-label {
margin-left: 10px;
flex: 1;
Expand Down
3 changes: 2 additions & 1 deletion pages/cap/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,8 @@ def item_author_email(self, item):
return None

def item_categories(self, item):
return [item.info[0].value.get('category')]
categories = item.info[0].value.get('category')
return categories


def get_cap_xml(request, identifier):
Expand Down
8 changes: 6 additions & 2 deletions pages/flex_page/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,15 @@
from base.models import AbstractBannerPage


# model for flexible pages
class FlexPage(AbstractBannerPage):
template = "flex_page.html"

parent_page_types = ['home.HomePage']
parent_page_types = [
'home.HomePage',
'services.ServicePage',
'organisation.OrganisationIndexPage',
'about.AboutPage',
]

content = StreamField(
[
Expand Down
2 changes: 1 addition & 1 deletion pages/organisation_pages/about/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
class AboutPage(AbstractIntroPage):
template = 'about_page.html'
parent_page_types = ['organisation.OrganisationIndexPage']
subpage_types = ['flex_page.FlexPage',]
subpage_types = ['flex_page.FlexPage', ]
max_count = 1
show_in_menus_default = True

Expand Down
33 changes: 29 additions & 4 deletions pages/services/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from base.models import ServiceCategory, AbstractBannerWithIntroPage
from nmhs_cms.settings.base import SUMMARY_RICHTEXT_FEATURES
from pages.events.models import EventPage
from pages.flex_page.models import FlexPage
from pages.news.models import NewsPage
from pages.organisation_pages.projects.models import ServiceProject
from pages.products.models import ProductPage
Expand All @@ -27,23 +28,26 @@ class ServiceIndexPage(MetadataPageMixin, Page):
listing_heading = models.CharField(max_length=255, default="Explore our Services",
verbose_name=_("Services listing Heading"))
max_count = 1
is_services_index = True

content_panels = Page.content_panels + [
FieldPanel("listing_heading")
]

def get_children_pages(self):
return self.get_children().live()

class Meta:
verbose_name = _('Service List Page')
verbose_name_plural = _('Service List Pages')

@cached_property
def service_pages(self):
service_pages = ServicePage.objects.live().descendant_of(self).order_by('service__order')
return service_pages


class ServicePage(AbstractBannerWithIntroPage):
template = 'services/service_page.html'
parent_page_types = ['services.ServiceIndexPage']
subpage_types = ['flex_page.FlexPage',]
subpage_types = ['flex_page.FlexPage', ]
show_in_menus_default = True

service = models.OneToOneField(ServiceCategory, on_delete=models.PROTECT, verbose_name=_("Service"))
Expand Down Expand Up @@ -102,6 +106,7 @@ class ServicePage(AbstractBannerWithIntroPage):
class Meta:
verbose_name = _('Service Page')
verbose_name_plural = _('Service Pages')
ordering = ['service__order']

@cached_property
def products(self):
Expand All @@ -114,6 +119,26 @@ def products(self):

return products

@cached_property
def core_products(self):
"""
Get list of core products related to this service
:return: core products list
"""
# Get all products related to this service
core_products = ProductPage.objects.filter(service=self.service)

return core_products

@cached_property
def flex_pages(self):
"""
Get list of flex pages related to this service
"""
flex_pages = FlexPage.objects.live().descendant_of(self)

return flex_pages

@cached_property
def listing_image(self):
if self.banner_image:
Expand Down