Skip to content

Commit

Permalink
Merge pull request #70 from joeyjurjens/update-odin-imports
Browse files Browse the repository at this point in the history
Load odin things with get_class and correct resource name
  • Loading branch information
viggo-devries authored Nov 1, 2024
2 parents f8dd70c + 728c516 commit ffe1f7e
Show file tree
Hide file tree
Showing 9 changed files with 31 additions and 23 deletions.
6 changes: 4 additions & 2 deletions oscar_elasticsearch/search/api/category.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,15 @@ class CategoryElasticsearchIndex(BaseElasticSearchApi, ESModelIndexer):
Model = Category

def make_documents(self, objects):
from oscar_odin.mappings import catalogue
CategoryToResource = get_class(
"oscar_odin.mappings.catalogue", "CategoryToResource"
)

CategoryElasticSearchMapping = get_class(
"search.mappings.categories", "CategoryElasticSearchMapping"
)

category_resources = catalogue.CategoryToResource.apply(objects)
category_resources = CategoryToResource.apply(objects)
category_document_resources = CategoryElasticSearchMapping.apply(
category_resources
)
Expand Down
6 changes: 4 additions & 2 deletions oscar_elasticsearch/search/api/product.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,9 @@ def make_documents(self, objects):
% type(objects)
)

from oscar_odin.mappings import catalogue
product_queryset_to_resources = get_class(
"oscar_odin.mappings.catalogue", "product_queryset_to_resources"
)

ProductElasticSearchMapping = get_class(
"search.mappings.products", "ProductElasticSearchMapping"
Expand All @@ -71,7 +73,7 @@ def make_documents(self, objects):
)
)

product_resources = catalogue.product_queryset_to_resources(
product_resources = product_queryset_to_resources(
objects, include_children=True
)
product_document_resources = ProductElasticSearchMapping.apply(
Expand Down
7 changes: 4 additions & 3 deletions oscar_elasticsearch/search/mappings/categories.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@

from oscar.core.loading import get_class, get_model

from oscar_odin.resources.catalogue import Category as CategoryResource
from oscar_odin.mappings._common import OscarBaseMapping
from oscar_odin.resources._base import OscarResource
OscarResource = get_class("oscar_odin.resources.base", "OscarResource")
CategoryResource = get_class("oscar_odin.resources.catalogue", "CategoryResource")

OscarBaseMapping = get_class("oscar_odin.mappings.common", "OscarBaseMapping")

OscarElasticSearchResourceMixin = get_class(
"search.mappings.mixins", "OscarElasticSearchResourceMixin"
Expand Down
4 changes: 3 additions & 1 deletion oscar_elasticsearch/search/mappings/mixins.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
from oscar_odin.resources._base import OscarResource
from oscar.core.loading import get_class

OscarResource = get_class("oscar_odin.resources.base", "OscarResource")


class OscarElasticSearchResourceMixin(OscarResource):
Expand Down
11 changes: 5 additions & 6 deletions oscar_elasticsearch/search/mappings/products/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@

from oscar.core.loading import get_class

from oscar_odin.resources._base import OscarResource
from oscar_odin.resources.catalogue import (
Product as ProductResource,
Category as CategoryResource,
)
from oscar_odin.mappings._common import OscarBaseMapping
OscarResource = get_class("oscar_odin.resources.base", "OscarResource")
ProductResource = get_class("oscar_odin.resources.catalogue", "ProductResource")
CategoryResource = get_class("oscar_odin.resources.catalogue", "CategoryResource")

OscarBaseMapping = get_class("oscar_odin.mappings.common", "OscarBaseMapping")

ProductElasticSearchResource = get_class(
"search.mappings.products.resources", "ProductElasticSearchResource"
Expand Down
11 changes: 5 additions & 6 deletions oscar_elasticsearch/search/mappings/products/mappings.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,6 @@

from oscar.core.loading import get_model, get_class

from oscar_odin.mappings._common import OscarBaseMapping
from oscar_odin.resources.catalogue import (
Product as ProductResource,
Category as CategoryResource,
)

from oscar_elasticsearch.search.constants import (
ES_CTX_PUBLIC,
ES_CTX_AVAILABLE,
Expand All @@ -24,6 +18,11 @@
Product = get_model("catalogue", "Product")
Line = get_model("order", "Line")

ProductResource = get_class("oscar_odin.resources.catalogue", "ProductResource")
CategoryResource = get_class("oscar_odin.resources.catalogue", "CategoryResource")

OscarBaseMapping = get_class("oscar_odin.mappings.common", "OscarBaseMapping")

OscarElasticSearchResourceMixin = get_class(
"search.mappings.mixins", "OscarElasticSearchResourceMixin"
)
Expand Down
5 changes: 4 additions & 1 deletion oscar_elasticsearch/search/mappings/products/resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,14 @@

from datetime import datetime

from oscar_odin.resources._base import OscarResource
from oscar.core.loading import get_class

from oscar_odin.fields import DecimalField

from oscar_elasticsearch.search.mappings.mixins import OscarElasticSearchResourceMixin

OscarResource = get_class("oscar_odin.resources.base", "OscarResource")


class CategoryElasticSearchRelatedResource(OscarResource):
id: int
Expand Down
2 changes: 1 addition & 1 deletion sandbox/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
'sorl.thumbnail',
'django_tables2',
'oscar_elasticsearch.search.apps.OscarElasticSearchConfig',
"oscar_odin"
"oscar_odin.apps.OscarOdinAppConfig"
]

MIDDLEWARE = [
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
"purl",
"elasticsearch>=8.0.0",
"uwsgidecorators-fallback",
"django-oscar-odin>0.1.0",
"django-oscar-odin>=0.3.0",
],
# mark test target to require extras.
extras_require={
Expand Down

0 comments on commit ffe1f7e

Please sign in to comment.