Skip to content

Commit

Permalink
ET-497: market sector snippet adds meta label
Browse files Browse the repository at this point in the history
  • Loading branch information
lewis-coulson-dit committed Oct 2, 2024
1 parent 914b833 commit 350333a
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 22 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Generated by Django 4.2.15 on 2024-10-02 11:45
# Generated by Django 4.2.15 on 2024-10-02 14:20

from django.db import migrations, models
import django.db.models.deletion
Expand All @@ -10,12 +10,12 @@
class Migration(migrations.Migration):

dependencies = [
('core', '0159_remove_regiontagged_content_type_and_more'),
('core', '0160_alter_herosnippet_slug'),
]

operations = [
migrations.CreateModel(
name='CountryTaggedSectorAndMarketPromo',
name='CountryTaggedSectorAndMarketCard',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
],
Expand All @@ -24,19 +24,31 @@ class Migration(migrations.Migration):
},
),
migrations.CreateModel(
name='SectorAndMarketPromo',
name='SectorAndMarketCard',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('title', models.CharField()),
('description', models.TextField()),
('link_text', models.CharField(blank=True)),
('link_url', models.CharField(blank=True)),
(
'meta_label',
models.CharField(
choices=[
('guidance_great', 'Guidance on great.gov.uk'),
('service_great', 'Service on great.gov.uk'),
('guidance_gov', 'Guidance on GOV.UK'),
('service_gov', 'Service on GOV.UK'),
],
max_length=255,
),
),
(
'country_tags',
taggit.managers.TaggableManager(
blank=True,
help_text='A comma-separated list of tags.',
through='core.CountryTaggedSectorAndMarketPromo',
through='core.CountryTaggedSectorAndMarketCard',
to='core.CountryTag',
verbose_name='Country tag',
),
Expand All @@ -48,13 +60,13 @@ class Migration(migrations.Migration):
bases=(wagtail.search.index.Indexed, models.Model),
),
migrations.CreateModel(
name='SectorTaggedTaggedSectorAndMarketPromo',
name='SectorTaggedTaggedSectorAndMarketCard',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
(
'content_object',
modelcluster.fields.ParentalKey(
on_delete=django.db.models.deletion.CASCADE, to='core.sectorandmarketpromo'
on_delete=django.db.models.deletion.CASCADE, to='core.sectorandmarketcard'
),
),
(
Expand All @@ -69,25 +81,25 @@ class Migration(migrations.Migration):
},
),
migrations.AddField(
model_name='sectorandmarketpromo',
model_name='sectorandmarketcard',
name='sector_tags',
field=taggit.managers.TaggableManager(
blank=True,
help_text='A comma-separated list of tags.',
through='core.SectorTaggedTaggedSectorAndMarketPromo',
through='core.SectorTaggedTaggedSectorAndMarketCard',
to='core.SectorTag',
verbose_name='Sector tag',
),
),
migrations.AddField(
model_name='countrytaggedsectorandmarketpromo',
model_name='countrytaggedsectorandmarketcard',
name='content_object',
field=modelcluster.fields.ParentalKey(
on_delete=django.db.models.deletion.CASCADE, to='core.sectorandmarketpromo'
on_delete=django.db.models.deletion.CASCADE, to='core.sectorandmarketcard'
),
),
migrations.AddField(
model_name='countrytaggedsectorandmarketpromo',
model_name='countrytaggedsectorandmarketcard',
name='tag',
field=models.ForeignKey(
on_delete=django.db.models.deletion.CASCADE, related_name='+', to='core.countrytag'
Expand Down
27 changes: 27 additions & 0 deletions core/migrations/0162_alter_sectorandmarketcard_meta_label.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Generated by Django 4.2.15 on 2024-10-02 14:24

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('core', '0161_countrytaggedsectorandmarketcard_sectorandmarketcard_and_more'),
]

operations = [
migrations.AlterField(
model_name='sectorandmarketcard',
name='meta_label',
field=models.CharField(
blank=True,
choices=[
('guidance_great', 'Guidance on great.gov.uk'),
('service_great', 'Service on great.gov.uk'),
('guidance_gov', 'Guidance on GOV.UK'),
('service_gov', 'Service on GOV.UK'),
],
max_length=255,
),
),
]
25 changes: 18 additions & 7 deletions core/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -2531,34 +2531,44 @@ def __str__(self):
return self.title


class CountryTaggedSectorAndMarketPromo(ItemBase):
class CountryTaggedSectorAndMarketCard(ItemBase):
tag = models.ForeignKey(CountryTag, related_name='+', on_delete=models.CASCADE)
content_object = ParentalKey(to='SectorAndMarketPromo', on_delete=models.CASCADE)
content_object = ParentalKey(to='SectorAndMarketCard', on_delete=models.CASCADE)


class SectorTaggedTaggedSectorAndMarketPromo(ItemBase):
class SectorTaggedTaggedSectorAndMarketCard(ItemBase):
tag = models.ForeignKey(SectorTag, related_name='+', on_delete=models.CASCADE)
content_object = ParentalKey(to='SectorAndMarketPromo', on_delete=models.CASCADE)
content_object = ParentalKey(to='SectorAndMarketCard', on_delete=models.CASCADE)


@register_snippet
class SectorAndMarketPromo(index.Indexed, ClusterableModel):
class SectorAndMarketCard(index.Indexed, ClusterableModel):
title = models.CharField()
description = models.TextField()
link_text = models.CharField(blank=True)
link_url = models.CharField(blank=True)
country_tags = TaggableManager(
through=CountryTaggedSectorAndMarketPromo,
through=CountryTaggedSectorAndMarketCard,
blank=True,
verbose_name='Country tag',
related_name='sector_and_market_promo_country_tags',
)
sector_tags = TaggableManager(
through=SectorTaggedTaggedSectorAndMarketPromo,
through=SectorTaggedTaggedSectorAndMarketCard,
blank=True,
verbose_name='Sector tag',
related_name='sector_and_market_promo_sector_tags',
)
meta_label = models.CharField(
max_length=255,
choices=(
('guidance_great', 'Guidance on great.gov.uk'),
('service_great', 'Service on great.gov.uk'),
('guidance_gov', 'Guidance on GOV.UK'),
('service_gov', 'Service on GOV.UK'),
),
blank=True,
)

panels = [
FieldPanel('title'),
Expand All @@ -2567,6 +2577,7 @@ class SectorAndMarketPromo(index.Indexed, ClusterableModel):
FieldPanel('link_url'),
FieldPanel('country_tags'),
FieldPanel('sector_tags'),
FieldPanel('meta_label'),
]

search_fields = [
Expand Down
6 changes: 3 additions & 3 deletions domestic/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from directory_forms_api_client import actions
from django.conf import settings

from core.models import CuratedListPage, DetailPage, SectorAndMarketPromo
from core.models import CuratedListPage, DetailPage, SectorAndMarketCard
from domestic import models as domestic_models
from sso import helpers as sso_helpers

Expand Down Expand Up @@ -162,10 +162,10 @@ def get_sector_widget_data_helper(sector):

def get_sector_and_market_promo_data_helper(sector, market):
return {
'market_matches': SectorAndMarketPromo.objects.filter(
'market_matches': SectorAndMarketCard.objects.filter(
country_tags__name__contains=market,
),
'sector_and_market_matches': SectorAndMarketPromo.objects.filter(
'sector_and_market_matches': SectorAndMarketCard.objects.filter(
country_tags__name__contains=market,
sector_tags__name__contains=sector,
),
Expand Down

0 comments on commit 350333a

Please sign in to comment.