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

Feature/oi integration fixes #39

Merged
merged 10 commits into from
Nov 8, 2024
Merged
Show file tree
Hide file tree
Changes from 6 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
2 changes: 1 addition & 1 deletion requirements/base.in
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ django-treebeard
# django-extra-fields
django-tinymce
geopy

django-open-forms-client
django-localflavor
5 changes: 5 additions & 0 deletions requirements/base.txt
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ django==4.2.13
# django-localflavor
# django-log-outgoing-requests
# django-markup
# django-open-forms-client
# django-otp
# django-phonenumber-field
# django-privates
Expand Down Expand Up @@ -130,6 +131,8 @@ django-log-outgoing-requests==0.6.1
# via open-api-framework
django-markup==1.8.1
# via open-api-framework
django-open-forms-client==0.4.0
# via -r requirements/base.in
django-ordered-model==3.7.4
# via django-admin-index
django-otp==1.5.0
Expand All @@ -154,6 +157,7 @@ django-solo==2.3.0
# via
# commonground-api-common
# django-log-outgoing-requests
# django-open-forms-client
# mozilla-django-oidc-db
# notifications-api-common
# zgw-consumers
Expand Down Expand Up @@ -306,6 +310,7 @@ requests==2.32.3
# commonground-api-common
# coreapi
# django-log-outgoing-requests
# django-open-forms-client
# gemma-zds-client
# mozilla-django-oidc
# open-api-framework
Expand Down
7 changes: 7 additions & 0 deletions requirements/ci.txt
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ django==4.2.13
# django-localflavor
# django-log-outgoing-requests
# django-markup
# django-open-forms-client
# django-otp
# django-phonenumber-field
# django-privates
Expand Down Expand Up @@ -228,6 +229,10 @@ django-markup==1.8.1
# -c requirements/base.txt
# -r requirements/base.txt
# open-api-framework
django-open-forms-client==0.4.0
# via
# -c requirements/base.txt
# -r requirements/base.txt
django-ordered-model==3.7.4
# via
# -c requirements/base.txt
Expand Down Expand Up @@ -284,6 +289,7 @@ django-solo==2.3.0
# -r requirements/base.txt
# commonground-api-common
# django-log-outgoing-requests
# django-open-forms-client
# mozilla-django-oidc-db
# notifications-api-common
# zgw-consumers
Expand Down Expand Up @@ -633,6 +639,7 @@ requests==2.32.3
# commonground-api-common
# coreapi
# django-log-outgoing-requests
# django-open-forms-client
# gemma-zds-client
# mozilla-django-oidc
# open-api-framework
Expand Down
7 changes: 7 additions & 0 deletions requirements/dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ django==4.2.13
# django-localflavor
# django-log-outgoing-requests
# django-markup
# django-open-forms-client
# django-otp
# django-phonenumber-field
# django-privates
Expand Down Expand Up @@ -262,6 +263,10 @@ django-markup==1.8.1
# -c requirements/ci.txt
# -r requirements/ci.txt
# open-api-framework
django-open-forms-client==0.4.0
# via
# -c requirements/ci.txt
# -r requirements/ci.txt
django-ordered-model==3.7.4
# via
# -c requirements/ci.txt
Expand Down Expand Up @@ -318,6 +323,7 @@ django-solo==2.3.0
# -r requirements/ci.txt
# commonground-api-common
# django-log-outgoing-requests
# django-open-forms-client
# mozilla-django-oidc-db
# notifications-api-common
# zgw-consumers
Expand Down Expand Up @@ -724,6 +730,7 @@ requests==2.32.3
# commonground-api-common
# coreapi
# django-log-outgoing-requests
# django-open-forms-client
# gemma-zds-client
# mozilla-django-oidc
# open-api-framework
Expand Down
1 change: 1 addition & 0 deletions src/open_producten/conf/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"localflavor",
"treebeard",
"tinymce",
"openformsclient",
"django.contrib.gis",
"open_producten.accounts",
"open_producten.utils",
Expand Down
4 changes: 4 additions & 0 deletions src/open_producten/fixtures/default_admin_index.json
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,10 @@
[
"admin_index",
"contenttypeproxy"
],
[
"openformsclient",
"configuration"
]
]
}
Expand Down
5 changes: 3 additions & 2 deletions src/open_producten/locations/admin/location.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
from django.contrib.gis import admin

