Skip to content

Commit

Permalink
Zoo-lane-2 (#868)
Browse files Browse the repository at this point in the history
* Excluding archived barriers from inactive notification alerts (#858)

Co-authored-by: santinomolinaro <santino.molinaro@mail>

* Deleting cached barrier when creating and updating next steps items so they are reflected instantly on frontend (#861)

Co-authored-by: santinomolinaro <santino.molinaro@mail>

* TSS-1995: Move set_to_allowed_on into public barrier serializer (#862)

* tss-1995: set_to_allowed expected on public_barrier serializer

---------

Co-authored-by: abarolo <[email protected]>

* Extend next steps bugfix to include barrier status (#863)

* Delete cache when updating barrier status

* Moving cache delete

---------

Co-authored-by: santinomolinaro <santino.molinaro@mail>

* tss-1975: Policy teams metadata (#857)

* tss-1975: Policy teams metadata

* tss-2017: Policy Team in download serializers

* Enabling filtering for the FE (#866)

Co-authored-by: abarolo <[email protected]>

---------

Co-authored-by: abarolo <[email protected]>
Co-authored-by: Elizabeth Pedley <[email protected]>

---------

Co-authored-by: Santino Molinaro <[email protected]>
Co-authored-by: santinomolinaro <santino.molinaro@mail>
Co-authored-by: abarolo <[email protected]>
Co-authored-by: Elizabeth Pedley <[email protected]>
  • Loading branch information
5 people authored Aug 19, 2024
1 parent 763ac16 commit 465b419
Show file tree
Hide file tree
Showing 23 changed files with 605 additions and 12 deletions.
1 change: 1 addition & 0 deletions api/barrier_downloads/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"overseas_region": "Overseas Region",
"location": "Location",
"sectors": "Sectors",
"policy_teams": "Policy Teams",
"product": "Product",
"categories": "Barrier categories",
"admin_areas": "Admin areas",
Expand Down
4 changes: 4 additions & 0 deletions api/barrier_downloads/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,10 @@ class CsvDownloadSerializer(serializers.Serializer):
valuation_assessment_midpoint = serializers.SerializerMethodField()
valuation_assessment_explanation = serializers.SerializerMethodField()
commercial_value = serializers.IntegerField()
policy_teams = serializers.SerializerMethodField()

def get_policy_teams(self, obj):
return [p.title for p in obj.policy_teams.all()]

def get_is_top_priority(self, obj):
return obj.is_top_priority
Expand Down
1 change: 1 addition & 0 deletions api/barrier_downloads/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ def get_queryset(barrier_ids: List[str]) -> QuerySet:
"public_barrier",
"economic_assessments",
"valuation_assessments",
"policy_teams",
Prefetch(
"next_steps_items",
queryset=BarrierNextStepItem.objects.filter(
Expand Down
1 change: 1 addition & 0 deletions api/barrier_downloads/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ class BarrierDownloadsView(generics.ListCreateAPIView):
"barrier_commodities",
"public_barrier__notes",
"organisations",
"policy_teams",
)
)
serializer_class = BarrierDownloadSerializer
Expand Down
11 changes: 11 additions & 0 deletions api/barriers/fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,15 @@
Category,
ExportType,
Organisation,
PolicyTeam,
)
from api.metadata.serializers import (
BarrierPrioritySerializer,
BarrierTagSerializer,
CategorySerializer,
ExportTypeSerializer,
OrganisationSerializer,
PolicyTeamSerializer,
)
from api.metadata.utils import get_country, get_sector, get_trading_bloc
from api.wto.models import WTOProfile
Expand Down Expand Up @@ -79,6 +81,15 @@ def to_internal_value(self, data):
raise serializers.ValidationError("Priority not found")


class PolicyTeamsField(serializers.ListField):
def to_representation(self, value):
serializer = PolicyTeamSerializer(value.all(), many=True)
return serializer.data

def to_internal_value(self, data):
return PolicyTeam.objects.filter(id__in=data)


class CategoriesField(serializers.ListField):
def to_representation(self, value):
serializer = CategorySerializer(value.all(), many=True)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,172 @@
# Generated by Django 4.2.14 on 2024-08-08 13:36

from django.conf import settings
from django.db import migrations, models
import django.db.models.deletion
import simple_history.models


class Migration(migrations.Migration):

dependencies = [
("metadata", "0048_policyteam_historicalpolicyteam"),
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
("barriers", "0169_alter_barrier_trading_bloc_and_more"),
]

operations = [
migrations.CreateModel(
name="HistoricalBarrierPolicyTeam",
fields=[
(
"id",
models.IntegerField(
auto_created=True, blank=True, db_index=True, verbose_name="ID"
),
),
(
"created_on",
models.DateTimeField(
blank=True, db_index=True, editable=False, null=True
),
),
(
"modified_on",
models.DateTimeField(blank=True, editable=False, null=True),
),
("history_id", models.AutoField(primary_key=True, serialize=False)),
("history_date", models.DateTimeField(db_index=True)),
("history_change_reason", models.CharField(max_length=100, null=True)),
(
"history_type",
models.CharField(
choices=[("+", "Created"), ("~", "Changed"), ("-", "Deleted")],
max_length=1,
),
),
(
"barrier",
models.ForeignKey(
blank=True,
db_constraint=False,
null=True,
on_delete=django.db.models.deletion.DO_NOTHING,
related_name="+",
to="barriers.barrier",
),
),
(
"created_by",
models.ForeignKey(
blank=True,
db_constraint=False,
null=True,
on_delete=django.db.models.deletion.DO_NOTHING,
related_name="+",
to=settings.AUTH_USER_MODEL,
),
),
(
"history_user",
models.ForeignKey(
null=True,
on_delete=django.db.models.deletion.SET_NULL,
related_name="+",
to=settings.AUTH_USER_MODEL,
),
),
(
"modified_by",
models.ForeignKey(
blank=True,
db_constraint=False,
null=True,
on_delete=django.db.models.deletion.DO_NOTHING,
related_name="+",
to=settings.AUTH_USER_MODEL,
),
),
(
"policy_team",
models.ForeignKey(
blank=True,
db_constraint=False,
null=True,
on_delete=django.db.models.deletion.DO_NOTHING,
related_name="+",
to="metadata.policyteam",
),
),
],
options={
"verbose_name": "historical barrier policy team",
"verbose_name_plural": "historical barrier policy teams",
"ordering": ("-history_date", "-history_id"),
"get_latest_by": ("history_date", "history_id"),
},
bases=(simple_history.models.HistoricalChanges, models.Model),
),
migrations.CreateModel(
name="BarrierPolicyTeam",
fields=[
(
"id",
models.AutoField(
auto_created=True,
primary_key=True,
serialize=False,
verbose_name="ID",
),
),
(
"created_on",
models.DateTimeField(auto_now_add=True, db_index=True, null=True),
),
("modified_on", models.DateTimeField(auto_now=True, null=True)),
(
"barrier",
models.ForeignKey(
on_delete=django.db.models.deletion.CASCADE,
to="barriers.barrier",
),
),
(
"created_by",
models.ForeignKey(
blank=True,
null=True,
on_delete=django.db.models.deletion.SET_NULL,
related_name="+",
to=settings.AUTH_USER_MODEL,
),
),
(
"modified_by",
models.ForeignKey(
blank=True,
null=True,
on_delete=django.db.models.deletion.SET_NULL,
related_name="+",
to=settings.AUTH_USER_MODEL,
),
),
(
"policy_team",
models.ForeignKey(
on_delete=django.db.models.deletion.CASCADE,
to="metadata.policyteam",
),
),
],
options={
"abstract": False,
},
),
migrations.AddField(
model_name="barrier",
name="policy_teams",
field=models.ManyToManyField(
through="barriers.BarrierPolicyTeam", to="metadata.policyteam"
),
),
]
14 changes: 14 additions & 0 deletions api/barriers/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,10 @@ class Barrier(FullyArchivableMixin, BaseModel):
)
reported_on = models.DateTimeField(db_index=True, auto_now_add=True)

policy_teams = models.ManyToManyField(
metadata_models.PolicyTeam, through="BarrierPolicyTeam"
)

# Barrier status
status = models.PositiveIntegerField(choices=BarrierStatus.choices, default=0)
sub_status = models.CharField(
Expand Down Expand Up @@ -1220,6 +1224,15 @@ def simple_formatted_code(self):
return format_commodity_code(self.code, separator="")


class BarrierPolicyTeam(BaseModel):
barrier = models.ForeignKey(Barrier, on_delete=models.CASCADE)
policy_team = models.ForeignKey(
metadata_models.PolicyTeam, on_delete=models.CASCADE
)

history = HistoricalRecords()


class BarrierFilterSet(django_filters.FilterSet):
"""
Custom FilterSet to handle all necessary filters on Barriers
Expand Down Expand Up @@ -1256,6 +1269,7 @@ class BarrierFilterSet(django_filters.FilterSet):
status_date_resolved_in_full = django_filters.Filter(method="resolved_date_filter")
delivery_confidence = django_filters.BaseInFilter(method="progress_status_filter")
category = django_filters.BaseInFilter("categories", distinct=True)
policy_team = django_filters.BaseInFilter("policy_teams", distinct=True)
top_priority = django_filters.BaseInFilter(method="tags_filter")
priority = django_filters.BaseInFilter(method="priority_filter")
top_priority_status = django_filters.BaseInFilter(
Expand Down
1 change: 1 addition & 0 deletions api/barriers/serializers/barriers.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ class Meta(BarrierSerializerBase.Meta):
"modified_by",
"modified_on",
"other_source",
"policy_teams",
"priority_level",
"priority_summary",
"product",
Expand Down
2 changes: 2 additions & 0 deletions api/barriers/serializers/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
CommoditiesField,
ExportTypesField,
OrganisationsField,
PolicyTeamsField,
PublicEligibilityField,
SectorField,
SectorsField,
Expand Down Expand Up @@ -64,6 +65,7 @@ class BarrierSerializerBase(
)
strategic_assessments = StrategicAssessmentSerializer(required=False, many=True)
categories = CategoriesField(required=False)
policy_teams = PolicyTeamsField(required=False)
commodities = CommoditiesField(source="barrier_commodities", required=False)
country = CountryField(required=False, allow_null=True)
created_by = UserField(required=False)
Expand Down
1 change: 1 addition & 0 deletions api/barriers/serializers/data_workspace.py
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,7 @@ class Meta(BarrierSerializerBase.Meta):
"main_sector",
"export_description",
"tags",
"policy_teams",
)

def to_representation(self, instance):
Expand Down
4 changes: 2 additions & 2 deletions api/metadata/fields.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from rest_framework import serializers

from .constants import BARRIER_TYPE_CATEGORIES
from .utils import get_admin_area, get_country, get_trading_bloc
from api.metadata.constants import BARRIER_TYPE_CATEGORIES
from api.metadata.utils import get_admin_area, get_country, get_trading_bloc


class AdminAreasField(serializers.ListField):
Expand Down
Loading

0 comments on commit 465b419

Please sign in to comment.