Skip to content

Commit

Permalink
Merge pull request #20 from wmo-raf/dev
Browse files Browse the repository at this point in the history
Allow multiple products for a product item type, with different dates
  • Loading branch information
Grace-Amondi authored Jul 31, 2023
2 parents 9a171ca + 21b467e commit 2e27f68
Show file tree
Hide file tree
Showing 6 changed files with 125 additions and 76 deletions.
2 changes: 1 addition & 1 deletion docker/cms/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
FROM ghcr.io/osgeo/gdal:ubuntu-small-3.7.0

# install dependencies
RUN apt-get update && apt-get -y install cron libgeos-dev imagemagick libmagic1 python3-pip --fix-missing
RUN apt-get update && apt-get -y install cron libgeos-dev imagemagick libmagic1 cairo libffi-dev python3-pip --fix-missing

# set python env
ENV PYTHONDONTWRITEBYTECODE 1
Expand Down
2 changes: 2 additions & 0 deletions pages/products/blocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ class ProductCategoryBlock(blocks.StructBlock):

class ProductItemImageContentBlock(blocks.StructBlock):
product_type = blocks.CharBlock(required=True, label=_("Product Type"))
date = blocks.DateBlock(required=True, label=_("Product date"))
image = ImageChooserBlock(required=True, label=_("Image"))
description = blocks.RichTextBlock(label=_("Summary of the map/image information"))

Expand All @@ -48,6 +49,7 @@ class ProductItemDocumentContentBlock(blocks.StructBlock):
product_type = blocks.CharBlock(required=True, label=_("Product Type"))
thumbnail = ImageChooserBlock(required=False, label=_("Thumbnail of the document"),
help_text=_("For example a screen grab of the cover page"))
date = blocks.DateBlock(required=True, label=_("Product date"))
document = DocumentChooserBlock(required=True, label=_("Document"))
description = blocks.RichTextBlock(label=_("Summary of the document information"))

Expand Down
22 changes: 22 additions & 0 deletions pages/products/migrations/0004_alter_productitempage_products.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Generated by Django 4.2.2 on 2023-07-26 15:14

from django.db import migrations
import wagtail.blocks
import wagtail.documents.blocks
import wagtail.fields
import wagtail.images.blocks


class Migration(migrations.Migration):

dependencies = [
('products', '0003_productindexpage_search_image'),
]

operations = [
migrations.AlterField(
model_name='productitempage',
name='products',
field=wagtail.fields.StreamField([('image_product', wagtail.blocks.StructBlock([('product_type', wagtail.blocks.CharBlock(label='Product Type', required=True)), ('date', wagtail.blocks.DateBlock(label='Product date', required=True)), ('image', wagtail.images.blocks.ImageChooserBlock(label='Image', required=True)), ('description', wagtail.blocks.RichTextBlock(label='Summary of the map/image information'))], label='Map/Image Product')), ('document_product', wagtail.blocks.StructBlock([('product_type', wagtail.blocks.CharBlock(label='Product Type', required=True)), ('thumbnail', wagtail.images.blocks.ImageChooserBlock(help_text='For example a screen grab of the cover page', label='Thumbnail of the document', required=False)), ('date', wagtail.blocks.DateBlock(label='Product date', required=True)), ('document', wagtail.documents.blocks.DocumentChooserBlock(label='Document', required=True)), ('description', wagtail.blocks.RichTextBlock(label='Summary of the document information'))], label='Document/Bulletin Product'))], use_json_field=True),
),
]
7 changes: 6 additions & 1 deletion pages/products/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,10 +191,15 @@ def get_context(self, request, *args, **kwargs):
products = self.products
for product in products:
item_type = product.value.product_item_type()
products_dict[item_type.slug] = product
if not products_dict.get(item_type.slug):
products_dict[item_type.slug] = {"item_type": item_type, "products": []}
products_dict[item_type.slug].get("products").append(product)
context.update({"products": products_dict})

for product_type in products_dict.keys():
# sort by date
products_dict[product_type]["products"].sort(key=lambda r: r.value.get("date"))

for category in categories:
if product_categories.get(category.id):
continue
Expand Down
10 changes: 9 additions & 1 deletion pages/products/static/css/product_detail.css
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
.product-item-wrapper {
padding: 20px;
}

.product-item-wrapper:nth-child(odd) {
background-color: #f8f9fb;
}


.product-items-container {
width: 100%;
Expand Down Expand Up @@ -59,7 +67,7 @@
border-bottom-left-radius: 8px;
border-top-left-radius: 8px;
color: var(--primary-color);
font-weight:600;
font-weight: 600;
}

.content-container .content {
Expand Down
Loading

0 comments on commit 2e27f68

Please sign in to comment.