from open_producten.utils.geocode import GeoAdminMixin

from ..models import Location


@admin.register(Location)
class LocationAdmin(admin.GISModelAdmin):
class LocationAdmin(GeoAdminMixin, admin.GISModelAdmin):
list_display = ("name", "city", "postcode", "street", "house_number")
list_filter = ("city",)
search_fields = ("name", "city")
readonly_fields = ["coordinates"]
6 changes: 3 additions & 3 deletions src/open_producten/locations/admin/organisation.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
from django.contrib.gis import admin
from django.utils.translation import gettext_lazy as _

from open_producten.utils.geocode import GeoAdminMixin

from ..models import Neighbourhood, Organisation, OrganisationType


@admin.register(Organisation)
class OrganisationAdmin(admin.GISModelAdmin):
class OrganisationAdmin(GeoAdminMixin, admin.GISModelAdmin):
list_display = ("name", "type")
list_filter = ("type__name", "city")
search_fields = ("name",)
ordering = ("name",)
readonly_fields = ["coordinates"]
modifiable = False

fieldsets = (
(
Expand Down
3 changes: 1 addition & 2 deletions src/open_producten/locations/serializers/location.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,8 @@ def update(self, instance, validated_data: dict) -> Location:


class ContactSerializer(serializers.ModelSerializer):
organisation = OrganisationSerializer(read_only=True)
organisation_id = serializers.PrimaryKeyRelatedField(
write_only=True, queryset=Organisation.objects.all(), source="organisation"
queryset=Organisation.objects.all(), source="organisation"
)

class Meta:
Expand Down
35 changes: 35 additions & 0 deletions src/open_producten/locations/tests/test_geoadmin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
from django.contrib.admin import AdminSite
from django.http import HttpRequest
from django.test import TestCase

from open_producten.locations.admin import LocationAdmin
from open_producten.locations.models import Location
from open_producten.locations.tests.factories import LocationFactory


class TestGeoAdminMixin(TestCase):

def setUp(self):
site = AdminSite()
self.admin = LocationAdmin(Location, site)

def test_get_read_only_fields_when_creating_object(self):
read_only_fields = self.admin.get_readonly_fields(HttpRequest())
self.assertIn("coordinates", read_only_fields)

def test_get_read_only_fields_when_updating_object(self):
read_only_fields = self.admin.get_readonly_fields(
HttpRequest(), LocationFactory()
)
self.assertNotIn("coordinates", read_only_fields)

def test_form_when_creating_object(self):
form_class = self.admin.get_form(HttpRequest())
form = form_class()
self.assertNotIn("coordinates", form.fields)

def test_form_when_updating_object(self):
form_class = self.admin.get_form(HttpRequest(), LocationFactory())
form = form_class()
self.assertIn("coordinates", form.fields)
self.assertTrue(form.fields["coordinates"].disabled)
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
# Generated by Django 4.2.13 on 2024-10-28 15:38

from django.db import migrations, models
import openformsclient.models


class Migration(migrations.Migration):

dependencies = [
("producttypes", "0007_alter_category_description_and_more"),
]

operations = [
migrations.AddField(
model_name="producttype",
name="open_forms_slug",
field=openformsclient.models.OpenFormsSlugField(
blank=True,
db_index=False,
help_text="Open forms slug of the product type form.",
max_length=100,
null=True,
verbose_name="Open forms slug",
),
),
migrations.AlterField(
model_name="condition",
name="negative_text",
field=models.TextField(
help_text="Description how not to meet the condition",
verbose_name="Negative text",
),
),
migrations.AlterField(
model_name="condition",
name="positive_text",
field=models.TextField(
help_text="Description how to meet the condition",
verbose_name="Positive text",
),
),
migrations.AlterField(
model_name="condition",
name="question",
field=models.TextField(
help_text="Question used in the question-answer game",
verbose_name="Question",
),
),
migrations.AlterField(
model_name="producttype",
name="summary",
field=models.TextField(
default="",
help_text="Short description of the product type, limited to 300 characters.",
max_length=300,
verbose_name="Summary",
),
),
]
8 changes: 3 additions & 5 deletions src/open_producten/producttypes/models/condition.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
from django.db import models
from django.utils.translation import gettext_lazy as _

from tinymce import models as tinymce_models

from open_producten.utils.models import BaseModel


Expand All @@ -12,15 +10,15 @@ class Condition(BaseModel):
max_length=100,
help_text=_("Short name of the condition"),
)
question = tinymce_models.HTMLField(
question = models.TextField(
verbose_name=_("Question"),
help_text=_("Question used in the question-answer game"),
)
positive_text = tinymce_models.HTMLField(
positive_text = models.TextField(
verbose_name=_("Positive text"),
help_text=_("Description how to meet the condition"),
)
negative_text = tinymce_models.HTMLField(
negative_text = models.TextField(
verbose_name=_("Negative text"),
help_text=_("Description how not to meet the condition"),
)
Expand Down
20 changes: 17 additions & 3 deletions src/open_producten/producttypes/models/producttype.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from django.db import models
from django.utils.translation import gettext_lazy as _

from openformsclient.models import OpenFormsSlugField
from tinymce import models as tinymce_models

from open_producten.locations.models import Contact, Location, Organisation
Expand All @@ -14,8 +15,6 @@
from .tag import Tag
from .upn import UniformProductName

# from ...utils.models import HTMLField


class CategoryProductType(models.Model):
"""
Expand All @@ -31,7 +30,7 @@ class ProductType(BasePublishableModel):
verbose_name=_("Name"), max_length=100, help_text=_("Name of the product type")
)

summary = tinymce_models.HTMLField(
summary = models.TextField(
verbose_name=_("Summary"),
default="",
max_length=300,
Expand Down Expand Up @@ -61,6 +60,13 @@ class ProductType(BasePublishableModel):
help_text=_("Action link to request the product type."),
)

open_forms_slug = OpenFormsSlugField(
verbose_name=_("Open forms slug"),
null=True,
Floris272 marked this conversation as resolved.
Show resolved Hide resolved
blank=True,
help_text=_("Open forms slug of the product type form."),
)

content = tinymce_models.HTMLField(
verbose_name=_("Content"),
help_text=_("Product type content with build-in WYSIWYG editor."),
Expand Down Expand Up @@ -145,6 +151,14 @@ class Meta:
def __str__(self):
return self.name

def clean(self):
for contact in self.contacts.all():
if (
contact.organisation_id is not None
and not self.organisations.filter(id=contact.organisation_id).exists()
):
self.organisations.add(contact.organisation)
swrichards marked this conversation as resolved.
Show resolved Hide resolved

@property
def current_price(self):
now = date.today()
Expand Down
3 changes: 2 additions & 1 deletion src/open_producten/producttypes/serializers/producttype.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ def create(self, validated_data):
organisations=organisations,
contacts=contacts,
)
product_type.clean()
product_type.save()

return product_type
Expand All @@ -194,7 +195,7 @@ def update(self, instance, validated_data):
organisations=organisations,
contacts=contacts,
)

instance.clean()
instance.save()

return instance
Expand Down
6 changes: 6 additions & 0 deletions src/open_producten/producttypes/tests/api/test_producttype.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,9 @@ def test_create_product_type_with_contact(self):
[contact.first_name],
)

# contact org is added in ProductType clean
self.assertEqual(ProductType.objects.first().organisations.count(), 1)

def test_create_product_type_with_duplicate_ids_returns_error(self):
tag = TagFactory.create()
condition = ConditionFactory.create()
Expand Down Expand Up @@ -379,6 +382,9 @@ def test_update_product_type_with_contact(self):
[contact.first_name],
)

# contact org is added in ProductType clean
self.assertEqual(ProductType.objects.first().organisations.count(), 1)

def test_update_product_type_with_duplicate_ids_returns_error(self):
product_type = ProductTypeFactory.create()
tag = TagFactory.create()
Expand Down
Loading
Loading